Commit 4ec1bc56 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Trim loopback tests.

parent fdf07284
...@@ -29,10 +29,8 @@ type testCase struct { ...@@ -29,10 +29,8 @@ type testCase struct {
mountFile string mountFile string
mountSubdir string mountSubdir string
mountSubfile string
origFile string origFile string
origSubdir string origSubdir string
origSubfile string
tester *testing.T tester *testing.T
state *MountState state *MountState
connector *FileSystemConnector connector *FileSystemConnector
...@@ -61,10 +59,8 @@ func NewTestCase(t *testing.T) *testCase { ...@@ -61,10 +59,8 @@ func NewTestCase(t *testing.T) *testCase {
me.mountFile = filepath.Join(me.mnt, name) me.mountFile = filepath.Join(me.mnt, name)
me.mountSubdir = filepath.Join(me.mnt, subdir) me.mountSubdir = filepath.Join(me.mnt, subdir)
me.mountSubfile = filepath.Join(me.mountSubdir, "subfile")
me.origFile = filepath.Join(me.orig, name) me.origFile = filepath.Join(me.orig, name)
me.origSubdir = filepath.Join(me.orig, subdir) me.origSubdir = filepath.Join(me.orig, subdir)
me.origSubfile = filepath.Join(me.origSubdir, "subfile")
var pfs FileSystem var pfs FileSystem
pfs = NewLoopbackFileSystem(me.orig) pfs = NewLoopbackFileSystem(me.orig)
...@@ -102,27 +98,7 @@ func (me *testCase) Cleanup() { ...@@ -102,27 +98,7 @@ func (me *testCase) Cleanup() {
os.Remove(me.tmpDir) os.Remove(me.tmpDir)
} }
////////////////
// Utilities.
func (me *testCase) makeOrigSubdir() {
err := os.Mkdir(me.origSubdir, 0777)
CheckSuccess(err)
}
func (me *testCase) removeMountSubdir() {
err := os.RemoveAll(me.mountSubdir)
CheckSuccess(err)
}
func (me *testCase) removeMountFile() {
os.Remove(me.mountFile)
// ignore errors.
}
func (me *testCase) writeOrigFile() { func (me *testCase) writeOrigFile() {
err := ioutil.WriteFile(me.origFile, []byte(contents), 0700)
CheckSuccess(err)
} }
//////////////// ////////////////
...@@ -142,8 +118,9 @@ func TestTouch(t *testing.T) { ...@@ -142,8 +118,9 @@ func TestTouch(t *testing.T) {
defer ts.Cleanup() defer ts.Cleanup()
log.Println("testTouch") log.Println("testTouch")
ts.writeOrigFile() err := ioutil.WriteFile(ts.origFile, []byte(contents), 0700)
err := os.Chtimes(ts.mountFile, 42e9, 43e9) CheckSuccess(err)
err = os.Chtimes(ts.mountFile, 42e9, 43e9)
CheckSuccess(err) CheckSuccess(err)
fi, err := os.Lstat(ts.mountFile) fi, err := os.Lstat(ts.mountFile)
CheckSuccess(err) CheckSuccess(err)
...@@ -156,10 +133,11 @@ func (me *testCase) TestReadThrough(t *testing.T) { ...@@ -156,10 +133,11 @@ func (me *testCase) TestReadThrough(t *testing.T) {
ts := NewTestCase(t) ts := NewTestCase(t)
defer ts.Cleanup() defer ts.Cleanup()
ts.writeOrigFile() err := ioutil.WriteFile(ts.origFile, []byte(contents), 0700)
CheckSuccess(err)
fmt.Println("Testing chmod.") fmt.Println("Testing chmod.")
err := os.Chmod(ts.mountFile, mode) err = os.Chmod(ts.mountFile, mode)
CheckSuccess(err) CheckSuccess(err)
fmt.Println("Testing Lstat.") fmt.Println("Testing Lstat.")
...@@ -190,10 +168,10 @@ func TestRemove(t *testing.T) { ...@@ -190,10 +168,10 @@ func TestRemove(t *testing.T) {
me := NewTestCase(t) me := NewTestCase(t)
defer me.Cleanup() defer me.Cleanup()
me.writeOrigFile() err := ioutil.WriteFile(me.origFile, []byte(contents), 0700)
CheckSuccess(err)
fmt.Println("Testing remove.") err = os.Remove(me.mountFile)
err := os.Remove(me.mountFile)
CheckSuccess(err) CheckSuccess(err)
_, err = os.Lstat(me.origFile) _, err = os.Lstat(me.origFile)
if err == nil { if err == nil {
...@@ -255,12 +233,14 @@ func TestLink(t *testing.T) { ...@@ -255,12 +233,14 @@ func TestLink(t *testing.T) {
defer me.Cleanup() defer me.Cleanup()
t.Log("Testing hard links.") t.Log("Testing hard links.")
me.writeOrigFile() err := ioutil.WriteFile(me.origFile, []byte(contents), 0700)
err := os.Mkdir(me.origSubdir, 0777) CheckSuccess(err)
err = os.Mkdir(me.origSubdir, 0777)
CheckSuccess(err) CheckSuccess(err)
// Link. // Link.
err = os.Link(me.mountFile, me.mountSubfile) mountSubfile := filepath.Join(me.mountSubdir, "subfile")
err = os.Link(me.mountFile, mountSubfile)
CheckSuccess(err) CheckSuccess(err)
fi, err := os.Lstat(me.origFile) fi, err := os.Lstat(me.origFile)
...@@ -268,7 +248,7 @@ func TestLink(t *testing.T) { ...@@ -268,7 +248,7 @@ func TestLink(t *testing.T) {
t.Errorf("Expect 2 links: %v", fi) t.Errorf("Expect 2 links: %v", fi)
} }
f, err := os.Open(me.mountSubfile) f, err := os.Open(mountSubfile)
var buf [1024]byte var buf [1024]byte
slice := buf[:] slice := buf[:]
...@@ -286,13 +266,12 @@ func TestSymlink(t *testing.T) { ...@@ -286,13 +266,12 @@ func TestSymlink(t *testing.T) {
defer me.Cleanup() defer me.Cleanup()
t.Log("testing symlink/readlink.") t.Log("testing symlink/readlink.")
me.writeOrigFile() err := ioutil.WriteFile(me.origFile, []byte(contents), 0700)
CheckSuccess(err)
linkFile := "symlink-file" linkFile := "symlink-file"
orig := "hello.txt" orig := "hello.txt"
err := os.Symlink(orig, filepath.Join(me.mnt, linkFile)) err = os.Symlink(orig, filepath.Join(me.mnt, linkFile))
defer os.Remove(filepath.Join(me.mnt, linkFile))
defer me.removeMountFile()
CheckSuccess(err) CheckSuccess(err)
...@@ -318,10 +297,10 @@ func TestRename(t *testing.T) { ...@@ -318,10 +297,10 @@ func TestRename(t *testing.T) {
defer me.Cleanup() defer me.Cleanup()
t.Log("Testing rename.") t.Log("Testing rename.")
me.writeOrigFile() err := ioutil.WriteFile(me.origFile, []byte(contents), 0700)
CheckSuccess(err)
sd := me.mnt + "/testRename" sd := me.mnt + "/testRename"
err := os.MkdirAll(sd, 0777) err = os.MkdirAll(sd, 0777)
defer os.RemoveAll(sd)
subFile := sd + "/subfile" subFile := sd + "/subfile"
err = os.Rename(me.mountFile, subFile) err = os.Rename(me.mountFile, subFile)
...@@ -332,7 +311,7 @@ func TestRename(t *testing.T) { ...@@ -332,7 +311,7 @@ func TestRename(t *testing.T) {
} }
f, _ = os.Lstat(subFile) f, _ = os.Lstat(subFile)
if f == nil { if f == nil {
t.Errorf("destination %v does not exist.", me.origSubfile) t.Errorf("destination %v does not exist.", subFile)
} }
} }
...@@ -396,8 +375,9 @@ func TestAccess(t *testing.T) { ...@@ -396,8 +375,9 @@ func TestAccess(t *testing.T) {
me := NewTestCase(t) me := NewTestCase(t)
defer me.Cleanup() defer me.Cleanup()
me.writeOrigFile() err := ioutil.WriteFile(me.origFile, []byte(contents), 0700)
err := os.Chmod(me.origFile, 0) CheckSuccess(err)
err = os.Chmod(me.origFile, 0)
CheckSuccess(err) CheckSuccess(err)
// Ugh - copied from unistd.h // Ugh - copied from unistd.h
const W_OK uint32 = 2 const W_OK uint32 = 2
...@@ -434,8 +414,10 @@ func TestReaddir(t *testing.T) { ...@@ -434,8 +414,10 @@ func TestReaddir(t *testing.T) {
defer me.Cleanup() defer me.Cleanup()
t.Log("Testing readdir.") t.Log("Testing readdir.")
me.writeOrigFile() err := ioutil.WriteFile(me.origFile, []byte(contents), 0700)
me.makeOrigSubdir() CheckSuccess(err)
err = os.Mkdir(me.origSubdir, 0777)
CheckSuccess(err)
dir, err := os.Open(me.mnt) dir, err := os.Open(me.mnt)
CheckSuccess(err) CheckSuccess(err)
...@@ -465,7 +447,8 @@ func TestFSync(t *testing.T) { ...@@ -465,7 +447,8 @@ func TestFSync(t *testing.T) {
defer me.Cleanup() defer me.Cleanup()
t.Log("Testing fsync.") t.Log("Testing fsync.")
me.writeOrigFile() err := ioutil.WriteFile(me.origFile, []byte(contents), 0700)
CheckSuccess(err)
f, err := os.OpenFile(me.mountFile, os.O_WRONLY, 0) f, err := os.OpenFile(me.mountFile, os.O_WRONLY, 0)
_, err = f.WriteString("hello there") _, err = f.WriteString("hello there")
...@@ -690,3 +673,4 @@ func TestOriginalIsSymlink(t *testing.T) { ...@@ -690,3 +673,4 @@ func TestOriginalIsSymlink(t *testing.T) {
_, err = os.Lstat(mnt) _, err = os.Lstat(mnt)
CheckSuccess(err) CheckSuccess(err)
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment