Commit 20f834fe authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fuse/test: cleanup loopback_test for style.

parent 9dab8e19
...@@ -39,8 +39,8 @@ const testTtl = 100 * time.Millisecond ...@@ -39,8 +39,8 @@ const testTtl = 100 * time.Millisecond
// Create and mount filesystem. // Create and mount filesystem.
func NewTestCase(t *testing.T) *testCase { func NewTestCase(t *testing.T) *testCase {
me := &testCase{} tc := &testCase{}
me.tester = t tc.tester = t
// Make sure system setting does not affect test. // Make sure system setting does not affect test.
syscall.Umask(0) syscall.Umask(0)
...@@ -49,47 +49,47 @@ func NewTestCase(t *testing.T) *testCase { ...@@ -49,47 +49,47 @@ func NewTestCase(t *testing.T) *testCase {
const subdir string = "subdir" const subdir string = "subdir"
var err error var err error
me.tmpDir, err = ioutil.TempDir("", "go-fuse") tc.tmpDir, err = ioutil.TempDir("", "go-fuse")
if err != nil { if err != nil {
t.Fatalf("TempDir failed: %v", err) t.Fatalf("TempDir failed: %v", err)
} }
me.orig = me.tmpDir + "/orig" tc.orig = tc.tmpDir + "/orig"
me.mnt = me.tmpDir + "/mnt" tc.mnt = tc.tmpDir + "/mnt"
os.Mkdir(me.orig, 0700) os.Mkdir(tc.orig, 0700)
os.Mkdir(me.mnt, 0700) os.Mkdir(tc.mnt, 0700)
me.mountFile = filepath.Join(me.mnt, name) tc.mountFile = filepath.Join(tc.mnt, name)
me.mountSubdir = filepath.Join(me.mnt, subdir) tc.mountSubdir = filepath.Join(tc.mnt, subdir)
me.origFile = filepath.Join(me.orig, name) tc.origFile = filepath.Join(tc.orig, name)
me.origSubdir = filepath.Join(me.orig, subdir) tc.origSubdir = filepath.Join(tc.orig, subdir)
var pfs pathfs.FileSystem var pfs pathfs.FileSystem
pfs = pathfs.NewLoopbackFileSystem(me.orig) pfs = pathfs.NewLoopbackFileSystem(tc.orig)
pfs = pathfs.NewLockingFileSystem(pfs) pfs = pathfs.NewLockingFileSystem(pfs)
me.pathFs = pathfs.NewPathNodeFs(pfs, &pathfs.PathNodeFsOptions{ tc.pathFs = pathfs.NewPathNodeFs(pfs, &pathfs.PathNodeFsOptions{
ClientInodes: true}) ClientInodes: true})
me.connector = nodefs.NewFileSystemConnector(me.pathFs.Root(), tc.connector = nodefs.NewFileSystemConnector(tc.pathFs.Root(),
&nodefs.Options{ &nodefs.Options{
EntryTimeout: testTtl, EntryTimeout: testTtl,
AttrTimeout: testTtl, AttrTimeout: testTtl,
NegativeTimeout: 0.0, NegativeTimeout: 0.0,
}) })
me.connector.SetDebug(VerboseTest()) tc.connector.SetDebug(VerboseTest())
me.state, err = fuse.NewServer( tc.state, err = fuse.NewServer(
fuse.NewRawFileSystem(me.connector.RawFS()), me.mnt, &fuse.MountOptions{SingleThreaded: true}) fuse.NewRawFileSystem(tc.connector.RawFS()), tc.mnt, &fuse.MountOptions{SingleThreaded: true})
if err != nil { if err != nil {
t.Fatal("NewServer:", err) t.Fatal("NewServer:", err)
} }
me.state.SetDebug(VerboseTest()) tc.state.SetDebug(VerboseTest())
// Unthreaded, but in background. // Unthreaded, but in background.
go me.state.Serve() go tc.state.Serve()
me.state.WaitMount() tc.state.WaitMount()
return me return tc
} }
// Unmount and del. // Unmount and del.
...@@ -109,30 +109,30 @@ func (tc *testCase) rootNode() *nodefs.Inode { ...@@ -109,30 +109,30 @@ func (tc *testCase) rootNode() *nodefs.Inode {
// Tests. // Tests.
func TestOpenUnreadable(t *testing.T) { func TestOpenUnreadable(t *testing.T) {
ts := NewTestCase(t) tc := NewTestCase(t)
defer ts.Cleanup() defer tc.Cleanup()
_, err := os.Open(ts.mnt + "/doesnotexist") _, err := os.Open(tc.mnt + "/doesnotexist")
if err == nil { if err == nil {
t.Errorf("open non-existent should raise error") t.Errorf("open non-existent should raise error")
} }
} }
func TestReadThrough(t *testing.T) { func TestReadThrough(t *testing.T) {
ts := NewTestCase(t) tc := NewTestCase(t)
defer ts.Cleanup() defer tc.Cleanup()
content := RandomData(125) content := RandomData(125)
err := ioutil.WriteFile(ts.origFile, content, 0700) err := ioutil.WriteFile(tc.origFile, content, 0700)
if err != nil { if err != nil {
t.Fatalf("WriteFile failed: %v", err) t.Fatalf("WriteFile failed: %v", err)
} }
err = os.Chmod(ts.mountFile, os.FileMode(mode)) err = os.Chmod(tc.mountFile, os.FileMode(mode))
if err != nil { if err != nil {
t.Fatalf("Chmod failed: %v", err) t.Fatalf("Chmod failed: %v", err)
} }
fi, err := os.Lstat(ts.mountFile) fi, err := os.Lstat(tc.mountFile)
if err != nil { if err != nil {
t.Fatalf("Lstat failed: %v", err) t.Fatalf("Lstat failed: %v", err)
} }
...@@ -141,7 +141,7 @@ func TestReadThrough(t *testing.T) { ...@@ -141,7 +141,7 @@ func TestReadThrough(t *testing.T) {
} }
// Open (for read), read. // Open (for read), read.
f, err := os.Open(ts.mountFile) f, err := os.Open(tc.mountFile)
if err != nil { if err != nil {
t.Fatalf("Open failed: %v", err) t.Fatalf("Open failed: %v", err)
} }
...@@ -407,25 +407,24 @@ func TestRename(t *testing.T) { ...@@ -407,25 +407,24 @@ func TestRename(t *testing.T) {
defer tc.Cleanup() defer tc.Cleanup()
contents := []byte{1, 2, 3} contents := []byte{1, 2, 3}
err := ioutil.WriteFile(tc.origFile, []byte(contents), 0700) if err := ioutil.WriteFile(tc.origFile, []byte(contents), 0700); err != nil {
if err != nil {
t.Fatalf("WriteFile failed: %v", err) t.Fatalf("WriteFile failed: %v", err)
} }
sd := tc.mnt + "/testRename" sd := tc.mnt + "/testRename"
err = os.MkdirAll(sd, 0777) if err := os.MkdirAll(sd, 0777); err != nil {
t.Fatalf("MkdirAll(%q): %v", sd, err)
}
subFile := sd + "/subfile" subFile := sd + "/subfile"
err = os.Rename(tc.mountFile, subFile) if err := os.Rename(tc.mountFile, subFile); err != nil {
if err != nil {
t.Fatalf("Rename failed: %v", err) t.Fatalf("Rename failed: %v", err)
} }
f, _ := os.Lstat(tc.origFile) f, _ := os.Lstat(tc.origFile)
if f != nil { if f != nil {
t.Errorf("original %v still exists.", tc.origFile) t.Errorf("original %v still exists.", tc.origFile)
} }
f, _ = os.Lstat(subFile) if _, err := os.Lstat(subFile); err != nil {
if f == nil { t.Errorf("destination %q does not exist: %v", subFile, err)
t.Errorf("destination %v does not exist.", subFile)
} }
} }
...@@ -437,14 +436,12 @@ func TestDelRename(t *testing.T) { ...@@ -437,14 +436,12 @@ func TestDelRename(t *testing.T) {
t.Log("Testing del+rename.") t.Log("Testing del+rename.")
sd := tc.mnt + "/testDelRename" sd := tc.mnt + "/testDelRename"
err := os.MkdirAll(sd, 0755) if err := os.MkdirAll(sd, 0755); err != nil {
if err != nil {
t.Fatalf("MkdirAll failed: %v", err) t.Fatalf("MkdirAll failed: %v", err)
} }
d := sd + "/dest" d := sd + "/dest"
err = ioutil.WriteFile(d, []byte("blabla"), 0644) if err := ioutil.WriteFile(d, []byte("blabla"), 0644); err != nil {
if err != nil {
t.Fatalf("WriteFile failed: %v", err) t.Fatalf("WriteFile failed: %v", err)
} }
...@@ -454,19 +451,16 @@ func TestDelRename(t *testing.T) { ...@@ -454,19 +451,16 @@ func TestDelRename(t *testing.T) {
} }
defer f.Close() defer f.Close()
err = os.Remove(d) if err := os.Remove(d); err != nil {
if err != nil {
t.Fatalf("Remove failed: %v", err) t.Fatalf("Remove failed: %v", err)
} }
s := sd + "/src" s := sd + "/src"
err = ioutil.WriteFile(s, []byte("blabla"), 0644) if err = ioutil.WriteFile(s, []byte("blabla"), 0644); err != nil {
if err != nil {
t.Fatalf("WriteFile failed: %v", err) t.Fatalf("WriteFile failed: %v", err)
} }
err = os.Rename(s, d) if err := os.Rename(s, d); err != nil {
if err != nil {
t.Fatalf("Rename failed: %v", err) t.Fatalf("Rename failed: %v", err)
} }
} }
...@@ -478,25 +472,21 @@ func TestOverwriteRename(t *testing.T) { ...@@ -478,25 +472,21 @@ func TestOverwriteRename(t *testing.T) {
t.Log("Testing rename overwrite.") t.Log("Testing rename overwrite.")
sd := tc.mnt + "/testOverwriteRename" sd := tc.mnt + "/testOverwriteRename"
err := os.MkdirAll(sd, 0755) if err := os.MkdirAll(sd, 0755); err != nil {
if err != nil {
t.Fatalf("MkdirAll failed: %v", err) t.Fatalf("MkdirAll failed: %v", err)
} }
d := sd + "/dest" d := sd + "/dest"
err = ioutil.WriteFile(d, []byte("blabla"), 0644) if err := ioutil.WriteFile(d, []byte("blabla"), 0644); err != nil {
if err != nil {
t.Fatalf("WriteFile failed: %v", err) t.Fatalf("WriteFile failed: %v", err)
} }
s := sd + "/src" s := sd + "/src"
err = ioutil.WriteFile(s, []byte("blabla"), 0644) if err := ioutil.WriteFile(s, []byte("blabla"), 0644); err != nil {
if err != nil {
t.Fatalf("WriteFile failed: %v", err) t.Fatalf("WriteFile failed: %v", err)
} }
err = os.Rename(s, d) if err := os.Rename(s, d); err != nil {
if err != nil {
t.Fatalf("Rename failed: %v", err) t.Fatalf("Rename failed: %v", err)
} }
} }
...@@ -510,27 +500,24 @@ func TestAccess(t *testing.T) { ...@@ -510,27 +500,24 @@ func TestAccess(t *testing.T) {
defer tc.Cleanup() defer tc.Cleanup()
contents := []byte{1, 2, 3} contents := []byte{1, 2, 3}
err := ioutil.WriteFile(tc.origFile, []byte(contents), 0700) if err := ioutil.WriteFile(tc.origFile, []byte(contents), 0700); err != nil {
if err != nil {
t.Fatalf("WriteFile failed: %v", err) t.Fatalf("WriteFile failed: %v", err)
} }
err = os.Chmod(tc.origFile, 0) if err := os.Chmod(tc.origFile, 0); err != nil {
if err != nil {
t.Fatalf("Chmod failed: %v", err) t.Fatalf("Chmod failed: %v", err)
} }
// Ugh - copied from unistd.h // Ugh - copied from unistd.h
const W_OK uint32 = 2 const W_OK uint32 = 2
errCode := syscall.Access(tc.mountFile, W_OK) if errCode := syscall.Access(tc.mountFile, W_OK); errCode != syscall.EACCES {
if errCode != syscall.EACCES {
t.Errorf("Expected EACCES for non-writable, %v %v", errCode, syscall.EACCES) t.Errorf("Expected EACCES for non-writable, %v %v", errCode, syscall.EACCES)
} }
err = os.Chmod(tc.origFile, 0222)
if err != nil { if err := os.Chmod(tc.origFile, 0222); err != nil {
t.Fatalf("Chmod failed: %v", err) t.Fatalf("Chmod failed: %v", err)
} }
errCode = syscall.Access(tc.mountFile, W_OK)
if errCode != nil { if errCode := syscall.Access(tc.mountFile, W_OK); errCode != nil {
t.Errorf("Expected no error code for writable. %v", errCode) t.Errorf("Expected no error code for writable. %v", errCode)
} }
} }
...@@ -540,13 +527,14 @@ func TestMknod(t *testing.T) { ...@@ -540,13 +527,14 @@ func TestMknod(t *testing.T) {
defer tc.Cleanup() defer tc.Cleanup()
t.Log("Testing mknod.") t.Log("Testing mknod.")
errNo := syscall.Mknod(tc.mountFile, syscall.S_IFIFO|0777, 0) if errNo := syscall.Mknod(tc.mountFile, syscall.S_IFIFO|0777, 0); errNo != nil {
if errNo != nil {
t.Errorf("Mknod %v", errNo) t.Errorf("Mknod %v", errNo)
} }
fi, _ := os.Lstat(tc.origFile)
if fi == nil || fi.Mode()&os.ModeNamedPipe == 0 { if fi, err := os.Lstat(tc.origFile); err != nil {
t.Errorf("Expected FIFO filetype.") t.Errorf("Lstat(%q): %v", tc.origFile, err)
} else if fi.Mode()&os.ModeNamedPipe == 0 {
t.Errorf("Expected FIFO filetype, got %x", fi.Mode())
} }
} }
...@@ -555,12 +543,10 @@ func TestReaddir(t *testing.T) { ...@@ -555,12 +543,10 @@ func TestReaddir(t *testing.T) {
defer tc.Cleanup() defer tc.Cleanup()
contents := []byte{1, 2, 3} contents := []byte{1, 2, 3}
err := ioutil.WriteFile(tc.origFile, []byte(contents), 0700) if err := ioutil.WriteFile(tc.origFile, []byte(contents), 0700); err != nil {
if err != nil {
t.Fatalf(" failed: %v", err) t.Fatalf(" failed: %v", err)
} }
err = os.Mkdir(tc.origSubdir, 0777) if err := os.Mkdir(tc.origSubdir, 0777); err != nil {
if err != nil {
t.Fatalf("Mkdir failed: %v", err) t.Fatalf("Mkdir failed: %v", err)
} }
...@@ -568,6 +554,8 @@ func TestReaddir(t *testing.T) { ...@@ -568,6 +554,8 @@ func TestReaddir(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Open failed: %v", err) t.Fatalf("Open failed: %v", err)
} }
defer dir.Close()
infos, err := dir.Readdir(10) infos, err := dir.Readdir(10)
if err != nil { if err != nil {
t.Fatalf("Readdir failed: %v", err) t.Fatalf("Readdir failed: %v", err)
...@@ -587,8 +575,6 @@ func TestReaddir(t *testing.T) { ...@@ -587,8 +575,6 @@ func TestReaddir(t *testing.T) {
} }
} }
} }
dir.Close()
} }
func TestFSync(t *testing.T) { func TestFSync(t *testing.T) {
...@@ -596,14 +582,17 @@ func TestFSync(t *testing.T) { ...@@ -596,14 +582,17 @@ func TestFSync(t *testing.T) {
defer tc.Cleanup() defer tc.Cleanup()
contents := []byte{1, 2, 3} contents := []byte{1, 2, 3}
err := ioutil.WriteFile(tc.origFile, []byte(contents), 0700) if err := ioutil.WriteFile(tc.origFile, []byte(contents), 0700); err != nil {
if err != nil {
t.Fatalf("WriteFile failed: %v", err) t.Fatalf("WriteFile failed: %v", err)
} }
f, err := os.OpenFile(tc.mountFile, os.O_WRONLY, 0) f, err := os.OpenFile(tc.mountFile, os.O_WRONLY, 0)
_, err = f.WriteString("hello there")
if err != nil { if err != nil {
t.Fatalf("OpenFile(%q): %v", tc.mountFile, err)
}
defer f.Close()
if _, err := f.WriteString("hello there"); err != nil {
t.Fatalf("WriteString failed: %v", err) t.Fatalf("WriteString failed: %v", err)
} }
...@@ -612,22 +601,19 @@ func TestFSync(t *testing.T) { ...@@ -612,22 +601,19 @@ func TestFSync(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("fsync returned: %v", err) t.Errorf("fsync returned: %v", err)
} }
f.Close()
} }
func TestReadZero(t *testing.T) { func TestReadZero(t *testing.T) {
ts := NewTestCase(t) tc := NewTestCase(t)
defer ts.Cleanup() defer tc.Cleanup()
err := ioutil.WriteFile(ts.origFile, []byte{}, 0644) if err := ioutil.WriteFile(tc.origFile, []byte{}, 0644); err != nil {
if err != nil {
t.Fatalf("WriteFile failed: %v", err) t.Fatalf("WriteFile failed: %v", err)
} }
back, err := ioutil.ReadFile(ts.mountFile) back, err := ioutil.ReadFile(tc.mountFile)
if err != nil { if err != nil {
t.Fatalf("ReadFile failed: %v", err) t.Fatalf("ReadFile(%q): %v", tc.mountFile, err)
} } else if len(back) != 0 {
if len(back) != 0 {
t.Errorf("content length: got %d want %d", len(back), 0) t.Errorf("content length: got %d want %d", len(back), 0)
} }
} }
...@@ -670,19 +656,20 @@ func CompareSlices(t *testing.T, got, want []byte) { ...@@ -670,19 +656,20 @@ func CompareSlices(t *testing.T, got, want []byte) {
// Check that reading large files doesn't lead to large allocations. // Check that reading large files doesn't lead to large allocations.
func TestReadLargeMemCheck(t *testing.T) { func TestReadLargeMemCheck(t *testing.T) {
ts := NewTestCase(t) tc := NewTestCase(t)
defer ts.Cleanup() defer tc.Cleanup()
content := RandomData(385 * 1023) content := RandomData(385 * 1023)
err := ioutil.WriteFile(ts.origFile, []byte(content), 0644) if err := ioutil.WriteFile(tc.origFile, []byte(content), 0644); err != nil {
if err != nil {
t.Fatalf("WriteFile failed: %v", err) t.Fatalf("WriteFile failed: %v", err)
} }
f, err := os.Open(ts.mountFile) f, err := os.Open(tc.mountFile)
if err != nil { if err != nil {
t.Fatalf("Open failed: %v", err) t.Fatalf("Open failed: %v", err)
} }
defer f.Close()
buf := make([]byte, len(content)+1024) buf := make([]byte, len(content)+1024)
f.Read(buf) f.Read(buf)
if err != nil { if err != nil {
...@@ -695,7 +682,7 @@ func TestReadLargeMemCheck(t *testing.T) { ...@@ -695,7 +682,7 @@ func TestReadLargeMemCheck(t *testing.T) {
N := 100 N := 100
runtime.ReadMemStats(&before) runtime.ReadMemStats(&before)
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
f, _ := os.Open(ts.mountFile) f, _ := os.Open(tc.mountFile)
f.Read(buf) f.Read(buf)
f.Close() f.Close()
} }
...@@ -706,16 +693,15 @@ func TestReadLargeMemCheck(t *testing.T) { ...@@ -706,16 +693,15 @@ func TestReadLargeMemCheck(t *testing.T) {
} }
func TestReadLarge(t *testing.T) { func TestReadLarge(t *testing.T) {
ts := NewTestCase(t) tc := NewTestCase(t)
defer ts.Cleanup() defer tc.Cleanup()
content := RandomData(385 * 1023) content := RandomData(385 * 1023)
err := ioutil.WriteFile(ts.origFile, []byte(content), 0644) if err := ioutil.WriteFile(tc.origFile, []byte(content), 0644); err != nil {
if err != nil {
t.Fatalf("WriteFile failed: %v", err) t.Fatalf("WriteFile failed: %v", err)
} }
back, err := ioutil.ReadFile(ts.mountFile) back, err := ioutil.ReadFile(tc.mountFile)
if err != nil { if err != nil {
t.Fatalf("ReadFile failed: %v", err) t.Fatalf("ReadFile failed: %v", err)
} }
...@@ -744,7 +730,10 @@ func TestLargeDirRead(t *testing.T) { ...@@ -744,7 +730,10 @@ func TestLargeDirRead(t *testing.T) {
names := make([]string, created) names := make([]string, created)
subdir := filepath.Join(tc.orig, "readdirSubdir") subdir := filepath.Join(tc.orig, "readdirSubdir")
os.Mkdir(subdir, 0700) if err := os.Mkdir(subdir, 0700); err != nil {
t.Fatalf("Mkdir(%q): %v", subdir, err)
}
longname := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" longname := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
nameSet := make(map[string]bool) nameSet := make(map[string]bool)
...@@ -756,12 +745,9 @@ func TestLargeDirRead(t *testing.T) { ...@@ -756,12 +745,9 @@ func TestLargeDirRead(t *testing.T) {
nameSet[base] = true nameSet[base] = true
f, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE, 0777) if err := ioutil.WriteFile(name, []byte("bla"), 0777); err != nil {
if err != nil { t.Fatalf("WriteFile(%q): %v", name, err)
t.Fatalf("OpenFile failed: %v", err)
} }
f.WriteString("bla")
f.Close()
names[i] = name names[i] = name
} }
...@@ -801,19 +787,18 @@ func TestLargeDirRead(t *testing.T) { ...@@ -801,19 +787,18 @@ func TestLargeDirRead(t *testing.T) {
} }
func TestRootDir(t *testing.T) { func TestRootDir(t *testing.T) {
ts := NewTestCase(t) tc := NewTestCase(t)
defer ts.Cleanup() defer tc.Cleanup()
d, err := os.Open(ts.mnt) d, err := os.Open(tc.mnt)
if err != nil { if err != nil {
t.Fatalf("Open failed: %v", err) t.Fatalf("Open failed: %v", err)
} }
_, err = d.Readdirnames(-1) if _, err := d.Readdirnames(-1); err != nil {
if err != nil {
t.Fatalf("Readdirnames failed: %v", err) t.Fatalf("Readdirnames failed: %v", err)
} }
err = d.Close()
if err != nil { if err := d.Close(); err != nil {
t.Fatalf("Close failed: %v", err) t.Fatalf("Close failed: %v", err)
} }
} }
...@@ -827,10 +812,10 @@ func ioctl(fd int, cmd int, arg uintptr) (int, int) { ...@@ -827,10 +812,10 @@ func ioctl(fd int, cmd int, arg uintptr) (int, int) {
} }
func TestIoctl(t *testing.T) { func TestIoctl(t *testing.T) {
ts := NewTestCase(t) tc := NewTestCase(t)
defer ts.Cleanup() defer tc.Cleanup()
f, err := os.OpenFile(filepath.Join(ts.mnt, "hello.txt"), f, err := os.OpenFile(filepath.Join(tc.mnt, "hello.txt"),
os.O_WRONLY|os.O_CREATE, 0777) os.O_WRONLY|os.O_CREATE, 0777)
if err != nil { if err != nil {
t.Fatalf("OpenFile failed: %v", err) t.Fatalf("OpenFile failed: %v", err)
...@@ -842,20 +827,17 @@ func TestIoctl(t *testing.T) { ...@@ -842,20 +827,17 @@ func TestIoctl(t *testing.T) {
// This test is racy. If an external process consumes space while this // This test is racy. If an external process consumes space while this
// runs, we may see spurious differences between the two statfs() calls. // runs, we may see spurious differences between the two statfs() calls.
func TestStatFs(t *testing.T) { func TestStatFs(t *testing.T) {
ts := NewTestCase(t) tc := NewTestCase(t)
defer ts.Cleanup() defer tc.Cleanup()
empty := syscall.Statfs_t{} empty := syscall.Statfs_t{}
s1 := empty s1 := empty
err := syscall.Statfs(ts.orig, &s1) if err := syscall.Statfs(tc.orig, &s1); err != nil {
if err != nil {
t.Fatal("statfs orig", err) t.Fatal("statfs orig", err)
} }
s2 := syscall.Statfs_t{} s2 := syscall.Statfs_t{}
err = syscall.Statfs(ts.mnt, &s2) if err := syscall.Statfs(tc.mnt, &s2); err != nil {
if err != nil {
t.Fatal("statfs mnt", err) t.Fatal("statfs mnt", err)
} }
...@@ -867,10 +849,10 @@ func TestStatFs(t *testing.T) { ...@@ -867,10 +849,10 @@ func TestStatFs(t *testing.T) {
} }
func TestFStatFs(t *testing.T) { func TestFStatFs(t *testing.T) {
ts := NewTestCase(t) tc := NewTestCase(t)
defer ts.Cleanup() defer tc.Cleanup()
fOrig, err := os.OpenFile(ts.orig+"/file", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0644) fOrig, err := os.OpenFile(tc.orig+"/file", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0644)
if err != nil { if err != nil {
t.Fatalf("OpenFile failed: %v", err) t.Fatalf("OpenFile failed: %v", err)
} }
...@@ -878,20 +860,18 @@ func TestFStatFs(t *testing.T) { ...@@ -878,20 +860,18 @@ func TestFStatFs(t *testing.T) {
empty := syscall.Statfs_t{} empty := syscall.Statfs_t{}
s1 := empty s1 := empty
errno := syscall.Fstatfs(int(fOrig.Fd()), &s1) if errno := syscall.Fstatfs(int(fOrig.Fd()), &s1); errno != nil {
if errno != nil {
t.Fatal("statfs orig", err) t.Fatal("statfs orig", err)
} }
fMnt, err := os.OpenFile(ts.mnt+"/file", os.O_RDWR, 0644) fMnt, err := os.OpenFile(tc.mnt+"/file", os.O_RDWR, 0644)
if err != nil { if err != nil {
t.Fatalf("OpenFile failed: %v", err) t.Fatalf("OpenFile failed: %v", err)
} }
defer fMnt.Close() defer fMnt.Close()
s2 := empty s2 := empty
errno = syscall.Fstatfs(int(fMnt.Fd()), &s2) if errno := syscall.Fstatfs(int(fMnt.Fd()), &s2); errno != nil {
if errno != nil {
t.Fatal("statfs mnt", err) t.Fatal("statfs mnt", err)
} }
...@@ -915,12 +895,10 @@ func TestOriginalIsSymlink(t *testing.T) { ...@@ -915,12 +895,10 @@ func TestOriginalIsSymlink(t *testing.T) {
} }
link := tmpDir + "/link" link := tmpDir + "/link"
mnt := tmpDir + "/mnt" mnt := tmpDir + "/mnt"
err = os.Mkdir(mnt, 0755) if err := os.Mkdir(mnt, 0755); err != nil {
if err != nil {
t.Fatalf("Mkdir failed: %v", err) t.Fatalf("Mkdir failed: %v", err)
} }
err = os.Symlink("orig", link) if err := os.Symlink("orig", link); err != nil {
if err != nil {
t.Fatalf("Symlink failed: %v", err) t.Fatalf("Symlink failed: %v", err)
} }
...@@ -934,28 +912,26 @@ func TestOriginalIsSymlink(t *testing.T) { ...@@ -934,28 +912,26 @@ func TestOriginalIsSymlink(t *testing.T) {
go state.Serve() go state.Serve()
_, err = os.Lstat(mnt) if _, err := os.Lstat(mnt); err != nil {
if err != nil {
t.Fatalf("Lstat failed: %v", err) t.Fatalf("Lstat failed: %v", err)
} }
} }
func TestDoubleOpen(t *testing.T) { func TestDoubleOpen(t *testing.T) {
ts := NewTestCase(t) tc := NewTestCase(t)
defer ts.Cleanup() defer tc.Cleanup()
err := ioutil.WriteFile(ts.orig+"/file", []byte("blabla"), 0644) if err := ioutil.WriteFile(tc.orig+"/file", []byte("blabla"), 0644); err != nil {
if err != nil {
t.Fatalf("WriteFile failed: %v", err) t.Fatalf("WriteFile failed: %v", err)
} }
roFile, err := os.Open(ts.mnt + "/file") roFile, err := os.Open(tc.mnt + "/file")
if err != nil { if err != nil {
t.Fatalf(" failed: %v", err) t.Fatalf(" failed: %v", err)
} }
defer roFile.Close() defer roFile.Close()
rwFile, err := os.OpenFile(ts.mnt+"/file", os.O_WRONLY|os.O_TRUNC, 0666) rwFile, err := os.OpenFile(tc.mnt+"/file", os.O_WRONLY|os.O_TRUNC, 0666)
if err != nil { if err != nil {
t.Fatalf("OpenFile failed: %v", err) t.Fatalf("OpenFile failed: %v", err)
} }
...@@ -963,15 +939,17 @@ func TestDoubleOpen(t *testing.T) { ...@@ -963,15 +939,17 @@ func TestDoubleOpen(t *testing.T) {
} }
func TestUmask(t *testing.T) { func TestUmask(t *testing.T) {
ts := NewTestCase(t) tc := NewTestCase(t)
defer ts.Cleanup() defer tc.Cleanup()
// Make sure system setting does not affect test. // Make sure system setting does not affect test.
fn := ts.mnt + "/file" fn := tc.mnt + "/file"
mask := 020 mask := 020
cmd := exec.Command("/bin/sh", "-c", cmd := exec.Command("/bin/sh", "-c",
fmt.Sprintf("umask %o && mkdir %s", mask, fn)) fmt.Sprintf("umask %o && mkdir %s", mask, fn))
cmd.Run() if err := cmd.Run(); err != nil {
t.Fatalf("cmd.Run: %v", err)
}
fi, err := os.Lstat(fn) fi, err := os.Lstat(fn)
if err != nil { if err != nil {
......
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