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