Commit 060980b2 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Drop CheckSuccess from rest of tests too.

parent ff72948e
...@@ -28,9 +28,11 @@ func (fs *cacheFs) Open(name string, flags uint32, context *Context) (fuseFile F ...@@ -28,9 +28,11 @@ func (fs *cacheFs) Open(name string, flags uint32, context *Context) (fuseFile F
} }
func setupCacheTest() (string, *PathNodeFs, func()) { func setupCacheTest(t *testing.T) (string, *PathNodeFs, func()) {
dir, err := ioutil.TempDir("", "go-fuse") dir, err := ioutil.TempDir("", "go-fuse")
CheckSuccess(err) if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
os.Mkdir(dir+"/mnt", 0755) os.Mkdir(dir+"/mnt", 0755)
os.Mkdir(dir+"/orig", 0755) os.Mkdir(dir+"/orig", 0755)
...@@ -39,7 +41,9 @@ func setupCacheTest() (string, *PathNodeFs, func()) { ...@@ -39,7 +41,9 @@ func setupCacheTest() (string, *PathNodeFs, func()) {
} }
pfs := NewPathNodeFs(fs, nil) pfs := NewPathNodeFs(fs, nil)
state, conn, err := MountNodeFileSystem(dir+"/mnt", pfs, nil) state, conn, err := MountNodeFileSystem(dir+"/mnt", pfs, nil)
CheckSuccess(err) if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
state.Debug = VerboseTest() state.Debug = VerboseTest()
conn.Debug = VerboseTest() conn.Debug = VerboseTest()
pfs.Debug = VerboseTest() pfs.Debug = VerboseTest()
...@@ -54,26 +58,34 @@ func setupCacheTest() (string, *PathNodeFs, func()) { ...@@ -54,26 +58,34 @@ func setupCacheTest() (string, *PathNodeFs, func()) {
} }
func TestCacheFs(t *testing.T) { func TestCacheFs(t *testing.T) {
wd, pathfs, clean := setupCacheTest() wd, pathfs, clean := setupCacheTest(t)
defer clean() defer clean()
content1 := "hello" content1 := "hello"
content2 := "qqqq" content2 := "qqqq"
err := ioutil.WriteFile(wd+"/orig/file.txt", []byte(content1), 0644) err := ioutil.WriteFile(wd+"/orig/file.txt", []byte(content1), 0644)
CheckSuccess(err) if err != nil {
t.Fatalf("WriteFile failed: %v", err)
}
c, err := ioutil.ReadFile(wd + "/mnt/file.txt") c, err := ioutil.ReadFile(wd + "/mnt/file.txt")
CheckSuccess(err) if err != nil {
t.Fatalf("ReadFile failed: %v", err)
}
if string(c) != "hello" { if string(c) != "hello" {
t.Fatalf("expect 'hello' %q", string(c)) t.Fatalf("expect 'hello' %q", string(c))
} }
err = ioutil.WriteFile(wd+"/orig/file.txt", []byte(content2), 0644) err = ioutil.WriteFile(wd+"/orig/file.txt", []byte(content2), 0644)
CheckSuccess(err) if err != nil {
t.Fatalf("WriteFile failed: %v", err)
}
c, err = ioutil.ReadFile(wd + "/mnt/file.txt") c, err = ioutil.ReadFile(wd + "/mnt/file.txt")
CheckSuccess(err) if err != nil {
t.Fatalf("ReadFile failed: %v", err)
}
if string(c) != "hello" { if string(c) != "hello" {
t.Fatalf("Page cache skipped: expect 'hello' %q", string(c)) t.Fatalf("Page cache skipped: expect 'hello' %q", string(c))
...@@ -85,7 +97,9 @@ func TestCacheFs(t *testing.T) { ...@@ -85,7 +97,9 @@ func TestCacheFs(t *testing.T) {
} }
c, err = ioutil.ReadFile(wd + "/mnt/file.txt") c, err = ioutil.ReadFile(wd + "/mnt/file.txt")
CheckSuccess(err) if err != nil {
t.Fatalf("ReadFile failed: %v", err)
}
if string(c) != string(content2) { if string(c) != string(content2) {
t.Fatalf("Mismatch after notify expect '%s' %q", content2, string(c)) t.Fatalf("Mismatch after notify expect '%s' %q", content2, string(c))
} }
...@@ -121,18 +135,24 @@ func TestNonseekable(t *testing.T) { ...@@ -121,18 +135,24 @@ func TestNonseekable(t *testing.T) {
fs.Length = 200 * 1024 fs.Length = 200 * 1024
dir, err := ioutil.TempDir("", "go-fuse") dir, err := ioutil.TempDir("", "go-fuse")
CheckSuccess(err) if err != nil {
t.Fatalf("failed: %v", err)
}
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
nfs := NewPathNodeFs(fs, nil) nfs := NewPathNodeFs(fs, nil)
state, _, err := MountNodeFileSystem(dir, nfs, nil) state, _, err := MountNodeFileSystem(dir, nfs, nil)
CheckSuccess(err) if err != nil {
t.Fatalf("failed: %v", err)
}
state.Debug = VerboseTest() state.Debug = VerboseTest()
defer state.Unmount() defer state.Unmount()
go state.Loop() go state.Loop()
f, err := os.Open(dir + "/file") f, err := os.Open(dir + "/file")
CheckSuccess(err) if err != nil {
t.Fatalf("failed: %v", err)
}
defer f.Close() defer f.Close()
b := make([]byte, 200) b := make([]byte, 200)
...@@ -144,7 +164,9 @@ func TestNonseekable(t *testing.T) { ...@@ -144,7 +164,9 @@ func TestNonseekable(t *testing.T) {
func TestGetAttrRace(t *testing.T) { func TestGetAttrRace(t *testing.T) {
dir, err := ioutil.TempDir("", "go-fuse") dir, err := ioutil.TempDir("", "go-fuse")
CheckSuccess(err) if err != nil {
t.Fatalf("failed: %v", err)
}
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
os.Mkdir(dir+"/mnt", 0755) os.Mkdir(dir+"/mnt", 0755)
os.Mkdir(dir+"/orig", 0755) os.Mkdir(dir+"/orig", 0755)
...@@ -153,7 +175,9 @@ func TestGetAttrRace(t *testing.T) { ...@@ -153,7 +175,9 @@ func TestGetAttrRace(t *testing.T) {
pfs := NewPathNodeFs(fs, nil) pfs := NewPathNodeFs(fs, nil)
state, conn, err := MountNodeFileSystem(dir+"/mnt", pfs, state, conn, err := MountNodeFileSystem(dir+"/mnt", pfs,
&FileSystemOptions{}) &FileSystemOptions{})
CheckSuccess(err) if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
state.Debug = VerboseTest() state.Debug = VerboseTest()
conn.Debug = VerboseTest() conn.Debug = VerboseTest()
pfs.Debug = VerboseTest() pfs.Debug = VerboseTest()
......
...@@ -8,10 +8,14 @@ import ( ...@@ -8,10 +8,14 @@ import (
func TestCopyFile(t *testing.T) { func TestCopyFile(t *testing.T) {
d1, err := ioutil.TempDir("", "go-fuse") d1, err := ioutil.TempDir("", "go-fuse")
CheckSuccess(err) if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
defer os.RemoveAll(d1) defer os.RemoveAll(d1)
d2, err := ioutil.TempDir("", "go-fuse") d2, err := ioutil.TempDir("", "go-fuse")
CheckSuccess(err) if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
defer os.RemoveAll(d2) defer os.RemoveAll(d2)
fs1 := NewLoopbackFileSystem(d1) fs1 := NewLoopbackFileSystem(d1)
...@@ -20,7 +24,9 @@ func TestCopyFile(t *testing.T) { ...@@ -20,7 +24,9 @@ func TestCopyFile(t *testing.T) {
content1 := "blabla" content1 := "blabla"
err = ioutil.WriteFile(d1+"/file", []byte(content1), 0644) err = ioutil.WriteFile(d1+"/file", []byte(content1), 0644)
CheckSuccess(err) if err != nil {
t.Fatalf("WriteFile failed: %v", err)
}
code := CopyFile(fs1, fs2, "file", "file", nil) code := CopyFile(fs1, fs2, "file", "file", nil)
if !code.Ok() { if !code.Ok() {
...@@ -35,7 +41,9 @@ func TestCopyFile(t *testing.T) { ...@@ -35,7 +41,9 @@ func TestCopyFile(t *testing.T) {
content2 := "foobar" content2 := "foobar"
err = ioutil.WriteFile(d2+"/file", []byte(content2), 0644) err = ioutil.WriteFile(d2+"/file", []byte(content2), 0644)
CheckSuccess(err) if err != nil {
t.Fatalf("WriteFile failed: %v", err)
}
// Copy back: should overwrite. // Copy back: should overwrite.
code = CopyFile(fs2, fs1, "file", "file", nil) code = CopyFile(fs2, fs1, "file", "file", nil)
......
...@@ -29,17 +29,21 @@ func (fs *DefaultReadFS) Open(name string, f uint32, context *Context) (File, St ...@@ -29,17 +29,21 @@ func (fs *DefaultReadFS) Open(name string, f uint32, context *Context) (File, St
return &DefaultFile{}, OK return &DefaultFile{}, OK
} }
func defaultReadTest() (root string, cleanup func()) { func defaultReadTest(t *testing.T) (root string, cleanup func()) {
fs := &DefaultReadFS{} fs := &DefaultReadFS{}
var err error var err error
dir, err := ioutil.TempDir("", "go-fuse") dir, err := ioutil.TempDir("", "go-fuse")
CheckSuccess(err) if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
pathfs := NewPathNodeFs(fs, nil) pathfs := NewPathNodeFs(fs, nil)
state, _, err := MountNodeFileSystem(dir, pathfs, nil) state, _, err := MountNodeFileSystem(dir, pathfs, nil)
CheckSuccess(err) if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
state.Debug = VerboseTest() state.Debug = VerboseTest()
go state.Loop() go state.Loop()
return dir, func() { return dir, func() {
state.Unmount() state.Unmount()
os.Remove(dir) os.Remove(dir)
...@@ -47,7 +51,7 @@ func defaultReadTest() (root string, cleanup func()) { ...@@ -47,7 +51,7 @@ func defaultReadTest() (root string, cleanup func()) {
} }
func TestDefaultRead(t *testing.T) { func TestDefaultRead(t *testing.T) {
root, clean := defaultReadTest() root, clean := defaultReadTest(t)
defer clean() defer clean()
_, err := ioutil.ReadFile(root + "/file") _, err := ioutil.ReadFile(root + "/file")
......
...@@ -132,10 +132,14 @@ func NewFile() *MutableDataFile { ...@@ -132,10 +132,14 @@ func NewFile() *MutableDataFile {
func setupFAttrTest(t *testing.T, fs FileSystem) (dir string, clean func(), sync func()) { func setupFAttrTest(t *testing.T, fs FileSystem) (dir string, clean func(), sync func()) {
dir, err := ioutil.TempDir("", "go-fuse") dir, err := ioutil.TempDir("", "go-fuse")
CheckSuccess(err) if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
nfs := NewPathNodeFs(fs, nil) nfs := NewPathNodeFs(fs, nil)
state, _, err := MountNodeFileSystem(dir, nfs, nil) state, _, err := MountNodeFileSystem(dir, nfs, nil)
CheckSuccess(err) if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
state.Debug = VerboseTest() state.Debug = VerboseTest()
go state.Loop() go state.Loop()
...@@ -163,10 +167,14 @@ func TestDataReadLarge(t *testing.T) { ...@@ -163,10 +167,14 @@ func TestDataReadLarge(t *testing.T) {
content := RandomData(385 * 1023) content := RandomData(385 * 1023)
fn := dir + "/file" fn := dir + "/file"
err := ioutil.WriteFile(fn, []byte(content), 0644) err := ioutil.WriteFile(fn, []byte(content), 0644)
CheckSuccess(err) if err != nil {
t.Fatalf("WriteFile failed: %v", err)
}
back, err := ioutil.ReadFile(fn) back, err := ioutil.ReadFile(fn)
CheckSuccess(err) if err != nil {
t.Fatalf("ReadFile failed: %v", err)
}
CompareSlices(t, back, content) CompareSlices(t, back, content)
} }
...@@ -178,13 +186,19 @@ func TestFSetAttr(t *testing.T) { ...@@ -178,13 +186,19 @@ func TestFSetAttr(t *testing.T) {
fn := dir + "/file" fn := dir + "/file"
f, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY, 0755) f, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY, 0755)
CheckSuccess(err) if err != nil {
t.Fatalf("OpenFile failed: %v", err)
}
defer f.Close() defer f.Close()
fi, err := f.Stat() fi, err := f.Stat()
CheckSuccess(err) if err != nil {
t.Fatalf("Stat failed: %v", err)
}
_, err = f.WriteString("hello") _, err = f.WriteString("hello")
CheckSuccess(err) if err != nil {
t.Fatalf("WriteString failed: %v", err)
}
code := syscall.Ftruncate(int(f.Fd()), 3) code := syscall.Ftruncate(int(f.Fd()), 3)
if code != nil { if code != nil {
...@@ -197,14 +211,18 @@ func TestFSetAttr(t *testing.T) { ...@@ -197,14 +211,18 @@ func TestFSetAttr(t *testing.T) {
} }
err = f.Chmod(024) err = f.Chmod(024)
CheckSuccess(err) if err != nil {
t.Fatalf("Chmod failed: %v", err)
}
sync() sync()
if fs.file.Attr.Mode&07777 != 024 { if fs.file.Attr.Mode&07777 != 024 {
t.Error("chmod") t.Error("chmod")
} }
err = os.Chtimes(fn, time.Unix(0, 100e3), time.Unix(0, 101e3)) err = os.Chtimes(fn, time.Unix(0, 100e3), time.Unix(0, 101e3))
CheckSuccess(err) if err != nil {
t.Fatalf("Chtimes failed: %v", err)
}
sync() sync()
if fs.file.Attr.Atimensec != 100e3 || fs.file.Attr.Mtimensec != 101e3 { if fs.file.Attr.Atimensec != 100e3 || fs.file.Attr.Mtimensec != 101e3 {
t.Errorf("Utimens: atime %d != 100e3 mtime %d != 101e3", t.Errorf("Utimens: atime %d != 100e3 mtime %d != 101e3",
...@@ -212,7 +230,9 @@ func TestFSetAttr(t *testing.T) { ...@@ -212,7 +230,9 @@ func TestFSetAttr(t *testing.T) {
} }
newFi, err := f.Stat() newFi, err := f.Stat()
CheckSuccess(err) if err != nil {
t.Fatalf("Stat failed: %v", err)
}
i1 := ToStatT(fi).Ino i1 := ToStatT(fi).Ino
i2 := ToStatT(newFi).Ino i2 := ToStatT(newFi).Ino
if i1 != i2 { if i1 != i2 {
......
package fuse package fuse
import ( import (
"syscall" "syscall"
) )
func clearStatfs(s *syscall.Statfs_t) { func clearStatfs(s *syscall.Statfs_t) {
......
...@@ -14,13 +14,19 @@ func TestTouch(t *testing.T) { ...@@ -14,13 +14,19 @@ func TestTouch(t *testing.T) {
contents := []byte{1, 2, 3} contents := []byte{1, 2, 3}
err := ioutil.WriteFile(ts.origFile, []byte(contents), 0700) err := ioutil.WriteFile(ts.origFile, []byte(contents), 0700)
CheckSuccess(err) if err != nil {
t.Fatalf("WriteFile failed: %v", err)
}
err = os.Chtimes(ts.mountFile, time.Unix(42, 0), time.Unix(43, 0)) err = os.Chtimes(ts.mountFile, time.Unix(42, 0), time.Unix(43, 0))
CheckSuccess(err) if err != nil {
t.Fatalf("Chtimes failed: %v", err)
}
var stat syscall.Stat_t var stat syscall.Stat_t
err = syscall.Lstat(ts.mountFile, &stat) err = syscall.Lstat(ts.mountFile, &stat)
CheckSuccess(err) if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
if stat.Atim.Sec != 42 || stat.Mtim.Sec != 43 { if stat.Atim.Sec != 42 || stat.Mtim.Sec != 43 {
t.Errorf("Got wrong timestamps %v", stat) t.Errorf("Got wrong timestamps %v", stat)
} }
......
...@@ -55,7 +55,9 @@ func NewTestCase(t *testing.T) *testCase { ...@@ -55,7 +55,9 @@ func NewTestCase(t *testing.T) *testCase {
var err error var err error
me.tmpDir, err = ioutil.TempDir("", "go-fuse") me.tmpDir, err = ioutil.TempDir("", "go-fuse")
CheckSuccess(err) if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
me.orig = me.tmpDir + "/orig" me.orig = me.tmpDir + "/orig"
me.mnt = me.tmpDir + "/mnt" me.mnt = me.tmpDir + "/mnt"
...@@ -99,7 +101,9 @@ func NewTestCase(t *testing.T) *testCase { ...@@ -99,7 +101,9 @@ func NewTestCase(t *testing.T) *testCase {
// Unmount and del. // Unmount and del.
func (tc *testCase) Cleanup() { func (tc *testCase) Cleanup() {
err := tc.state.Unmount() err := tc.state.Unmount()
CheckSuccess(err) if err != nil {
tc.tester.Fatalf("Unmount failed: %v", err)
}
os.RemoveAll(tc.tmpDir) os.RemoveAll(tc.tmpDir)
} }
...@@ -126,17 +130,17 @@ func TestReadThrough(t *testing.T) { ...@@ -126,17 +130,17 @@ func TestReadThrough(t *testing.T) {
content := RandomData(125) content := RandomData(125)
err := ioutil.WriteFile(ts.origFile, content, 0700) err := ioutil.WriteFile(ts.origFile, content, 0700)
if err != nil { if err != nil {
t.Fatalf(" failed: %v", err) t.Fatalf("WriteFile failed: %v", err)
} }
err = os.Chmod(ts.mountFile, os.FileMode(mode)) err = os.Chmod(ts.mountFile, os.FileMode(mode))
if err != nil { if err != nil {
t.Fatalf(" failed: %v", err) t.Fatalf("Chmod failed: %v", err)
} }
fi, err := os.Lstat(ts.mountFile) fi, err := os.Lstat(ts.mountFile)
if err != nil { if err != nil {
t.Fatalf(" failed: %v", err) t.Fatalf("Lstat failed: %v", err)
} }
if uint32(fi.Mode().Perm()) != mode { if uint32(fi.Mode().Perm()) != mode {
t.Errorf("Wrong mode %o != %o", int(fi.Mode().Perm()), mode) t.Errorf("Wrong mode %o != %o", int(fi.Mode().Perm()), mode)
...@@ -145,7 +149,7 @@ func TestReadThrough(t *testing.T) { ...@@ -145,7 +149,7 @@ func TestReadThrough(t *testing.T) {
// Open (for read), read. // Open (for read), read.
f, err := os.Open(ts.mountFile) f, err := os.Open(ts.mountFile)
if err != nil { if err != nil {
t.Fatalf(" failed: %v", err) t.Fatalf("Open failed: %v", err)
} }
defer f.Close() defer f.Close()
...@@ -992,7 +996,7 @@ func TestFallocate(t *testing.T) { ...@@ -992,7 +996,7 @@ func TestFallocate(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Lstat failed: %v", err) t.Fatalf("Lstat failed: %v", err)
} }
if fi.Size() < (1024+4096) { if fi.Size() < (1024 + 4096) {
t.Fatalf("fallocate should have changed file size. Got %d bytes", t.Fatalf("fallocate should have changed file size. Got %d bytes",
fi.Size()) fi.Size())
} }
......
...@@ -11,7 +11,9 @@ var _ = log.Println ...@@ -11,7 +11,9 @@ var _ = log.Println
func setupMemNodeTest(t *testing.T) (wd string, fs *MemNodeFs, clean func()) { func setupMemNodeTest(t *testing.T) (wd string, fs *MemNodeFs, clean func()) {
tmp, err := ioutil.TempDir("", "go-fuse") tmp, err := ioutil.TempDir("", "go-fuse")
CheckSuccess(err) if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
back := tmp + "/backing" back := tmp + "/backing"
os.Mkdir(back, 0700) os.Mkdir(back, 0700)
fs = NewMemNodeFs(back) fs = NewMemNodeFs(back)
...@@ -46,7 +48,9 @@ func TestMemNodeFsWrite(t *testing.T) { ...@@ -46,7 +48,9 @@ func TestMemNodeFsWrite(t *testing.T) {
want := "hello" want := "hello"
err := ioutil.WriteFile(wd+"/test", []byte(want), 0644) err := ioutil.WriteFile(wd+"/test", []byte(want), 0644)
CheckSuccess(err) if err != nil {
t.Fatalf("WriteFile failed: %v", err)
}
content, err := ioutil.ReadFile(wd + "/test") content, err := ioutil.ReadFile(wd + "/test")
if string(content) != want { if string(content) != want {
...@@ -59,10 +63,14 @@ func TestMemNodeFs(t *testing.T) { ...@@ -59,10 +63,14 @@ func TestMemNodeFs(t *testing.T) {
defer clean() defer clean()
err := ioutil.WriteFile(wd+"/test", []byte{42}, 0644) err := ioutil.WriteFile(wd+"/test", []byte{42}, 0644)
CheckSuccess(err) if err != nil {
t.Fatalf("WriteFile failed: %v", err)
}
fi, err := os.Lstat(wd + "/test") fi, err := os.Lstat(wd + "/test")
CheckSuccess(err) if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
if fi.Size() != 1 { if fi.Size() != 1 {
t.Errorf("Size after write incorrect: got %d want 1", fi.Size()) t.Errorf("Size after write incorrect: got %d want 1", fi.Size())
} }
...@@ -78,14 +86,20 @@ func TestMemNodeSetattr(t *testing.T) { ...@@ -78,14 +86,20 @@ func TestMemNodeSetattr(t *testing.T) {
defer clean() defer clean()
f, err := os.OpenFile(wd+"/test", os.O_CREATE|os.O_WRONLY, 0644) f, err := os.OpenFile(wd+"/test", os.O_CREATE|os.O_WRONLY, 0644)
CheckSuccess(err) if err != nil {
t.Fatalf("OpenFile failed: %v", err)
}
defer f.Close() defer f.Close()
err = f.Truncate(4096) err = f.Truncate(4096)
CheckSuccess(err) if err != nil {
t.Fatalf("Truncate failed: %v", err)
}
fi, err := f.Stat() fi, err := f.Stat()
CheckSuccess(err) if err != nil {
t.Fatalf("Stat failed: %v", err)
}
if fi.Size() != 4096 { if fi.Size() != 4096 {
t.Errorf("Size should be 4096 after Truncate: %d", fi.Size()) t.Errorf("Size should be 4096 after Truncate: %d", fi.Size())
} }
......
...@@ -71,12 +71,6 @@ func ModeToType(mode uint32) uint32 { ...@@ -71,12 +71,6 @@ func ModeToType(mode uint32) uint32 {
return (mode & 0170000) >> 12 return (mode & 0170000) >> 12
} }
func CheckSuccess(e error) {
if e != nil {
log.Panicf("Unexpected error: %v", e)
}
}
// Thanks to Andrew Gerrand for this hack. // Thanks to Andrew Gerrand for this hack.
func toSlice(dest *[]byte, ptr unsafe.Pointer, byteCount uintptr) { func toSlice(dest *[]byte, ptr unsafe.Pointer, byteCount uintptr) {
h := (*reflect.SliceHeader)(unsafe.Pointer(dest)) h := (*reflect.SliceHeader)(unsafe.Pointer(dest))
......
...@@ -13,7 +13,9 @@ func TestMountOnExisting(t *testing.T) { ...@@ -13,7 +13,9 @@ func TestMountOnExisting(t *testing.T) {
defer ts.Cleanup() defer ts.Cleanup()
err := os.Mkdir(ts.mnt+"/mnt", 0777) err := os.Mkdir(ts.mnt+"/mnt", 0777)
CheckSuccess(err) if err != nil {
t.Fatalf("Mkdir failed: %v", err)
}
nfs := &DefaultNodeFileSystem{} nfs := &DefaultNodeFileSystem{}
code := ts.connector.Mount(ts.rootNode(), "mnt", nfs, nil) code := ts.connector.Mount(ts.rootNode(), "mnt", nfs, nil)
if code != EBUSY { if code != EBUSY {
...@@ -21,7 +23,9 @@ func TestMountOnExisting(t *testing.T) { ...@@ -21,7 +23,9 @@ func TestMountOnExisting(t *testing.T) {
} }
err = os.Remove(ts.mnt + "/mnt") err = os.Remove(ts.mnt + "/mnt")
CheckSuccess(err) if err != nil {
t.Fatalf("Remove failed: %v", err)
}
code = ts.connector.Mount(ts.rootNode(), "mnt", nfs, nil) code = ts.connector.Mount(ts.rootNode(), "mnt", nfs, nil)
if !code.Ok() { if !code.Ok() {
t.Fatal("expect OK:", code) t.Fatal("expect OK:", code)
...@@ -60,7 +64,9 @@ func TestMountReaddir(t *testing.T) { ...@@ -60,7 +64,9 @@ func TestMountReaddir(t *testing.T) {
} }
entries, err := ioutil.ReadDir(ts.mnt) entries, err := ioutil.ReadDir(ts.mnt)
CheckSuccess(err) if err != nil {
t.Fatalf("ReadDir failed: %v", err)
}
if len(entries) != 1 || entries[0].Name() != "mnt" { if len(entries) != 1 || entries[0].Name() != "mnt" {
t.Error("wrong readdir result", entries) t.Error("wrong readdir result", entries)
} }
...@@ -72,7 +78,9 @@ func TestRecursiveMount(t *testing.T) { ...@@ -72,7 +78,9 @@ func TestRecursiveMount(t *testing.T) {
defer ts.Cleanup() defer ts.Cleanup()
err := ioutil.WriteFile(ts.orig+"/hello.txt", []byte("blabla"), 0644) err := ioutil.WriteFile(ts.orig+"/hello.txt", []byte("blabla"), 0644)
CheckSuccess(err) if err != nil {
t.Fatalf("WriteFile failed: %v", err)
}
fs := NewPathNodeFs(NewLoopbackFileSystem(ts.orig), nil) fs := NewPathNodeFs(NewLoopbackFileSystem(ts.orig), nil)
code := ts.connector.Mount(ts.rootNode(), "mnt", fs, nil) code := ts.connector.Mount(ts.rootNode(), "mnt", fs, nil)
...@@ -82,12 +90,18 @@ func TestRecursiveMount(t *testing.T) { ...@@ -82,12 +90,18 @@ func TestRecursiveMount(t *testing.T) {
submnt := ts.mnt + "/mnt" submnt := ts.mnt + "/mnt"
_, err = os.Lstat(submnt) _, err = os.Lstat(submnt)
CheckSuccess(err) if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
_, err = os.Lstat(filepath.Join(submnt, "hello.txt")) _, err = os.Lstat(filepath.Join(submnt, "hello.txt"))
CheckSuccess(err) if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
f, err := os.Open(filepath.Join(submnt, "hello.txt")) f, err := os.Open(filepath.Join(submnt, "hello.txt"))
CheckSuccess(err) if err != nil {
t.Fatalf("Open failed: %v", err)
}
t.Log("Attempting unmount, should fail") t.Log("Attempting unmount, should fail")
code = ts.pathFs.Unmount("mnt") code = ts.pathFs.Unmount("mnt")
if code != EBUSY { if code != EBUSY {
...@@ -116,15 +130,21 @@ func TestDeletedUnmount(t *testing.T) { ...@@ -116,15 +130,21 @@ func TestDeletedUnmount(t *testing.T) {
t.Fatal("Mount error", code) t.Fatal("Mount error", code)
} }
f, err := os.Create(filepath.Join(submnt, "hello.txt")) f, err := os.Create(filepath.Join(submnt, "hello.txt"))
CheckSuccess(err) if err != nil {
t.Fatalf("Create failed: %v", err)
}
t.Log("Removing") t.Log("Removing")
err = os.Remove(filepath.Join(submnt, "hello.txt")) err = os.Remove(filepath.Join(submnt, "hello.txt"))
CheckSuccess(err) if err != nil {
t.Fatalf("Remove failed: %v", err)
}
t.Log("Removing") t.Log("Removing")
_, err = f.Write([]byte("bla")) _, err = f.Write([]byte("bla"))
CheckSuccess(err) if err != nil {
t.Fatalf("Write failed: %v", err)
}
code = ts.pathFs.Unmount("mnt") code = ts.pathFs.Unmount("mnt")
if code != EBUSY { if code != EBUSY {
......
...@@ -41,12 +41,14 @@ type NotifyTest struct { ...@@ -41,12 +41,14 @@ type NotifyTest struct {
state *MountState state *MountState
} }
func NewNotifyTest() *NotifyTest { func NewNotifyTest(t *testing.T) *NotifyTest {
me := &NotifyTest{} me := &NotifyTest{}
me.fs = &NotifyFs{} me.fs = &NotifyFs{}
var err error var err error
me.dir, err = ioutil.TempDir("", "go-fuse") me.dir, err = ioutil.TempDir("", "go-fuse")
CheckSuccess(err) if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
entryTtl := 100 * time.Millisecond entryTtl := 100 * time.Millisecond
opts := &FileSystemOptions{ opts := &FileSystemOptions{
EntryTimeout: entryTtl, EntryTimeout: entryTtl,
...@@ -56,7 +58,9 @@ func NewNotifyTest() *NotifyTest { ...@@ -56,7 +58,9 @@ func NewNotifyTest() *NotifyTest {
me.pathfs = NewPathNodeFs(me.fs, nil) me.pathfs = NewPathNodeFs(me.fs, nil)
me.state, me.connector, err = MountNodeFileSystem(me.dir, me.pathfs, opts) me.state, me.connector, err = MountNodeFileSystem(me.dir, me.pathfs, opts)
CheckSuccess(err) if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
me.state.Debug = VerboseTest() me.state.Debug = VerboseTest()
go me.state.Loop() go me.state.Loop()
...@@ -71,7 +75,7 @@ func (t *NotifyTest) Clean() { ...@@ -71,7 +75,7 @@ func (t *NotifyTest) Clean() {
} }
func TestInodeNotify(t *testing.T) { func TestInodeNotify(t *testing.T) {
test := NewNotifyTest() test := NewNotifyTest(t)
defer test.Clean() defer test.Clean()
fs := test.fs fs := test.fs
...@@ -81,7 +85,9 @@ func TestInodeNotify(t *testing.T) { ...@@ -81,7 +85,9 @@ func TestInodeNotify(t *testing.T) {
test.state.ThreadSanitizerSync() test.state.ThreadSanitizerSync()
fi, err := os.Lstat(dir + "/file") fi, err := os.Lstat(dir + "/file")
CheckSuccess(err) if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
if fi.Mode()&os.ModeType != 0 || fi.Size() != 42 { if fi.Mode()&os.ModeType != 0 || fi.Size() != 42 {
t.Error(fi) t.Error(fi)
} }
...@@ -90,7 +96,9 @@ func TestInodeNotify(t *testing.T) { ...@@ -90,7 +96,9 @@ func TestInodeNotify(t *testing.T) {
fs.size = 666 fs.size = 666
fi, err = os.Lstat(dir + "/file") fi, err = os.Lstat(dir + "/file")
CheckSuccess(err) if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
if fi.Mode()&os.ModeType != 0 || fi.Size() == 666 { if fi.Mode()&os.ModeType != 0 || fi.Size() == 666 {
t.Error(fi) t.Error(fi)
} }
...@@ -101,14 +109,16 @@ func TestInodeNotify(t *testing.T) { ...@@ -101,14 +109,16 @@ func TestInodeNotify(t *testing.T) {
} }
fi, err = os.Lstat(dir + "/file") fi, err = os.Lstat(dir + "/file")
CheckSuccess(err) if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
if fi.Mode()&os.ModeType != 0 || fi.Size() != 666 { if fi.Mode()&os.ModeType != 0 || fi.Size() != 666 {
t.Error(fi) t.Error(fi)
} }
} }
func TestEntryNotify(t *testing.T) { func TestEntryNotify(t *testing.T) {
test := NewNotifyTest() test := NewNotifyTest(t)
defer test.Clean() defer test.Clean()
dir := test.dir dir := test.dir
...@@ -135,5 +145,7 @@ func TestEntryNotify(t *testing.T) { ...@@ -135,5 +145,7 @@ func TestEntryNotify(t *testing.T) {
} }
fi, err := os.Lstat(fn) fi, err := os.Lstat(fn)
CheckSuccess(err) if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
} }
...@@ -27,13 +27,15 @@ func (fs *ownerFs) GetAttr(name string, context *Context) (*Attr, Status) { ...@@ -27,13 +27,15 @@ func (fs *ownerFs) GetAttr(name string, context *Context) (*Attr, Status) {
return a, OK return a, OK
} }
func setupOwnerTest(opts *FileSystemOptions) (workdir string, cleanup func()) { func setupOwnerTest(t *testing.T, opts *FileSystemOptions) (workdir string, cleanup func()) {
wd, err := ioutil.TempDir("", "go-fuse") wd, err := ioutil.TempDir("", "go-fuse")
fs := &ownerFs{} fs := &ownerFs{}
nfs := NewPathNodeFs(fs, nil) nfs := NewPathNodeFs(fs, nil)
state, _, err := MountNodeFileSystem(wd, nfs, opts) state, _, err := MountNodeFileSystem(wd, nfs, opts)
CheckSuccess(err) if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
go state.Loop() go state.Loop()
return wd, func() { return wd, func() {
state.Unmount() state.Unmount()
...@@ -42,12 +44,14 @@ func setupOwnerTest(opts *FileSystemOptions) (workdir string, cleanup func()) { ...@@ -42,12 +44,14 @@ func setupOwnerTest(opts *FileSystemOptions) (workdir string, cleanup func()) {
} }
func TestOwnerDefault(t *testing.T) { func TestOwnerDefault(t *testing.T) {
wd, cleanup := setupOwnerTest(NewFileSystemOptions()) wd, cleanup := setupOwnerTest(t, NewFileSystemOptions())
defer cleanup() defer cleanup()
var stat syscall.Stat_t var stat syscall.Stat_t
err := syscall.Lstat(wd+"/foo", &stat) err := syscall.Lstat(wd+"/foo", &stat)
CheckSuccess(err) if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
if int(stat.Uid) != os.Getuid() || int(stat.Gid) != os.Getgid() { if int(stat.Uid) != os.Getuid() || int(stat.Gid) != os.Getgid() {
t.Fatal("Should use current uid for mount") t.Fatal("Should use current uid for mount")
...@@ -55,12 +59,14 @@ func TestOwnerDefault(t *testing.T) { ...@@ -55,12 +59,14 @@ func TestOwnerDefault(t *testing.T) {
} }
func TestOwnerRoot(t *testing.T) { func TestOwnerRoot(t *testing.T) {
wd, cleanup := setupOwnerTest(&FileSystemOptions{}) wd, cleanup := setupOwnerTest(t, &FileSystemOptions{})
defer cleanup() defer cleanup()
var st syscall.Stat_t var st syscall.Stat_t
err := syscall.Lstat(wd+"/foo", &st) err := syscall.Lstat(wd+"/foo", &st)
CheckSuccess(err) if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
if st.Uid != _RANDOM_OWNER || st.Gid != _RANDOM_OWNER { if st.Uid != _RANDOM_OWNER || st.Gid != _RANDOM_OWNER {
t.Fatal("Should use FS owner uid") t.Fatal("Should use FS owner uid")
...@@ -68,12 +74,14 @@ func TestOwnerRoot(t *testing.T) { ...@@ -68,12 +74,14 @@ func TestOwnerRoot(t *testing.T) {
} }
func TestOwnerOverride(t *testing.T) { func TestOwnerOverride(t *testing.T) {
wd, cleanup := setupOwnerTest(&FileSystemOptions{Owner: &Owner{42, 43}}) wd, cleanup := setupOwnerTest(t, &FileSystemOptions{Owner: &Owner{42, 43}})
defer cleanup() defer cleanup()
var stat syscall.Stat_t var stat syscall.Stat_t
err := syscall.Lstat(wd+"/foo", &stat) err := syscall.Lstat(wd+"/foo", &stat)
CheckSuccess(err) if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
if stat.Uid != 42 || stat.Gid != 43 { if stat.Uid != 42 || stat.Gid != 43 {
t.Fatal("Should use current uid for mount") t.Fatal("Should use current uid for mount")
......
...@@ -42,7 +42,9 @@ func TestMemoryPressure(t *testing.T) { ...@@ -42,7 +42,9 @@ func TestMemoryPressure(t *testing.T) {
} }
dir, err := ioutil.TempDir("", "go-fuse") dir, err := ioutil.TempDir("", "go-fuse")
CheckSuccess(err) if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
nfs := NewPathNodeFs(fs, nil) nfs := NewPathNodeFs(fs, nil)
o := &FileSystemOptions{PortableInodes: true} o := &FileSystemOptions{PortableInodes: true}
......
...@@ -104,12 +104,16 @@ func xattrTestCase(t *testing.T, nm string) (mountPoint string, cleanup func()) ...@@ -104,12 +104,16 @@ func xattrTestCase(t *testing.T, nm string) (mountPoint string, cleanup func())
xfs := NewXAttrFs(nm, xattrGolden) xfs := NewXAttrFs(nm, xattrGolden)
xfs.tester = t xfs.tester = t
mountPoint, err := ioutil.TempDir("", "go-fuse") mountPoint, err := ioutil.TempDir("", "go-fuse")
CheckSuccess(err) if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
defer os.RemoveAll(mountPoint) defer os.RemoveAll(mountPoint)
nfs := NewPathNodeFs(xfs, nil) nfs := NewPathNodeFs(xfs, nil)
state, _, err := MountNodeFileSystem(mountPoint, nfs, nil) state, _, err := MountNodeFileSystem(mountPoint, nfs, nil)
CheckSuccess(err) if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
state.Debug = VerboseTest() state.Debug = VerboseTest()
go state.Loop() go state.Loop()
......
...@@ -13,8 +13,6 @@ import ( ...@@ -13,8 +13,6 @@ import (
var _ = fmt.Print var _ = fmt.Print
var _ = log.Print var _ = log.Print
var CheckSuccess = fuse.CheckSuccess
const entryTtl = 100 * time.Millisecond const entryTtl = 100 * time.Millisecond
var testAOpts = AutoUnionFsOptions{ var testAOpts = AutoUnionFsOptions{
...@@ -27,29 +25,39 @@ var testAOpts = AutoUnionFsOptions{ ...@@ -27,29 +25,39 @@ var testAOpts = AutoUnionFsOptions{
HideReadonly: true, HideReadonly: true,
} }
func WriteFile(name string, contents string) { func WriteFile(t *testing.T, name string, contents string) {
err := ioutil.WriteFile(name, []byte(contents), 0644) err := ioutil.WriteFile(name, []byte(contents), 0644)
CheckSuccess(err) if err != nil {
t.Fatalf("WriteFile failed: %v", err)
}
} }
func setup(t *testing.T) (workdir string, cleanup func()) { func setup(t *testing.T) (workdir string, cleanup func()) {
wd, _ := ioutil.TempDir("", "") wd, _ := ioutil.TempDir("", "")
err := os.Mkdir(wd+"/mnt", 0700) err := os.Mkdir(wd+"/mnt", 0700)
fuse.CheckSuccess(err) if err != nil {
t.Fatalf("Mkdir failed: %v", err)
}
err = os.Mkdir(wd+"/store", 0700) err = os.Mkdir(wd+"/store", 0700)
fuse.CheckSuccess(err) if err != nil {
t.Fatalf("Mkdir failed: %v", err)
}
os.Mkdir(wd+"/ro", 0700) os.Mkdir(wd+"/ro", 0700)
fuse.CheckSuccess(err) if err != nil {
WriteFile(wd+"/ro/file1", "file1") t.Fatalf("Mkdir failed: %v", err)
WriteFile(wd+"/ro/file2", "file2") }
WriteFile(t, wd+"/ro/file1", "file1")
WriteFile(t, wd+"/ro/file2", "file2")
fs := NewAutoUnionFs(wd+"/store", testAOpts) fs := NewAutoUnionFs(wd+"/store", testAOpts)
nfs := fuse.NewPathNodeFs(fs, nil) nfs := fuse.NewPathNodeFs(fs, nil)
state, conn, err := fuse.MountNodeFileSystem(wd+"/mnt", nfs, &testAOpts.FileSystemOptions) state, conn, err := fuse.MountNodeFileSystem(wd+"/mnt", nfs, &testAOpts.FileSystemOptions)
CheckSuccess(err) if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
state.Debug = fuse.VerboseTest() state.Debug = fuse.VerboseTest()
conn.Debug = fuse.VerboseTest() conn.Debug = fuse.VerboseTest()
go state.Loop() go state.Loop()
...@@ -65,7 +73,9 @@ func TestDebug(t *testing.T) { ...@@ -65,7 +73,9 @@ func TestDebug(t *testing.T) {
defer clean() defer clean()
c, err := ioutil.ReadFile(wd + "/mnt/status/debug") c, err := ioutil.ReadFile(wd + "/mnt/status/debug")
CheckSuccess(err) if err != nil {
t.Fatalf("ReadFile failed: %v", err)
}
if len(c) == 0 { if len(c) == 0 {
t.Fatal("No debug found.") t.Fatal("No debug found.")
} }
...@@ -77,7 +87,9 @@ func TestVersion(t *testing.T) { ...@@ -77,7 +87,9 @@ func TestVersion(t *testing.T) {
defer clean() defer clean()
c, err := ioutil.ReadFile(wd + "/mnt/status/gounionfs_version") c, err := ioutil.ReadFile(wd + "/mnt/status/gounionfs_version")
CheckSuccess(err) if err != nil {
t.Fatalf("ReadFile failed: %v", err)
}
if len(c) == 0 { if len(c) == 0 {
t.Fatal("No version found.") t.Fatal("No version found.")
} }
...@@ -89,25 +101,37 @@ func TestAutoFsSymlink(t *testing.T) { ...@@ -89,25 +101,37 @@ func TestAutoFsSymlink(t *testing.T) {
defer clean() defer clean()
err := os.Mkdir(wd+"/store/backing1", 0755) err := os.Mkdir(wd+"/store/backing1", 0755)
CheckSuccess(err) if err != nil {
t.Fatalf("Mkdir failed: %v", err)
}
err = os.Symlink(wd+"/ro", wd+"/store/backing1/READONLY") err = os.Symlink(wd+"/ro", wd+"/store/backing1/READONLY")
CheckSuccess(err) if err != nil {
t.Fatalf("Symlink failed: %v", err)
}
err = os.Symlink(wd+"/store/backing1", wd+"/mnt/config/manual1") err = os.Symlink(wd+"/store/backing1", wd+"/mnt/config/manual1")
CheckSuccess(err) if err != nil {
t.Fatalf("Symlink failed: %v", err)
}
fi, err := os.Lstat(wd + "/mnt/manual1/file1") fi, err := os.Lstat(wd + "/mnt/manual1/file1")
CheckSuccess(err) if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
entries, err := ioutil.ReadDir(wd + "/mnt") entries, err := ioutil.ReadDir(wd + "/mnt")
CheckSuccess(err) if err != nil {
t.Fatalf("ReadDir failed: %v", err)
}
if len(entries) != 3 { if len(entries) != 3 {
t.Error("readdir mismatch", entries) t.Error("readdir mismatch", entries)
} }
err = os.Remove(wd + "/mnt/config/manual1") err = os.Remove(wd + "/mnt/config/manual1")
CheckSuccess(err) if err != nil {
t.Fatalf("Remove failed: %v", err)
}
scan := wd + "/mnt/config/" + _SCAN_CONFIG scan := wd + "/mnt/config/" + _SCAN_CONFIG
err = ioutil.WriteFile(scan, []byte("something"), 0644) err = ioutil.WriteFile(scan, []byte("something"), 0644)
...@@ -121,10 +145,14 @@ func TestAutoFsSymlink(t *testing.T) { ...@@ -121,10 +145,14 @@ func TestAutoFsSymlink(t *testing.T) {
} }
_, err = ioutil.ReadDir(wd + "/mnt/config") _, err = ioutil.ReadDir(wd + "/mnt/config")
CheckSuccess(err) if err != nil {
t.Fatalf("ReadDir failed: %v", err)
}
_, err = os.Lstat(wd + "/mnt/backing1/file1") _, err = os.Lstat(wd + "/mnt/backing1/file1")
CheckSuccess(err) if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
} }
func TestDetectSymlinkedDirectories(t *testing.T) { func TestDetectSymlinkedDirectories(t *testing.T) {
...@@ -132,13 +160,19 @@ func TestDetectSymlinkedDirectories(t *testing.T) { ...@@ -132,13 +160,19 @@ func TestDetectSymlinkedDirectories(t *testing.T) {
defer clean() defer clean()
err := os.Mkdir(wd+"/backing1", 0755) err := os.Mkdir(wd+"/backing1", 0755)
CheckSuccess(err) if err != nil {
t.Fatalf("Mkdir failed: %v", err)
}
err = os.Symlink(wd+"/ro", wd+"/backing1/READONLY") err = os.Symlink(wd+"/ro", wd+"/backing1/READONLY")
CheckSuccess(err) if err != nil {
t.Fatalf("Symlink failed: %v", err)
}
err = os.Symlink(wd+"/backing1", wd+"/store/backing1") err = os.Symlink(wd+"/backing1", wd+"/store/backing1")
CheckSuccess(err) if err != nil {
t.Fatalf("Symlink failed: %v", err)
}
scan := wd + "/mnt/config/" + _SCAN_CONFIG scan := wd + "/mnt/config/" + _SCAN_CONFIG
err = ioutil.WriteFile(scan, []byte("something"), 0644) err = ioutil.WriteFile(scan, []byte("something"), 0644)
...@@ -147,7 +181,9 @@ func TestDetectSymlinkedDirectories(t *testing.T) { ...@@ -147,7 +181,9 @@ func TestDetectSymlinkedDirectories(t *testing.T) {
} }
_, err = os.Lstat(wd + "/mnt/backing1") _, err = os.Lstat(wd + "/mnt/backing1")
CheckSuccess(err) if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
} }
func TestExplicitScan(t *testing.T) { func TestExplicitScan(t *testing.T) {
...@@ -155,9 +191,13 @@ func TestExplicitScan(t *testing.T) { ...@@ -155,9 +191,13 @@ func TestExplicitScan(t *testing.T) {
defer clean() defer clean()
err := os.Mkdir(wd+"/store/backing1", 0755) err := os.Mkdir(wd+"/store/backing1", 0755)
CheckSuccess(err) if err != nil {
t.Fatalf("Mkdir failed: %v", err)
}
os.Symlink(wd+"/ro", wd+"/store/backing1/READONLY") os.Symlink(wd+"/ro", wd+"/store/backing1/READONLY")
CheckSuccess(err) if err != nil {
t.Fatalf("Symlink failed: %v", err)
}
fi, _ := os.Lstat(wd + "/mnt/backing1") fi, _ := os.Lstat(wd + "/mnt/backing1")
if fi != nil { if fi != nil {
...@@ -186,17 +226,27 @@ func TestCreationChecks(t *testing.T) { ...@@ -186,17 +226,27 @@ func TestCreationChecks(t *testing.T) {
defer clean() defer clean()
err := os.Mkdir(wd+"/store/foo", 0755) err := os.Mkdir(wd+"/store/foo", 0755)
CheckSuccess(err) if err != nil {
t.Fatalf("Mkdir failed: %v", err)
}
os.Symlink(wd+"/ro", wd+"/store/foo/READONLY") os.Symlink(wd+"/ro", wd+"/store/foo/READONLY")
CheckSuccess(err) if err != nil {
t.Fatalf("Symlink failed: %v", err)
}
err = os.Mkdir(wd+"/store/ws2", 0755) err = os.Mkdir(wd+"/store/ws2", 0755)
CheckSuccess(err) if err != nil {
t.Fatalf("Mkdir failed: %v", err)
}
os.Symlink(wd+"/ro", wd+"/store/ws2/READONLY") os.Symlink(wd+"/ro", wd+"/store/ws2/READONLY")
CheckSuccess(err) if err != nil {
t.Fatalf("Symlink failed: %v", err)
}
err = os.Symlink(wd+"/store/foo", wd+"/mnt/config/bar") err = os.Symlink(wd+"/store/foo", wd+"/mnt/config/bar")
CheckSuccess(err) if err != nil {
t.Fatalf("Symlink failed: %v", err)
}
err = os.Symlink(wd+"/store/foo", wd+"/mnt/config/foo") err = os.Symlink(wd+"/store/foo", wd+"/mnt/config/foo")
code := fuse.ToStatus(err) code := fuse.ToStatus(err)
......
This diff is collapsed.
...@@ -10,11 +10,10 @@ import ( ...@@ -10,11 +10,10 @@ import (
) )
var _ = log.Printf var _ = log.Printf
var CheckSuccess = fuse.CheckSuccess
const testTtl = 100 * time.Millisecond const testTtl = 100 * time.Millisecond
func setupMzfs() (mountPoint string, cleanup func()) { func setupMzfs(t *testing.T) (mountPoint string, cleanup func()) {
fs := NewMultiZipFs() fs := NewMultiZipFs()
mountPoint, _ = ioutil.TempDir("", "") mountPoint, _ = ioutil.TempDir("", "")
nfs := fuse.NewPathNodeFs(fs, nil) nfs := fuse.NewPathNodeFs(fs, nil)
...@@ -23,7 +22,9 @@ func setupMzfs() (mountPoint string, cleanup func()) { ...@@ -23,7 +22,9 @@ func setupMzfs() (mountPoint string, cleanup func()) {
AttrTimeout: testTtl, AttrTimeout: testTtl,
NegativeTimeout: 0.0, NegativeTimeout: 0.0,
}) })
CheckSuccess(err) if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
state.Debug = fuse.VerboseTest() state.Debug = fuse.VerboseTest()
go state.Loop() go state.Loop()
...@@ -34,7 +35,7 @@ func setupMzfs() (mountPoint string, cleanup func()) { ...@@ -34,7 +35,7 @@ func setupMzfs() (mountPoint string, cleanup func()) {
} }
func TestMultiZipReadonly(t *testing.T) { func TestMultiZipReadonly(t *testing.T) {
mountPoint, cleanup := setupMzfs() mountPoint, cleanup := setupMzfs(t)
defer cleanup() defer cleanup()
_, err := os.Create(mountPoint + "/random") _, err := os.Create(mountPoint + "/random")
...@@ -49,19 +50,23 @@ func TestMultiZipReadonly(t *testing.T) { ...@@ -49,19 +50,23 @@ func TestMultiZipReadonly(t *testing.T) {
} }
func TestMultiZipFs(t *testing.T) { func TestMultiZipFs(t *testing.T) {
mountPoint, cleanup := setupMzfs() mountPoint, cleanup := setupMzfs(t)
defer cleanup() defer cleanup()
zipFile := testZipFile() zipFile := testZipFile()
entries, err := ioutil.ReadDir(mountPoint) entries, err := ioutil.ReadDir(mountPoint)
CheckSuccess(err) if err != nil {
t.Fatalf("ReadDir failed: %v", err)
}
if len(entries) != 1 || string(entries[0].Name()) != "config" { if len(entries) != 1 || string(entries[0].Name()) != "config" {
t.Errorf("wrong names return. %v", entries) t.Errorf("wrong names return. %v", entries)
} }
err = os.Symlink(zipFile, mountPoint+"/config/zipmount") err = os.Symlink(zipFile, mountPoint+"/config/zipmount")
CheckSuccess(err) if err != nil {
t.Fatalf("Symlink failed: %v", err)
}
fi, err := os.Lstat(mountPoint + "/zipmount") fi, err := os.Lstat(mountPoint + "/zipmount")
if !fi.IsDir() { if !fi.IsDir() {
...@@ -69,33 +74,43 @@ func TestMultiZipFs(t *testing.T) { ...@@ -69,33 +74,43 @@ func TestMultiZipFs(t *testing.T) {
} }
entries, err = ioutil.ReadDir(mountPoint) entries, err = ioutil.ReadDir(mountPoint)
CheckSuccess(err) if err != nil {
t.Fatalf("ReadDir failed: %v", err)
}
if len(entries) != 2 { if len(entries) != 2 {
t.Error("Expect 2 entries", entries) t.Error("Expect 2 entries", entries)
} }
val, err := os.Readlink(mountPoint + "/config/zipmount") val, err := os.Readlink(mountPoint + "/config/zipmount")
CheckSuccess(err) if err != nil {
t.Fatalf("Readlink failed: %v", err)
}
if val != zipFile { if val != zipFile {
t.Errorf("expected %v got %v", zipFile, val) t.Errorf("expected %v got %v", zipFile, val)
} }
fi, err = os.Lstat(mountPoint + "/zipmount") fi, err = os.Lstat(mountPoint + "/zipmount")
CheckSuccess(err) if err != nil {
t.Fatalf("Lstat failed: %v", err)
}
if !fi.IsDir() { if !fi.IsDir() {
t.Fatal("expect directory for /zipmount, got %v", fi) t.Fatal("expect directory for /zipmount, got %v", fi)
} }
// Check that zipfs itself works. // Check that zipfs itself works.
fi, err = os.Stat(mountPoint + "/zipmount/subdir") fi, err = os.Stat(mountPoint + "/zipmount/subdir")
CheckSuccess(err) if err != nil {
t.Fatalf("Stat failed: %v", err)
}
if !fi.IsDir() { if !fi.IsDir() {
t.Error("directory type", fi) t.Error("directory type", fi)
} }
// Removing the config dir unmount // Removing the config dir unmount
err = os.Remove(mountPoint + "/config/zipmount") err = os.Remove(mountPoint + "/config/zipmount")
CheckSuccess(err) if err != nil {
t.Fatalf("Remove failed: %v", err)
}
fi, err = os.Stat(mountPoint + "/zipmount") fi, err = os.Stat(mountPoint + "/zipmount")
if err == nil { if err == nil {
......
...@@ -18,9 +18,11 @@ func testZipFile() string { ...@@ -18,9 +18,11 @@ func testZipFile() string {
return filepath.Join(dir, "test.zip") return filepath.Join(dir, "test.zip")
} }
func setupZipfs() (mountPoint string, cleanup func()) { func setupZipfs(t *testing.T) (mountPoint string, cleanup func()) {
zfs, err := NewArchiveFileSystem(testZipFile()) zfs, err := NewArchiveFileSystem(testZipFile())
CheckSuccess(err) if err != nil {
t.Fatalf("NewArchiveFileSystem failed: %v", err)
}
mountPoint, _ = ioutil.TempDir("", "") mountPoint, _ = ioutil.TempDir("", "")
state, _, err := fuse.MountNodeFileSystem(mountPoint, zfs, nil) state, _, err := fuse.MountNodeFileSystem(mountPoint, zfs, nil)
...@@ -35,29 +37,37 @@ func setupZipfs() (mountPoint string, cleanup func()) { ...@@ -35,29 +37,37 @@ func setupZipfs() (mountPoint string, cleanup func()) {
} }
func TestZipFs(t *testing.T) { func TestZipFs(t *testing.T) {
mountPoint, clean := setupZipfs() mountPoint, clean := setupZipfs(t)
defer clean() defer clean()
entries, err := ioutil.ReadDir(mountPoint) entries, err := ioutil.ReadDir(mountPoint)
CheckSuccess(err) if err != nil {
t.Fatalf("ReadDir failed: %v", err)
}
if len(entries) != 2 { if len(entries) != 2 {
t.Error("wrong length", entries) t.Error("wrong length", entries)
} }
fi, err := os.Stat(mountPoint + "/subdir") fi, err := os.Stat(mountPoint + "/subdir")
CheckSuccess(err) if err != nil {
t.Fatalf("Stat failed: %v", err)
}
if !fi.IsDir() { if !fi.IsDir() {
t.Error("directory type", fi) t.Error("directory type", fi)
} }
fi, err = os.Stat(mountPoint + "/file.txt") fi, err = os.Stat(mountPoint + "/file.txt")
CheckSuccess(err) if err != nil {
t.Fatalf("Stat failed: %v", err)
}
if fi.IsDir() { if fi.IsDir() {
t.Error("file type", fi) t.Error("file type", fi)
} }
f, err := os.Open(mountPoint + "/file.txt") f, err := os.Open(mountPoint + "/file.txt")
CheckSuccess(err) if err != nil {
t.Fatalf("Open failed: %v", err)
}
b := make([]byte, 1024) b := make([]byte, 1024)
n, err := f.Read(b) n, err := f.Read(b)
...@@ -70,11 +80,13 @@ func TestZipFs(t *testing.T) { ...@@ -70,11 +80,13 @@ func TestZipFs(t *testing.T) {
} }
func TestLinkCount(t *testing.T) { func TestLinkCount(t *testing.T) {
mp, clean := setupZipfs() mp, clean := setupZipfs(t)
defer clean() defer clean()
fi, err := os.Stat(mp + "/file.txt") fi, err := os.Stat(mp + "/file.txt")
CheckSuccess(err) if err != nil {
t.Fatalf("Stat failed: %v", err)
}
if fuse.ToStatT(fi).Nlink != 1 { if fuse.ToStatT(fi).Nlink != 1 {
t.Fatal("wrong link count", fuse.ToStatT(fi).Nlink) t.Fatal("wrong link count", fuse.ToStatT(fi).Nlink)
} }
......
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