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

Put test name into temp directory.

This makes it evident which tests leak mount points.

Move shared test utilities into internal/testutil/ package.
parent 2b61bf5a
...@@ -18,36 +18,29 @@ import ( ...@@ -18,36 +18,29 @@ import (
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs" "github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
import "flag"
// VerboseTest returns true if the testing framework is run with -v.
func VerboseTest() bool {
flag := flag.Lookup("test.v")
return flag != nil && flag.Value.String() == "true"
}
func setupFs(fs pathfs.FileSystem, N int) (string, func()) { func setupFs(fs pathfs.FileSystem, N int) (string, func()) {
opts := &nodefs.Options{ opts := &nodefs.Options{
EntryTimeout: 0.0, EntryTimeout: 0.0,
AttrTimeout: 0.0, AttrTimeout: 0.0,
NegativeTimeout: 0.0, NegativeTimeout: 0.0,
} }
mountPoint, _ := ioutil.TempDir("", "stat_test") mountPoint := testutil.TempDir()
nfs := pathfs.NewPathNodeFs(fs, nil) nfs := pathfs.NewPathNodeFs(fs, nil)
state, _, err := nodefs.MountRoot(mountPoint, nfs.Root(), opts) state, _, err := nodefs.MountRoot(mountPoint, nfs.Root(), opts)
if err != nil { if err != nil {
panic(fmt.Sprintf("cannot mount %v", err)) // ugh - benchmark has no error methods. panic(fmt.Sprintf("cannot mount %v", err)) // ugh - benchmark has no error methods.
} }
lmap := NewLatencyMap() lmap := NewLatencyMap()
if VerboseTest() { if testutil.VerboseTest() {
state.RecordLatencies(lmap) state.RecordLatencies(lmap)
} }
go state.Serve() go state.Serve()
return mountPoint, func() { return mountPoint, func() {
if VerboseTest() { if testutil.VerboseTest() {
var total time.Duration var total time.Duration
for _, n := range []string{"LOOKUP", "GETATTR", "OPENDIR", "READDIR", for _, n := range []string{"LOOKUP", "GETATTR", "OPENDIR", "READDIR",
"READDIRPLUS", "RELEASEDIR", "FLUSH", "READDIRPLUS", "RELEASEDIR", "FLUSH",
...@@ -203,7 +196,7 @@ func TestingBOnePass(b *testing.B, threads int, filelist, mountPoint string) err ...@@ -203,7 +196,7 @@ func TestingBOnePass(b *testing.B, threads int, filelist, mountPoint string) err
fmt.Sprintf("-cpu=%d", threads), fmt.Sprintf("-cpu=%d", threads),
fmt.Sprintf("-prefix=%s", mountPoint), fmt.Sprintf("-prefix=%s", mountPoint),
fmt.Sprintf("-N=%d", b.N), fmt.Sprintf("-N=%d", b.N),
fmt.Sprintf("-quiet=%v", !VerboseTest()), fmt.Sprintf("-quiet=%v", !testutil.VerboseTest()),
filelist) filelist)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
...@@ -217,7 +210,7 @@ func TestingBOnePass(b *testing.B, threads int, filelist, mountPoint string) err ...@@ -217,7 +210,7 @@ func TestingBOnePass(b *testing.B, threads int, filelist, mountPoint string) err
return err return err
} }
if VerboseTest() { if testutil.VerboseTest() {
fmt.Printf("GC count %d, total GC time: %d ns/file\n", fmt.Printf("GC count %d, total GC time: %d ns/file\n",
after.NumGC-before.NumGC, (after.PauseTotalNs-before.PauseTotalNs)/uint64(b.N)) after.NumGC-before.NumGC, (after.PauseTotalNs-before.PauseTotalNs)/uint64(b.N))
} }
...@@ -263,7 +256,7 @@ func BenchmarkCFuseThreadedStat(b *testing.B) { ...@@ -263,7 +256,7 @@ func BenchmarkCFuseThreadedStat(b *testing.B) {
} }
f.Close() f.Close()
mountPoint, _ := ioutil.TempDir("", "stat_test") mountPoint := testutil.TempDir()
cmd := exec.Command(wd+"/cstatfs", cmd := exec.Command(wd+"/cstatfs",
"-o", "-o",
"entry_timeout=0.0,attr_timeout=0.0,ac_attr_timeout=0.0,negative_timeout=0.0", "entry_timeout=0.0,attr_timeout=0.0,ac_attr_timeout=0.0,negative_timeout=0.0",
......
...@@ -8,18 +8,14 @@ import ( ...@@ -8,18 +8,14 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"testing" "testing"
"github.com/hanwen/go-fuse/internal/testutil"
) )
func TestCopyFile(t *testing.T) { func TestCopyFile(t *testing.T) {
d1, err := ioutil.TempDir("", "go-fuse") d1 := testutil.TempDir()
if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
defer os.RemoveAll(d1) defer os.RemoveAll(d1)
d2, err := ioutil.TempDir("", "go-fuse") d2 := testutil.TempDir()
if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
defer os.RemoveAll(d2) defer os.RemoveAll(d2)
fs1 := NewLoopbackFileSystem(d1) fs1 := NewLoopbackFileSystem(d1)
...@@ -27,7 +23,7 @@ func TestCopyFile(t *testing.T) { ...@@ -27,7 +23,7 @@ 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)
if err != nil { if err != nil {
t.Fatalf("WriteFile failed: %v", err) t.Fatalf("WriteFile failed: %v", err)
} }
......
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
package pathfs package pathfs
import ( import (
"io/ioutil"
"os" "os"
"syscall" "syscall"
"testing" "testing"
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
type ownerFs struct { type ownerFs struct {
...@@ -35,7 +35,7 @@ func (fs *ownerFs) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse ...@@ -35,7 +35,7 @@ func (fs *ownerFs) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse
} }
func setupOwnerTest(t *testing.T, opts *nodefs.Options) (workdir string, cleanup func()) { func setupOwnerTest(t *testing.T, opts *nodefs.Options) (workdir string, cleanup func()) {
wd, err := ioutil.TempDir("", "go-fuse-owner_test") wd := testutil.TempDir()
fs := &ownerFs{NewDefaultFileSystem()} fs := &ownerFs{NewDefaultFileSystem()}
nfs := NewPathNodeFs(fs, nil) nfs := NewPathNodeFs(fs, nil)
......
...@@ -8,13 +8,13 @@ package pathfs ...@@ -8,13 +8,13 @@ package pathfs
import ( import (
"bytes" "bytes"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
var xattrGolden = map[string][]byte{ var xattrGolden = map[string][]byte{
...@@ -106,16 +106,13 @@ func readXAttr(p, a string) (val []byte, err error) { ...@@ -106,16 +106,13 @@ func readXAttr(p, a string) (val []byte, err error) {
func xattrTestCase(t *testing.T, nm string, m map[string][]byte) (mountPoint string, cleanup func()) { func xattrTestCase(t *testing.T, nm string, m map[string][]byte) (mountPoint string, cleanup func()) {
xfs := NewXAttrFs(nm, m) xfs := NewXAttrFs(nm, m)
mountPoint, err := ioutil.TempDir("", "go-fuse-xattr_test") mountPoint = testutil.TempDir()
if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
nfs := NewPathNodeFs(xfs, nil) nfs := NewPathNodeFs(xfs, nil)
state, _, err := nodefs.MountRoot(mountPoint, nfs.Root(), state, _, err := nodefs.MountRoot(mountPoint, nfs.Root(),
&nodefs.Options{Debug: VerboseTest()}) &nodefs.Options{Debug: VerboseTest()})
if err != nil { if err != nil {
t.Fatalf("TempDir failed: %v", err) t.Fatalf("MountRoot failed: %v", err)
} }
go state.Serve() go state.Serve()
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs" "github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
type cacheFs struct { type cacheFs struct {
...@@ -34,20 +35,17 @@ func (fs *cacheFs) Open(name string, flags uint32, context *fuse.Context) (fuseF ...@@ -34,20 +35,17 @@ func (fs *cacheFs) Open(name string, flags uint32, context *fuse.Context) (fuseF
} }
func setupCacheTest(t *testing.T) (string, *pathfs.PathNodeFs, func()) { func setupCacheTest(t *testing.T) (string, *pathfs.PathNodeFs, func()) {
dir, err := ioutil.TempDir("", "go-fuse-cachetest") dir := testutil.TempDir()
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)
fs := &cacheFs{ fs := &cacheFs{
pathfs.NewLoopbackFileSystem(dir + "/orig"), pathfs.NewLoopbackFileSystem(dir + "/orig"),
} }
pfs := pathfs.NewPathNodeFs(fs, &pathfs.PathNodeFsOptions{Debug: VerboseTest()}) pfs := pathfs.NewPathNodeFs(fs, &pathfs.PathNodeFsOptions{Debug: testutil.VerboseTest()})
opts := nodefs.NewOptions() opts := nodefs.NewOptions()
opts.Debug = VerboseTest() opts.Debug = testutil.VerboseTest()
state, _, err := nodefs.MountRoot(dir+"/mnt", pfs.Root(), opts) state, _, err := nodefs.MountRoot(dir+"/mnt", pfs.Root(), opts)
if err != nil { if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err) t.Fatalf("MountNodeFileSystem failed: %v", err)
...@@ -142,14 +140,11 @@ func TestNonseekable(t *testing.T) { ...@@ -142,14 +140,11 @@ func TestNonseekable(t *testing.T) {
fs := &nonseekFs{FileSystem: pathfs.NewDefaultFileSystem()} fs := &nonseekFs{FileSystem: pathfs.NewDefaultFileSystem()}
fs.Length = 200 * 1024 fs.Length = 200 * 1024
dir, err := ioutil.TempDir("", "go-fuse-cache_test") dir := testutil.TempDir()
if err != nil {
t.Fatalf("failed: %v", err)
}
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
nfs := pathfs.NewPathNodeFs(fs, nil) nfs := pathfs.NewPathNodeFs(fs, nil)
opts := nodefs.NewOptions() opts := nodefs.NewOptions()
opts.Debug = VerboseTest() opts.Debug = testutil.VerboseTest()
state, _, err := nodefs.MountRoot(dir, nfs.Root(), opts) state, _, err := nodefs.MountRoot(dir, nfs.Root(), opts)
if err != nil { if err != nil {
t.Fatalf("failed: %v", err) t.Fatalf("failed: %v", err)
...@@ -175,18 +170,15 @@ func TestNonseekable(t *testing.T) { ...@@ -175,18 +170,15 @@ func TestNonseekable(t *testing.T) {
} }
func TestGetAttrRace(t *testing.T) { func TestGetAttrRace(t *testing.T) {
dir, err := ioutil.TempDir("", "go-fuse-cache_test") dir := testutil.TempDir()
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)
fs := pathfs.NewLoopbackFileSystem(dir + "/orig") fs := pathfs.NewLoopbackFileSystem(dir + "/orig")
pfs := pathfs.NewPathNodeFs(fs, &pathfs.PathNodeFsOptions{Debug: VerboseTest()}) pfs := pathfs.NewPathNodeFs(fs, &pathfs.PathNodeFsOptions{Debug: testutil.VerboseTest()})
state, _, err := nodefs.MountRoot(dir+"/mnt", pfs.Root(), state, _, err := nodefs.MountRoot(dir+"/mnt", pfs.Root(),
&nodefs.Options{Debug: VerboseTest()}) &nodefs.Options{Debug: testutil.VerboseTest()})
if err != nil { if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err) t.Fatalf("MountNodeFileSystem failed: %v", err)
} }
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs" "github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
type DefaultReadFS struct { type DefaultReadFS struct {
...@@ -41,13 +42,10 @@ func defaultReadTest(t *testing.T) (root string, cleanup func()) { ...@@ -41,13 +42,10 @@ func defaultReadTest(t *testing.T) (root string, cleanup func()) {
} }
var err error var err error
dir, err := ioutil.TempDir("", "go-fuse") dir := testutil.TempDir()
if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
pathfs := pathfs.NewPathNodeFs(fs, nil) pathfs := pathfs.NewPathNodeFs(fs, nil)
opts := nodefs.NewOptions() opts := nodefs.NewOptions()
opts.Debug = VerboseTest() opts.Debug = testutil.VerboseTest()
state, _, err := nodefs.MountRoot(dir, pathfs.Root(), opts) state, _, err := nodefs.MountRoot(dir, pathfs.Root(), opts)
if err != nil { if err != nil {
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
type flipNode struct { type flipNode struct {
...@@ -33,22 +34,19 @@ func (f *flipNode) GetAttr(out *fuse.Attr, file nodefs.File, c *fuse.Context) fu ...@@ -33,22 +34,19 @@ func (f *flipNode) GetAttr(out *fuse.Attr, file nodefs.File, c *fuse.Context) fu
} }
func TestDeleteNotify(t *testing.T) { func TestDeleteNotify(t *testing.T) {
dir, err := ioutil.TempDir("", "go-fuse-delete_test") dir := testutil.TempDir()
if err != nil {
t.Fatalf("TempDir failed %v", err)
}
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
root := nodefs.NewMemNodeFSRoot(dir + "/backing") root := nodefs.NewMemNodeFSRoot(dir + "/backing")
conn := nodefs.NewFileSystemConnector(root, conn := nodefs.NewFileSystemConnector(root,
&nodefs.Options{PortableInodes: true}) &nodefs.Options{PortableInodes: true})
mnt := dir + "/mnt" mnt := dir + "/mnt"
err = os.Mkdir(mnt, 0755) err := os.Mkdir(mnt, 0755)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
state, err := fuse.NewServer(conn.RawFS(), mnt, &fuse.MountOptions{ state, err := fuse.NewServer(conn.RawFS(), mnt, &fuse.MountOptions{
Debug: VerboseTest(), Debug: testutil.VerboseTest(),
}) })
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package test package test
import ( import (
"io/ioutil"
"os" "os"
"syscall" "syscall"
"testing" "testing"
...@@ -14,6 +13,7 @@ import ( ...@@ -14,6 +13,7 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs" "github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
type MutableDataFile struct { type MutableDataFile struct {
...@@ -143,13 +143,10 @@ func NewFile() *MutableDataFile { ...@@ -143,13 +143,10 @@ func NewFile() *MutableDataFile {
} }
func setupFAttrTest(t *testing.T, fs pathfs.FileSystem) (dir string, clean func()) { func setupFAttrTest(t *testing.T, fs pathfs.FileSystem) (dir string, clean func()) {
dir, err := ioutil.TempDir("", "go-fuse-fsetattr_test") dir = testutil.TempDir()
if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
nfs := pathfs.NewPathNodeFs(fs, nil) nfs := pathfs.NewPathNodeFs(fs, nil)
opts := nodefs.NewOptions() opts := nodefs.NewOptions()
opts.Debug = VerboseTest() opts.Debug = testutil.VerboseTest()
state, _, err := nodefs.MountRoot(dir, nfs.Root(), opts) state, _, err := nodefs.MountRoot(dir, nfs.Root(), opts)
if err != nil { if err != nil {
...@@ -161,17 +158,20 @@ func setupFAttrTest(t *testing.T, fs pathfs.FileSystem) (dir string, clean func( ...@@ -161,17 +158,20 @@ func setupFAttrTest(t *testing.T, fs pathfs.FileSystem) (dir string, clean func(
t.Fatal("WaitMount", err) t.Fatal("WaitMount", err)
} }
if state.KernelSettings().Flags&fuse.CAP_FILE_OPS == 0 { clean = func() {
t.Skip("Mount does not support file operations")
}
return dir, func() {
if err := state.Unmount(); err != nil { if err := state.Unmount(); err != nil {
t.Errorf("cleanup: Unmount: %v", err) t.Errorf("cleanup: Unmount: %v", err)
} else { } else {
os.RemoveAll(dir) os.RemoveAll(dir)
} }
} }
if state.KernelSettings().Flags&fuse.CAP_FILE_OPS == 0 {
clean()
t.Skip("Mount does not support file operations")
}
return dir, clean
} }
func TestFSetAttr(t *testing.T) { func TestFSetAttr(t *testing.T) {
......
...@@ -22,6 +22,7 @@ import ( ...@@ -22,6 +22,7 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs" "github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
const mode uint32 = 0757 const mode uint32 = 0757
...@@ -74,10 +75,7 @@ func NewTestCase(t *testing.T) *testCase { ...@@ -74,10 +75,7 @@ func NewTestCase(t *testing.T) *testCase {
const subdir string = "subdir" const subdir string = "subdir"
var err error var err error
tc.tmpDir, err = ioutil.TempDir("", "go-fuse") tc.tmpDir = testutil.TempDir()
if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
tc.orig = tc.tmpDir + "/orig" tc.orig = tc.tmpDir + "/orig"
tc.mnt = tc.tmpDir + "/mnt" tc.mnt = tc.tmpDir + "/mnt"
...@@ -100,12 +98,12 @@ func NewTestCase(t *testing.T) *testCase { ...@@ -100,12 +98,12 @@ func NewTestCase(t *testing.T) *testCase {
EntryTimeout: testTtl, EntryTimeout: testTtl,
AttrTimeout: testTtl, AttrTimeout: testTtl,
NegativeTimeout: 0.0, NegativeTimeout: 0.0,
Debug: VerboseTest(), Debug: testutil.VerboseTest(),
}) })
tc.state, err = fuse.NewServer( tc.state, err = fuse.NewServer(
fuse.NewRawFileSystem(tc.connector.RawFS()), tc.mnt, &fuse.MountOptions{ fuse.NewRawFileSystem(tc.connector.RawFS()), tc.mnt, &fuse.MountOptions{
SingleThreaded: true, SingleThreaded: true,
Debug: VerboseTest(), Debug: testutil.VerboseTest(),
}) })
if err != nil { if err != nil {
t.Fatal("NewServer:", err) t.Fatal("NewServer:", err)
...@@ -865,13 +863,10 @@ func TestFStatFs(t *testing.T) { ...@@ -865,13 +863,10 @@ func TestFStatFs(t *testing.T) {
} }
func TestOriginalIsSymlink(t *testing.T) { func TestOriginalIsSymlink(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "go-fuse-loopback_test") tmpDir := testutil.TempDir()
if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
orig := tmpDir + "/orig" orig := tmpDir + "/orig"
err = os.Mkdir(orig, 0755) err := os.Mkdir(orig, 0755)
if err != nil { if err != nil {
t.Fatalf("Mkdir failed: %v", err) t.Fatalf("Mkdir failed: %v", err)
} }
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs" "github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
func TestMountOnExisting(t *testing.T) { func TestMountOnExisting(t *testing.T) {
...@@ -170,10 +171,7 @@ func TestDeletedUnmount(t *testing.T) { ...@@ -170,10 +171,7 @@ func TestDeletedUnmount(t *testing.T) {
} }
func TestDefaultNodeMount(t *testing.T) { func TestDefaultNodeMount(t *testing.T) {
dir, err := ioutil.TempDir("", "go-fuse") dir := testutil.TempDir()
if err != nil {
t.Fatalf("TempDir: %v", err)
}
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
root := nodefs.NewDefaultNode() root := nodefs.NewDefaultNode()
s, conn, err := nodefs.MountRoot(dir, root, nil) s, conn, err := nodefs.MountRoot(dir, root, nil)
...@@ -200,10 +198,7 @@ func TestDefaultNodeMount(t *testing.T) { ...@@ -200,10 +198,7 @@ func TestDefaultNodeMount(t *testing.T) {
} }
func TestLiveness(t *testing.T) { func TestLiveness(t *testing.T) {
dir, err := ioutil.TempDir("", "go-fuse") dir := testutil.TempDir()
if err != nil {
t.Fatalf("TempDir: %v", err)
}
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
root := nodefs.NewDefaultNode() root := nodefs.NewDefaultNode()
s, _, err := nodefs.MountRoot(dir, root, nil) s, _, err := nodefs.MountRoot(dir, root, nil)
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package test package test
import ( import (
"io/ioutil"
"os" "os"
"testing" "testing"
"time" "time"
...@@ -13,6 +12,7 @@ import ( ...@@ -13,6 +12,7 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs" "github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
type NotifyFs struct { type NotifyFs struct {
...@@ -78,20 +78,17 @@ type NotifyTest struct { ...@@ -78,20 +78,17 @@ type NotifyTest struct {
func NewNotifyTest(t *testing.T) *NotifyTest { func NewNotifyTest(t *testing.T) *NotifyTest {
me := &NotifyTest{} me := &NotifyTest{}
me.fs = newNotifyFs() me.fs = newNotifyFs()
var err error me.dir = testutil.TempDir()
me.dir, err = ioutil.TempDir("", "go-fuse-notify_test")
if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
entryTtl := 100 * time.Millisecond entryTtl := 100 * time.Millisecond
opts := &nodefs.Options{ opts := &nodefs.Options{
EntryTimeout: entryTtl, EntryTimeout: entryTtl,
AttrTimeout: entryTtl, AttrTimeout: entryTtl,
NegativeTimeout: entryTtl, NegativeTimeout: entryTtl,
Debug: VerboseTest(), Debug: testutil.VerboseTest(),
} }
me.pathfs = pathfs.NewPathNodeFs(me.fs, nil) me.pathfs = pathfs.NewPathNodeFs(me.fs, nil)
var err error
me.state, me.connector, err = nodefs.MountRoot(me.dir, me.pathfs.Root(), opts) me.state, me.connector, err = nodefs.MountRoot(me.dir, me.pathfs.Root(), opts)
if err != nil { if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err) t.Fatalf("MountNodeFileSystem failed: %v", err)
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
package test package test
import ( import (
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"syscall" "syscall"
...@@ -15,6 +14,7 @@ import ( ...@@ -15,6 +14,7 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
// this file is linux-only, since it uses syscall.Getxattr. // this file is linux-only, since it uses syscall.Getxattr.
...@@ -36,10 +36,7 @@ func (n *xattrChildNode) GetXAttr(attr string, context *fuse.Context) ([]byte, f ...@@ -36,10 +36,7 @@ func (n *xattrChildNode) GetXAttr(attr string, context *fuse.Context) ([]byte, f
} }
func TestDefaultXAttr(t *testing.T) { func TestDefaultXAttr(t *testing.T) {
dir, err := ioutil.TempDir("", "go-fuse") dir := testutil.TempDir()
if err != nil {
t.Fatalf("TempDir: %v", err)
}
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
root := &xattrNode{ root := &xattrNode{
...@@ -47,7 +44,7 @@ func TestDefaultXAttr(t *testing.T) { ...@@ -47,7 +44,7 @@ func TestDefaultXAttr(t *testing.T) {
} }
opts := nodefs.NewOptions() opts := nodefs.NewOptions()
opts.Debug = VerboseTest() opts.Debug = testutil.VerboseTest()
s, _, err := nodefs.MountRoot(dir, root, opts) s, _, err := nodefs.MountRoot(dir, root, opts)
if err != nil { if err != nil {
t.Fatalf("MountRoot: %v", err) t.Fatalf("MountRoot: %v", err)
......
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package testutil
import (
"io/ioutil"
"log"
"runtime"
"strings"
)
// TempDir creates a temporary directory that includes the name of the
// testcase. Panics if there was an I/O problem creating the directory.
func TempDir() string {
frames := make([]uintptr, 10) // at least 1 entry needed
n := runtime.Callers(1, frames)
lastName := ""
for _, pc := range frames[:n] {
f := runtime.FuncForPC(pc)
name := f.Name()
i := strings.LastIndex(name, ".")
if i >= 0 {
name = name[i+1:]
}
if strings.HasPrefix(name, "Test") {
lastName = name
}
}
dir, err := ioutil.TempDir("", lastName)
if err != nil {
log.Panicf("TempDir(%s): %v", lastName, err)
}
return dir
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package test package testutil
import "flag" import "flag"
......
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs" "github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
const entryTtl = 100 * time.Millisecond const entryTtl = 100 * time.Millisecond
...@@ -30,7 +31,7 @@ var testAOpts = AutoUnionFsOptions{ ...@@ -30,7 +31,7 @@ var testAOpts = AutoUnionFsOptions{
} }
func init() { func init() {
testAOpts.Options.Debug = VerboseTest() testAOpts.Options.Debug = testutil.VerboseTest()
} }
func WriteFile(t *testing.T, name string, contents string) { func WriteFile(t *testing.T, name string, contents string) {
...@@ -41,7 +42,7 @@ func WriteFile(t *testing.T, name string, contents string) { ...@@ -41,7 +42,7 @@ func WriteFile(t *testing.T, name string, contents string) {
} }
func setup(t *testing.T) (workdir string, server *fuse.Server, cleanup func()) { func setup(t *testing.T) (workdir string, server *fuse.Server, cleanup func()) {
wd, _ := ioutil.TempDir("", "") wd := testutil.TempDir()
err := os.Mkdir(wd+"/mnt", 0700) err := os.Mkdir(wd+"/mnt", 0700)
if err != nil { if err != nil {
t.Fatalf("Mkdir failed: %v", err) t.Fatalf("Mkdir failed: %v", err)
......
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
package unionfs package unionfs
import ( import (
"io/ioutil"
"os" "os"
"syscall" "syscall"
"testing" "testing"
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/pathfs" "github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
func modeMapEq(m1, m2 map[string]uint32) bool { func modeMapEq(m1, m2 map[string]uint32) bool {
...@@ -29,7 +29,7 @@ func modeMapEq(m1, m2 map[string]uint32) bool { ...@@ -29,7 +29,7 @@ func modeMapEq(m1, m2 map[string]uint32) bool {
} }
func TestCachingFs(t *testing.T) { func TestCachingFs(t *testing.T) {
wd, _ := ioutil.TempDir("", "") wd := testutil.TempDir()
defer os.RemoveAll(wd) defer os.RemoveAll(wd)
fs := pathfs.NewLoopbackFileSystem(wd) fs := pathfs.NewLoopbackFileSystem(wd)
......
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs" "github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
func TestFilePathHash(t *testing.T) { func TestFilePathHash(t *testing.T) {
...@@ -63,7 +64,7 @@ func setupUfs(t *testing.T) (wd string, cleanup func()) { ...@@ -63,7 +64,7 @@ func setupUfs(t *testing.T) (wd string, cleanup func()) {
// Make sure system setting does not affect test. // Make sure system setting does not affect test.
syscall.Umask(0) syscall.Umask(0)
wd, _ = ioutil.TempDir("", "unionfs") wd = testutil.TempDir()
err := os.Mkdir(wd+"/mnt", 0700) err := os.Mkdir(wd+"/mnt", 0700)
if err != nil { if err != nil {
t.Fatalf("Mkdir failed: %v", err) t.Fatalf("Mkdir failed: %v", err)
...@@ -94,7 +95,7 @@ func setupUfs(t *testing.T) (wd string, cleanup func()) { ...@@ -94,7 +95,7 @@ func setupUfs(t *testing.T) (wd string, cleanup func()) {
AttrTimeout: entryTtl / 2, AttrTimeout: entryTtl / 2,
NegativeTimeout: entryTtl / 2, NegativeTimeout: entryTtl / 2,
PortableInodes: true, PortableInodes: true,
Debug: VerboseTest(), Debug: testutil.VerboseTest(),
} }
pathfs := pathfs.NewPathNodeFs(ufs, pathfs := pathfs.NewPathNodeFs(ufs,
...@@ -1129,7 +1130,7 @@ func newDisappearingFS(fs, nop pathfs.FileSystem) *disappearingFS { ...@@ -1129,7 +1130,7 @@ func newDisappearingFS(fs, nop pathfs.FileSystem) *disappearingFS {
func TestUnionFsDisappearing(t *testing.T) { func TestUnionFsDisappearing(t *testing.T) {
// This init is like setupUfs, but we want access to the // This init is like setupUfs, but we want access to the
// writable Fs. // writable Fs.
wd, _ := ioutil.TempDir("", "") wd := testutil.TempDir()
defer os.RemoveAll(wd) defer os.RemoveAll(wd)
err := os.Mkdir(wd+"/mnt", 0700) err := os.Mkdir(wd+"/mnt", 0700)
if err != nil { if err != nil {
...@@ -1160,7 +1161,7 @@ func TestUnionFsDisappearing(t *testing.T) { ...@@ -1160,7 +1161,7 @@ func TestUnionFsDisappearing(t *testing.T) {
EntryTimeout: entryTtl, EntryTimeout: entryTtl,
AttrTimeout: entryTtl, AttrTimeout: entryTtl,
NegativeTimeout: entryTtl, NegativeTimeout: entryTtl,
Debug: VerboseTest(), Debug: testutil.VerboseTest(),
} }
nfs := pathfs.NewPathNodeFs(ufs, nil) nfs := pathfs.NewPathNodeFs(ufs, nil)
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package unionfs package unionfs
import ( import (
"io/ioutil"
"os" "os"
"testing" "testing"
"time" "time"
...@@ -13,6 +12,7 @@ import ( ...@@ -13,6 +12,7 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs" "github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
type TestFS struct { type TestFS struct {
...@@ -39,7 +39,7 @@ func (fs *TestFS) GetXAttr(path string, name string, context *fuse.Context) ([]b ...@@ -39,7 +39,7 @@ func (fs *TestFS) GetXAttr(path string, name string, context *fuse.Context) ([]b
} }
func TestXAttrCaching(t *testing.T) { func TestXAttrCaching(t *testing.T) {
wd, _ := ioutil.TempDir("", "unionfs") wd := testutil.TempDir()
defer os.RemoveAll(wd) defer os.RemoveAll(wd)
os.Mkdir(wd+"/mnt", 0700) os.Mkdir(wd+"/mnt", 0700)
err := os.Mkdir(wd+"/rw", 0700) err := os.Mkdir(wd+"/rw", 0700)
...@@ -62,12 +62,12 @@ func TestXAttrCaching(t *testing.T) { ...@@ -62,12 +62,12 @@ func TestXAttrCaching(t *testing.T) {
EntryTimeout: entryTtl / 2, EntryTimeout: entryTtl / 2,
AttrTimeout: entryTtl / 2, AttrTimeout: entryTtl / 2,
NegativeTimeout: entryTtl / 2, NegativeTimeout: entryTtl / 2,
Debug: VerboseTest(), Debug: testutil.VerboseTest(),
} }
pathfs := pathfs.NewPathNodeFs(ufs, pathfs := pathfs.NewPathNodeFs(ufs,
&pathfs.PathNodeFsOptions{ClientInodes: true, &pathfs.PathNodeFsOptions{ClientInodes: true,
Debug: VerboseTest()}) Debug: testutil.VerboseTest()})
server, _, err := nodefs.MountRoot(wd+"/mnt", pathfs.Root(), opts) server, _, err := nodefs.MountRoot(wd+"/mnt", pathfs.Root(), opts)
if err != nil { if err != nil {
......
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package unionfs
import "flag"
// VerboseTest returns true if the testing framework is run with -v.
func VerboseTest() bool {
flag := flag.Lookup("test.v")
return flag != nil && flag.Value.String() == "true"
}
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package zipfs package zipfs
import ( import (
"flag"
"io/ioutil" "io/ioutil"
"os" "os"
"testing" "testing"
...@@ -14,25 +13,20 @@ import ( ...@@ -14,25 +13,20 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs" "github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
// VerboseTest returns true if the testing framework is run with -v.
func VerboseTest() bool {
flag := flag.Lookup("test.v")
return flag != nil && flag.Value.String() == "true"
}
const testTtl = 100 * time.Millisecond const testTtl = 100 * time.Millisecond
func setupMzfs(t *testing.T) (mountPoint string, state *fuse.Server, cleanup func()) { func setupMzfs(t *testing.T) (mountPoint string, state *fuse.Server, cleanup func()) {
fs := NewMultiZipFs() fs := NewMultiZipFs()
mountPoint, _ = ioutil.TempDir("", "") mountPoint = testutil.TempDir()
nfs := pathfs.NewPathNodeFs(fs, nil) nfs := pathfs.NewPathNodeFs(fs, nil)
state, _, err := nodefs.MountRoot(mountPoint, nfs.Root(), &nodefs.Options{ state, _, err := nodefs.MountRoot(mountPoint, nfs.Root(), &nodefs.Options{
EntryTimeout: testTtl, EntryTimeout: testTtl,
AttrTimeout: testTtl, AttrTimeout: testTtl,
NegativeTimeout: 0.0, NegativeTimeout: 0.0,
Debug: VerboseTest(), Debug: testutil.VerboseTest(),
}) })
if err != nil { if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err) t.Fatalf("MountNodeFileSystem failed: %v", err)
......
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/internal/testutil"
) )
func testZipFile() string { func testZipFile() string {
...@@ -30,9 +31,9 @@ func setupZipfs(t *testing.T) (mountPoint string, cleanup func()) { ...@@ -30,9 +31,9 @@ func setupZipfs(t *testing.T) (mountPoint string, cleanup func()) {
t.Fatalf("NewArchiveFileSystem failed: %v", err) t.Fatalf("NewArchiveFileSystem failed: %v", err)
} }
mountPoint, _ = ioutil.TempDir("", "") mountPoint = testutil.TempDir()
state, _, err := nodefs.MountRoot(mountPoint, root, &nodefs.Options{ state, _, err := nodefs.MountRoot(mountPoint, root, &nodefs.Options{
Debug: VerboseTest(), Debug: testutil.VerboseTest(),
}) })
go state.Serve() go state.Serve()
......
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