Commit a393c5e2 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Move loopback test and friends to separate package test/

parent 66031878
...@@ -5,10 +5,13 @@ import ( ...@@ -5,10 +5,13 @@ import (
"log" "log"
"os" "os"
"testing" "testing"
"time"
) )
var _ = log.Println var _ = log.Println
const testTtl = 100 * time.Millisecond
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-memnode_test") tmp, err := ioutil.TempDir("", "go-fuse-memnode_test")
if err != nil { if err != nil {
......
...@@ -126,10 +126,3 @@ func Removexattr(path string, attr string) (errno int) { ...@@ -126,10 +126,3 @@ func Removexattr(path string, attr string) (errno int) {
return int(errNo) return int(errNo)
} }
func ioctl(fd int, cmd int, arg uintptr) (int, int) {
r0, _, e1 := syscall.Syscall(
syscall.SYS_IOCTL, uintptr(fd), uintptr(cmd), uintptr(arg))
val := int(r0)
errno := int(e1)
return val, errno
}
...@@ -126,13 +126,6 @@ func Removexattr(path string, attr string) (errno int) { ...@@ -126,13 +126,6 @@ func Removexattr(path string, attr string) (errno int) {
return int(errNo) return int(errNo)
} }
func ioctl(fd int, cmd int, arg uintptr) (int, int) {
r0, _, e1 := syscall.Syscall(
syscall.SYS_IOCTL, uintptr(fd), uintptr(cmd), uintptr(arg))
val := int(r0)
errno := int(e1)
return val, errno
}
const AT_FDCWD = -100 const AT_FDCWD = -100
......
package fuse package test
import ( import (
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"testing" "testing"
"github.com/hanwen/go-fuse/fuse"
) )
var _ = log.Println var _ = log.Println
type DefaultReadFS struct { type DefaultReadFS struct {
DefaultFileSystem fuse.DefaultFileSystem
size uint64 size uint64
exist bool exist bool
} }
func (fs *DefaultReadFS) GetAttr(name string, context *Context) (*Attr, Status) { func (fs *DefaultReadFS) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
if name == "" { if name == "" {
return &Attr{Mode: S_IFDIR | 0755}, OK return &fuse.Attr{Mode: fuse.S_IFDIR | 0755}, fuse.OK
} }
if name == "file" { if name == "file" {
return &Attr{Mode: S_IFREG | 0644, Size: fs.size}, OK return &fuse.Attr{Mode: fuse.S_IFREG | 0644, Size: fs.size}, fuse.OK
} }
return nil, ENOENT return nil, fuse.ENOENT
} }
func (fs *DefaultReadFS) Open(name string, f uint32, context *Context) (File, Status) { func (fs *DefaultReadFS) Open(name string, f uint32, context *fuse.Context) (fuse.File, fuse.Status) {
return &DefaultFile{}, OK return &fuse.DefaultFile{}, fuse.OK
} }
func defaultReadTest(t *testing.T) (root string, cleanup func()) { func defaultReadTest(t *testing.T) (root string, cleanup func()) {
...@@ -36,12 +38,12 @@ func defaultReadTest(t *testing.T) (root string, cleanup func()) { ...@@ -36,12 +38,12 @@ func defaultReadTest(t *testing.T) (root string, cleanup func()) {
if err != nil { if err != nil {
t.Fatalf("TempDir failed: %v", err) t.Fatalf("TempDir failed: %v", err)
} }
pathfs := NewPathNodeFs(fs, nil) pathfs := fuse.NewPathNodeFs(fs, nil)
state, _, err := MountNodeFileSystem(dir, pathfs, nil) state, _, err := fuse.MountNodeFileSystem(dir, pathfs, nil)
if err != nil { if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err) t.Fatalf("MountNodeFileSystem failed: %v", err)
} }
state.Debug = VerboseTest() state.Debug = fuse.VerboseTest()
go state.Loop() go state.Loop()
return dir, func() { return dir, func() {
......
package fuse package test
import ( import (
"bytes" "bytes"
...@@ -8,21 +8,23 @@ import ( ...@@ -8,21 +8,23 @@ import (
"syscall" "syscall"
"testing" "testing"
"time" "time"
"github.com/hanwen/go-fuse/fuse"
) )
type flipNode struct { type flipNode struct {
*memNode fuse.FsNode
ok chan int ok chan int
} }
func (f *flipNode) GetAttr(out *Attr, file File, c *Context) Status { func (f *flipNode) GetAttr(out *fuse.Attr, file fuse.File, c *fuse.Context) fuse.Status {
select { select {
case <-f.ok: case <-f.ok:
// use a status that is easily recognizable. // use a status that is easily recognizable.
return Status(syscall.EXDEV) return fuse.Status(syscall.EXDEV)
default: default:
} }
return f.memNode.GetAttr(out, file, c) return f.FsNode.GetAttr(out, file, c)
} }
func TestDeleteNotify(t *testing.T) { func TestDeleteNotify(t *testing.T) {
...@@ -31,10 +33,10 @@ func TestDeleteNotify(t *testing.T) { ...@@ -31,10 +33,10 @@ func TestDeleteNotify(t *testing.T) {
t.Fatalf("TempDir failed %v", err) t.Fatalf("TempDir failed %v", err)
} }
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
fs := NewMemNodeFs(dir + "/backing") fs := fuse.NewMemNodeFs(dir + "/backing")
conn := NewFileSystemConnector(fs, conn := fuse.NewFileSystemConnector(fs,
&FileSystemOptions{PortableInodes: true}) &fuse.FileSystemOptions{PortableInodes: true})
state := NewMountState(conn) state := fuse.NewMountState(conn)
mnt := dir + "/mnt" mnt := dir + "/mnt"
err = os.Mkdir(mnt, 0755) err = os.Mkdir(mnt, 0755)
if err != nil { if err != nil {
...@@ -44,7 +46,7 @@ func TestDeleteNotify(t *testing.T) { ...@@ -44,7 +46,7 @@ func TestDeleteNotify(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
state.Debug = VerboseTest() state.Debug = fuse.VerboseTest()
go state.Loop() go state.Loop()
defer state.Unmount() defer state.Unmount()
...@@ -54,9 +56,9 @@ func TestDeleteNotify(t *testing.T) { ...@@ -54,9 +56,9 @@ func TestDeleteNotify(t *testing.T) {
} }
ch := fs.Root().Inode().RmChild("testdir") ch := fs.Root().Inode().RmChild("testdir")
ch.FsNode().(*memNode).SetInode(nil) ch.FsNode().SetInode(nil)
flip := flipNode{ flip := flipNode{
memNode: ch.FsNode().(*memNode), FsNode: ch.FsNode(),
ok: make(chan int), ok: make(chan int),
} }
newCh := fs.Root().Inode().New(true, &flip) newCh := fs.Root().Inode().New(true, &flip)
......
package fuse package test
import ( import (
"io/ioutil" "io/ioutil"
...@@ -8,13 +8,14 @@ import ( ...@@ -8,13 +8,14 @@ import (
"time" "time"
"github.com/hanwen/go-fuse/raw" "github.com/hanwen/go-fuse/raw"
"github.com/hanwen/go-fuse/fuse"
) )
type MutableDataFile struct { type MutableDataFile struct {
DefaultFile fuse.DefaultFile
data []byte data []byte
Attr fuse.Attr
GetAttrCalled bool GetAttrCalled bool
} }
...@@ -22,16 +23,16 @@ func (f *MutableDataFile) String() string { ...@@ -22,16 +23,16 @@ func (f *MutableDataFile) String() string {
return "MutableDataFile" return "MutableDataFile"
} }
func (f *MutableDataFile) Read(buf []byte, off int64) (ReadResult, Status) { func (f *MutableDataFile) Read(buf []byte, off int64) (fuse.ReadResult, fuse.Status) {
end := int(off) + len(buf) end := int(off) + len(buf)
if end > len(f.data) { if end > len(f.data) {
end = len(f.data) end = len(f.data)
} }
return &ReadResultData{Data: f.data[off:end]}, OK return &fuse.ReadResultData{Data: f.data[off:end]}, fuse.OK
} }
func (f *MutableDataFile) Write(d []byte, off int64) (uint32, Status) { func (f *MutableDataFile) Write(d []byte, off int64) (uint32, fuse.Status) {
end := int64(len(d)) + off end := int64(len(d)) + off
if int(end) > len(f.data) { if int(end) > len(f.data) {
data := make([]byte, len(f.data), end) data := make([]byte, len(f.data), end)
...@@ -41,106 +42,106 @@ func (f *MutableDataFile) Write(d []byte, off int64) (uint32, Status) { ...@@ -41,106 +42,106 @@ func (f *MutableDataFile) Write(d []byte, off int64) (uint32, Status) {
copy(f.data[off:end], d) copy(f.data[off:end], d)
f.Attr.Size = uint64(len(f.data)) f.Attr.Size = uint64(len(f.data))
return uint32(end - off), OK return uint32(end - off), fuse.OK
} }
func (f *MutableDataFile) Flush() Status { func (f *MutableDataFile) Flush() fuse.Status {
return OK return fuse.OK
} }
func (f *MutableDataFile) Release() { func (f *MutableDataFile) Release() {
} }
func (f *MutableDataFile) getAttr(out *Attr) { func (f *MutableDataFile) getAttr(out *fuse.Attr) {
*out = f.Attr *out = f.Attr
out.Size = uint64(len(f.data)) out.Size = uint64(len(f.data))
} }
func (f *MutableDataFile) GetAttr(out *Attr) Status { func (f *MutableDataFile) GetAttr(out *fuse.Attr) fuse.Status {
f.GetAttrCalled = true f.GetAttrCalled = true
f.getAttr(out) f.getAttr(out)
return OK return fuse.OK
} }
func (f *MutableDataFile) Utimens(atime *time.Time, mtime *time.Time) Status { func (f *MutableDataFile) Utimens(atime *time.Time, mtime *time.Time) fuse.Status {
f.Attr.SetTimes(atime, mtime, nil) f.Attr.SetTimes(atime, mtime, nil)
return OK return fuse.OK
} }
func (f *MutableDataFile) Truncate(size uint64) Status { func (f *MutableDataFile) Truncate(size uint64) fuse.Status {
f.data = f.data[:size] f.data = f.data[:size]
return OK return fuse.OK
} }
func (f *MutableDataFile) Chown(uid uint32, gid uint32) Status { func (f *MutableDataFile) Chown(uid uint32, gid uint32) fuse.Status {
f.Attr.Uid = uid f.Attr.Uid = uid
f.Attr.Gid = gid f.Attr.Gid = gid
return OK return fuse.OK
} }
func (f *MutableDataFile) Chmod(perms uint32) Status { func (f *MutableDataFile) Chmod(perms uint32) fuse.Status {
f.Attr.Mode = (f.Attr.Mode &^ 07777) | perms f.Attr.Mode = (f.Attr.Mode &^ 07777) | perms
return OK return fuse.OK
} }
//////////////// ////////////////
// This FS only supports a single r/w file called "/file". // This FS only supports a single r/w file called "/file".
type FSetAttrFs struct { type FSetAttrFs struct {
DefaultFileSystem fuse.DefaultFileSystem
file *MutableDataFile file *MutableDataFile
} }
func (fs *FSetAttrFs) GetXAttr(name string, attr string, context *Context) ([]byte, Status) { func (fs *FSetAttrFs) GetXAttr(name string, attr string, context *fuse.Context) ([]byte, fuse.Status) {
return nil, ENODATA return nil, fuse.ENODATA
} }
func (fs *FSetAttrFs) GetAttr(name string, context *Context) (*Attr, Status) { func (fs *FSetAttrFs) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
if name == "" { if name == "" {
return &Attr{Mode: S_IFDIR | 0700}, OK return &fuse.Attr{Mode: fuse.S_IFDIR | 0700}, fuse.OK
} }
if name == "file" && fs.file != nil { if name == "file" && fs.file != nil {
var a Attr var a fuse.Attr
fs.file.getAttr(&a) fs.file.getAttr(&a)
a.Mode |= S_IFREG a.Mode |= fuse.S_IFREG
return &a, OK return &a, fuse.OK
} }
return nil, ENOENT return nil, fuse.ENOENT
} }
func (fs *FSetAttrFs) Open(name string, flags uint32, context *Context) (File, Status) { func (fs *FSetAttrFs) Open(name string, flags uint32, context *fuse.Context) (fuse.File, fuse.Status) {
if name == "file" { if name == "file" {
return fs.file, OK return fs.file, fuse.OK
} }
return nil, ENOENT return nil, fuse.ENOENT
} }
func (fs *FSetAttrFs) Create(name string, flags uint32, mode uint32, context *Context) (File, Status) { func (fs *FSetAttrFs) Create(name string, flags uint32, mode uint32, context *fuse.Context) (fuse.File, fuse.Status) {
if name == "file" { if name == "file" {
f := NewFile() f := NewFile()
fs.file = f fs.file = f
fs.file.Attr.Mode = mode fs.file.Attr.Mode = mode
return f, OK return f, fuse.OK
} }
return nil, ENOENT return nil, fuse.ENOENT
} }
func NewFile() *MutableDataFile { func NewFile() *MutableDataFile {
return &MutableDataFile{} return &MutableDataFile{}
} }
func setupFAttrTest(t *testing.T, fs FileSystem) (dir string, clean func(), sync func()) { func setupFAttrTest(t *testing.T, fs fuse.FileSystem) (dir string, clean func(), sync func()) {
dir, err := ioutil.TempDir("", "go-fuse-fsetattr_test") dir, err := ioutil.TempDir("", "go-fuse-fsetattr_test")
if err != nil { if err != nil {
t.Fatalf("TempDir failed: %v", err) t.Fatalf("TempDir failed: %v", err)
} }
nfs := NewPathNodeFs(fs, nil) nfs := fuse.NewPathNodeFs(fs, nil)
state, _, err := MountNodeFileSystem(dir, nfs, nil) state, _, err := fuse.MountNodeFileSystem(dir, nfs, nil)
if err != nil { if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err) t.Fatalf("MountNodeFileSystem failed: %v", err)
} }
state.Debug = VerboseTest() state.Debug = fuse.VerboseTest()
go state.Loop() go state.Loop()
...@@ -233,8 +234,8 @@ func TestFSetAttr(t *testing.T) { ...@@ -233,8 +234,8 @@ func TestFSetAttr(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Stat failed: %v", err) t.Fatalf("Stat failed: %v", err)
} }
i1 := ToStatT(fi).Ino i1 := fuse.ToStatT(fi).Ino
i2 := ToStatT(newFi).Ino i2 := fuse.ToStatT(newFi).Ino
if i1 != i2 { if i1 != i2 {
t.Errorf("f.Lstat().Ino = %d. Returned %d before.", i2, i1) t.Errorf("f.Lstat().Ino = %d. Returned %d before.", i2, i1)
} }
......
package fuse package test
import ( import (
"syscall" "syscall"
......
package fuse package test
import ( import (
"io/ioutil" "io/ioutil"
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"syscall" "syscall"
"testing" "testing"
"time" "time"
) )
func TestTouch(t *testing.T) { func TestTouch(t *testing.T) {
......
package fuse package test
import ( import (
"fmt" "fmt"
...@@ -14,6 +14,8 @@ import ( ...@@ -14,6 +14,8 @@ import (
"syscall" "syscall"
"testing" "testing"
"time" "time"
"github.com/hanwen/go-fuse/fuse"
) )
var _ = strings.Join var _ = strings.Join
...@@ -34,9 +36,9 @@ type testCase struct { ...@@ -34,9 +36,9 @@ type testCase struct {
origFile string origFile string
origSubdir string origSubdir string
tester *testing.T tester *testing.T
state *MountState state *fuse.MountState
pathFs *PathNodeFs pathFs *fuse.PathNodeFs
connector *FileSystemConnector connector *fuse.FileSystemConnector
} }
const testTtl = 100 * time.Millisecond const testTtl = 100 * time.Millisecond
...@@ -45,7 +47,6 @@ const testTtl = 100 * time.Millisecond ...@@ -45,7 +47,6 @@ const testTtl = 100 * time.Millisecond
func NewTestCase(t *testing.T) *testCase { func NewTestCase(t *testing.T) *testCase {
me := &testCase{} me := &testCase{}
me.tester = t me.tester = t
paranoia = true
// Make sure system setting does not affect test. // Make sure system setting does not affect test.
syscall.Umask(0) syscall.Umask(0)
...@@ -69,27 +70,27 @@ func NewTestCase(t *testing.T) *testCase { ...@@ -69,27 +70,27 @@ func NewTestCase(t *testing.T) *testCase {
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)
var pfs FileSystem var pfs fuse.FileSystem
pfs = NewLoopbackFileSystem(me.orig) pfs = fuse.NewLoopbackFileSystem(me.orig)
pfs = NewLockingFileSystem(pfs) pfs = fuse.NewLockingFileSystem(pfs)
var rfs RawFileSystem var rfs fuse.RawFileSystem
me.pathFs = NewPathNodeFs(pfs, &PathNodeFsOptions{ me.pathFs = fuse.NewPathNodeFs(pfs, &fuse.PathNodeFsOptions{
ClientInodes: true}) ClientInodes: true})
me.connector = NewFileSystemConnector(me.pathFs, me.connector = fuse.NewFileSystemConnector(me.pathFs,
&FileSystemOptions{ &fuse.FileSystemOptions{
EntryTimeout: testTtl, EntryTimeout: testTtl,
AttrTimeout: testTtl, AttrTimeout: testTtl,
NegativeTimeout: 0.0, NegativeTimeout: 0.0,
}) })
rfs = me.connector rfs = me.connector
rfs = NewLockingRawFileSystem(rfs) rfs = fuse.NewLockingRawFileSystem(rfs)
me.connector.Debug = VerboseTest() me.connector.Debug = fuse.VerboseTest()
me.state = NewMountState(rfs) me.state = fuse.NewMountState(rfs)
me.state.Mount(me.mnt, nil) me.state.Mount(me.mnt, nil)
me.state.Debug = VerboseTest() me.state.Debug = fuse.VerboseTest()
// Unthreaded, but in background. // Unthreaded, but in background.
go me.state.Loop() go me.state.Loop()
...@@ -107,7 +108,7 @@ func (tc *testCase) Cleanup() { ...@@ -107,7 +108,7 @@ func (tc *testCase) Cleanup() {
os.RemoveAll(tc.tmpDir) os.RemoveAll(tc.tmpDir)
} }
func (tc *testCase) rootNode() *Inode { func (tc *testCase) rootNode() *fuse.Inode {
return tc.pathFs.Root().Inode() return tc.pathFs.Root().Inode()
} }
...@@ -821,6 +822,14 @@ func TestRootDir(t *testing.T) { ...@@ -821,6 +822,14 @@ func TestRootDir(t *testing.T) {
} }
} }
func ioctl(fd int, cmd int, arg uintptr) (int, int) {
r0, _, e1 := syscall.Syscall(
syscall.SYS_IOCTL, uintptr(fd), uintptr(cmd), uintptr(arg))
val := int(r0)
errno := int(e1)
return val, errno
}
func TestIoctl(t *testing.T) { func TestIoctl(t *testing.T) {
ts := NewTestCase(t) ts := NewTestCase(t)
defer ts.Cleanup() defer ts.Cleanup()
...@@ -919,9 +928,9 @@ func TestOriginalIsSymlink(t *testing.T) { ...@@ -919,9 +928,9 @@ func TestOriginalIsSymlink(t *testing.T) {
t.Fatalf("Symlink failed: %v", err) t.Fatalf("Symlink failed: %v", err)
} }
fs := NewLoopbackFileSystem(link) fs := fuse.NewLoopbackFileSystem(link)
nfs := NewPathNodeFs(fs, nil) nfs := fuse.NewPathNodeFs(fs, nil)
state, _, err := MountNodeFileSystem(mnt, nfs, nil) state, _, err := fuse.MountNodeFileSystem(mnt, nfs, nil)
if err != nil { if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err) t.Fatalf("MountNodeFileSystem failed: %v", err)
} }
......
package fuse package test
import ( import (
"io/ioutil" "io/ioutil"
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"time" "time"
"github.com/hanwen/go-fuse/fuse"
) )
func TestMountOnExisting(t *testing.T) { func TestMountOnExisting(t *testing.T) {
...@@ -16,9 +18,9 @@ func TestMountOnExisting(t *testing.T) { ...@@ -16,9 +18,9 @@ func TestMountOnExisting(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Mkdir failed: %v", err) t.Fatalf("Mkdir failed: %v", err)
} }
nfs := &DefaultNodeFileSystem{} nfs := &fuse.DefaultNodeFileSystem{}
code := ts.connector.Mount(ts.rootNode(), "mnt", nfs, nil) code := ts.connector.Mount(ts.rootNode(), "mnt", nfs, nil)
if code != EBUSY { if code != fuse.EBUSY {
t.Fatal("expect EBUSY:", code) t.Fatal("expect EBUSY:", code)
} }
...@@ -41,13 +43,13 @@ func TestMountRename(t *testing.T) { ...@@ -41,13 +43,13 @@ func TestMountRename(t *testing.T) {
ts := NewTestCase(t) ts := NewTestCase(t)
defer ts.Cleanup() defer ts.Cleanup()
fs := NewPathNodeFs(NewLoopbackFileSystem(ts.orig), nil) fs := fuse.NewPathNodeFs(fuse.NewLoopbackFileSystem(ts.orig), nil)
code := ts.connector.Mount(ts.rootNode(), "mnt", fs, nil) code := ts.connector.Mount(ts.rootNode(), "mnt", fs, nil)
if !code.Ok() { if !code.Ok() {
t.Fatal("mount should succeed") t.Fatal("mount should succeed")
} }
err := os.Rename(ts.mnt+"/mnt", ts.mnt+"/foobar") err := os.Rename(ts.mnt+"/mnt", ts.mnt+"/foobar")
if ToStatus(err) != EBUSY { if fuse.ToStatus(err) != fuse.EBUSY {
t.Fatal("rename mount point should fail with EBUSY:", err) t.Fatal("rename mount point should fail with EBUSY:", err)
} }
ts.pathFs.Unmount("mnt") ts.pathFs.Unmount("mnt")
...@@ -57,7 +59,7 @@ func TestMountReaddir(t *testing.T) { ...@@ -57,7 +59,7 @@ func TestMountReaddir(t *testing.T) {
ts := NewTestCase(t) ts := NewTestCase(t)
defer ts.Cleanup() defer ts.Cleanup()
fs := NewPathNodeFs(NewLoopbackFileSystem(ts.orig), nil) fs := fuse.NewPathNodeFs(fuse.NewLoopbackFileSystem(ts.orig), nil)
code := ts.connector.Mount(ts.rootNode(), "mnt", fs, nil) code := ts.connector.Mount(ts.rootNode(), "mnt", fs, nil)
if !code.Ok() { if !code.Ok() {
t.Fatal("mount should succeed") t.Fatal("mount should succeed")
...@@ -82,7 +84,7 @@ func TestRecursiveMount(t *testing.T) { ...@@ -82,7 +84,7 @@ func TestRecursiveMount(t *testing.T) {
t.Fatalf("WriteFile failed: %v", err) t.Fatalf("WriteFile failed: %v", err)
} }
fs := NewPathNodeFs(NewLoopbackFileSystem(ts.orig), nil) fs := fuse.NewPathNodeFs(fuse.NewLoopbackFileSystem(ts.orig), nil)
code := ts.connector.Mount(ts.rootNode(), "mnt", fs, nil) code := ts.connector.Mount(ts.rootNode(), "mnt", fs, nil)
if !code.Ok() { if !code.Ok() {
t.Fatal("mount should succeed") t.Fatal("mount should succeed")
...@@ -104,7 +106,7 @@ func TestRecursiveMount(t *testing.T) { ...@@ -104,7 +106,7 @@ func TestRecursiveMount(t *testing.T) {
} }
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 != fuse.EBUSY {
t.Error("expect EBUSY") t.Error("expect EBUSY")
} }
...@@ -114,7 +116,7 @@ func TestRecursiveMount(t *testing.T) { ...@@ -114,7 +116,7 @@ func TestRecursiveMount(t *testing.T) {
t.Log("Attempting unmount, should succeed") t.Log("Attempting unmount, should succeed")
code = ts.pathFs.Unmount("mnt") code = ts.pathFs.Unmount("mnt")
if code != OK { if code != fuse.OK {
t.Error("umount failed.", code) t.Error("umount failed.", code)
} }
} }
...@@ -124,7 +126,7 @@ func TestDeletedUnmount(t *testing.T) { ...@@ -124,7 +126,7 @@ func TestDeletedUnmount(t *testing.T) {
defer ts.Cleanup() defer ts.Cleanup()
submnt := filepath.Join(ts.mnt, "mnt") submnt := filepath.Join(ts.mnt, "mnt")
pfs2 := NewPathNodeFs(NewLoopbackFileSystem(ts.orig), nil) pfs2 := fuse.NewPathNodeFs(fuse.NewLoopbackFileSystem(ts.orig), nil)
code := ts.connector.Mount(ts.rootNode(), "mnt", pfs2, nil) code := ts.connector.Mount(ts.rootNode(), "mnt", pfs2, nil)
if !code.Ok() { if !code.Ok() {
t.Fatal("Mount error", code) t.Fatal("Mount error", code)
...@@ -147,7 +149,7 @@ func TestDeletedUnmount(t *testing.T) { ...@@ -147,7 +149,7 @@ func TestDeletedUnmount(t *testing.T) {
} }
code = ts.pathFs.Unmount("mnt") code = ts.pathFs.Unmount("mnt")
if code != EBUSY { if code != fuse.EBUSY {
t.Error("expect EBUSY for unmount with open files", code) t.Error("expect EBUSY for unmount with open files", code)
} }
......
package fuse package test
import ( import (
"io/ioutil" "io/ioutil"
...@@ -6,39 +6,41 @@ import ( ...@@ -6,39 +6,41 @@ import (
"os" "os"
"testing" "testing"
"time" "time"
"github.com/hanwen/go-fuse/fuse"
) )
var _ = log.Println var _ = log.Println
type NotifyFs struct { type NotifyFs struct {
DefaultFileSystem fuse.DefaultFileSystem
size uint64 size uint64
exist bool exist bool
} }
func (fs *NotifyFs) GetAttr(name string, context *Context) (*Attr, Status) { func (fs *NotifyFs) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
if name == "" { if name == "" {
return &Attr{Mode: S_IFDIR | 0755}, OK return &fuse.Attr{Mode: fuse.S_IFDIR | 0755}, fuse.OK
} }
if name == "file" || (name == "dir/file" && fs.exist) { if name == "file" || (name == "dir/file" && fs.exist) {
return &Attr{Mode: S_IFREG | 0644, Size: fs.size}, OK return &fuse.Attr{Mode: fuse.S_IFREG | 0644, Size: fs.size}, fuse.OK
} }
if name == "dir" { if name == "dir" {
return &Attr{Mode: S_IFDIR | 0755}, OK return &fuse.Attr{Mode: fuse.S_IFDIR | 0755}, fuse.OK
} }
return nil, ENOENT return nil, fuse.ENOENT
} }
func (fs *NotifyFs) Open(name string, f uint32, context *Context) (File, Status) { func (fs *NotifyFs) Open(name string, f uint32, context *fuse.Context) (fuse.File, fuse.Status) {
return NewDataFile([]byte{42}), OK return fuse.NewDataFile([]byte{42}), fuse.OK
} }
type NotifyTest struct { type NotifyTest struct {
fs *NotifyFs fs *NotifyFs
pathfs *PathNodeFs pathfs *fuse.PathNodeFs
connector *FileSystemConnector connector *fuse.FileSystemConnector
dir string dir string
state *MountState state *fuse.MountState
} }
func NewNotifyTest(t *testing.T) *NotifyTest { func NewNotifyTest(t *testing.T) *NotifyTest {
...@@ -50,18 +52,18 @@ func NewNotifyTest(t *testing.T) *NotifyTest { ...@@ -50,18 +52,18 @@ func NewNotifyTest(t *testing.T) *NotifyTest {
t.Fatalf("TempDir failed: %v", err) t.Fatalf("TempDir failed: %v", err)
} }
entryTtl := 100 * time.Millisecond entryTtl := 100 * time.Millisecond
opts := &FileSystemOptions{ opts := &fuse.FileSystemOptions{
EntryTimeout: entryTtl, EntryTimeout: entryTtl,
AttrTimeout: entryTtl, AttrTimeout: entryTtl,
NegativeTimeout: entryTtl, NegativeTimeout: entryTtl,
} }
me.pathfs = NewPathNodeFs(me.fs, nil) me.pathfs = fuse.NewPathNodeFs(me.fs, nil)
me.state, me.connector, err = MountNodeFileSystem(me.dir, me.pathfs, opts) me.state, me.connector, err = fuse.MountNodeFileSystem(me.dir, me.pathfs, opts)
if err != nil { if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err) t.Fatalf("MountNodeFileSystem failed: %v", err)
} }
me.state.Debug = VerboseTest() me.state.Debug = fuse.VerboseTest()
go me.state.Loop() go me.state.Loop()
return me return me
......
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