Commit 8363cf88 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

internal/testutil: drop TempDir

Change-Id: I9357f137487d1c958a95ed46db081b7775604b6b
parent bd47fe9b
...@@ -25,7 +25,10 @@ import ( ...@@ -25,7 +25,10 @@ import (
func setupFs(node fs.InodeEmbedder, N int) (string, func()) { func setupFs(node fs.InodeEmbedder, N int) (string, func()) {
opts := &fs.Options{} opts := &fs.Options{}
opts.Debug = testutil.VerboseTest() opts.Debug = testutil.VerboseTest()
mountPoint := testutil.TempDir() mountPoint, err := os.MkdirTemp("", "")
if err != nil {
log.Panicf("TempDir: %v", err)
}
server, err := fs.Mount(mountPoint, node, opts) server, err := fs.Mount(mountPoint, node, opts)
if err != nil { if err != nil {
log.Panicf("cannot mount %v", err) log.Panicf("cannot mount %v", err)
...@@ -53,8 +56,6 @@ func setupFs(node fs.InodeEmbedder, N int) (string, func()) { ...@@ -53,8 +56,6 @@ func setupFs(node fs.InodeEmbedder, N int) (string, func()) {
err := server.Unmount() err := server.Unmount()
if err != nil { if err != nil {
log.Println("error during unmount", err) log.Println("error during unmount", err)
} else {
os.RemoveAll(mountPoint)
} }
} }
} }
...@@ -251,8 +252,10 @@ func BenchmarkCFuseThreadedStat(b *testing.B) { ...@@ -251,8 +252,10 @@ func BenchmarkCFuseThreadedStat(b *testing.B) {
} }
f.Close() f.Close()
mountPoint := testutil.TempDir() mountPoint, err := os.MkdirTemp("", "")
defer os.RemoveAll(mountPoint) if err != nil {
b.Fatalf("MkdirTemp: %v", err)
}
cmd := exec.Command(wd+"/cstatfs", cmd := exec.Command(wd+"/cstatfs",
"-o", "-o",
......
...@@ -301,7 +301,7 @@ func waitMount(mnt string) error { ...@@ -301,7 +301,7 @@ func waitMount(mnt string) error {
func TestParallelDiropsHang(t *testing.T) { func TestParallelDiropsHang(t *testing.T) {
// We do NOT want to use newTestCase() here because we need to know the // We do NOT want to use newTestCase() here because we need to know the
// mnt path before the filesystem is mounted // mnt path before the filesystem is mounted
dir := testutil.TempDir() dir := t.TempDir()
orig := dir + "/orig" orig := dir + "/orig"
mnt := dir + "/mnt" mnt := dir + "/mnt"
if err := os.Mkdir(orig, 0755); err != nil { if err := os.Mkdir(orig, 0755); err != nil {
...@@ -310,7 +310,6 @@ func TestParallelDiropsHang(t *testing.T) { ...@@ -310,7 +310,6 @@ func TestParallelDiropsHang(t *testing.T) {
if err := os.Mkdir(mnt, 0755); err != nil { if err := os.Mkdir(mnt, 0755); err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer os.RemoveAll(dir)
// Unblock the goroutines onces the mount shows up in /proc/self/mounts // Unblock the goroutines onces the mount shows up in /proc/self/mounts
wait := make(chan struct{}) wait := make(chan struct{})
......
...@@ -24,7 +24,7 @@ import ( ...@@ -24,7 +24,7 @@ import (
func testMount(t *testing.T, root InodeEmbedder, opts *Options) (string, *fuse.Server) { func testMount(t *testing.T, root InodeEmbedder, opts *Options) (string, *fuse.Server) {
t.Helper() t.Helper()
mntDir := testutil.TempDir() mntDir := t.TempDir()
if opts == nil { if opts == nil {
opts = &Options{ opts = &Options{
FirstAutomaticIno: 1, FirstAutomaticIno: 1,
...@@ -40,9 +40,6 @@ func testMount(t *testing.T, root InodeEmbedder, opts *Options) (string, *fuse.S ...@@ -40,9 +40,6 @@ func testMount(t *testing.T, root InodeEmbedder, opts *Options) (string, *fuse.S
if err := server.Unmount(); err != nil { if err := server.Unmount(); err != nil {
t.Fatalf("testMount: Unmount failed: %v", err) t.Fatalf("testMount: Unmount failed: %v", err)
} }
if err := syscall.Rmdir(mntDir); err != nil {
t.Errorf("testMount: Remove failed: %v", err)
}
}) })
return mntDir, server return mntDir, server
} }
......
...@@ -50,9 +50,6 @@ func (tc *testCase) clean() { ...@@ -50,9 +50,6 @@ func (tc *testCase) clean() {
if err := tc.server.Unmount(); err != nil { if err := tc.server.Unmount(); err != nil {
tc.Fatal(err) tc.Fatal(err)
} }
if err := os.RemoveAll(tc.dir); err != nil {
tc.Fatal(err)
}
} }
type testOptions struct { type testOptions struct {
...@@ -73,7 +70,7 @@ func newTestCase(t *testing.T, opts *testOptions) *testCase { ...@@ -73,7 +70,7 @@ func newTestCase(t *testing.T, opts *testOptions) *testCase {
opts = &testOptions{} opts = &testOptions{}
} }
if opts.testDir == "" { if opts.testDir == "" {
opts.testDir = testutil.TempDir() opts.testDir = t.TempDir()
} }
tc := &testCase{ tc := &testCase{
dir: opts.testDir, dir: opts.testDir,
...@@ -356,8 +353,7 @@ func TestMknod(t *testing.T) { ...@@ -356,8 +353,7 @@ func TestMknod(t *testing.T) {
} }
func TestMknodNotSupported(t *testing.T) { func TestMknodNotSupported(t *testing.T) {
mountPoint := testutil.TempDir() mountPoint := t.TempDir()
defer os.Remove(mountPoint)
server, err := Mount(mountPoint, &Inode{}, nil) server, err := Mount(mountPoint, &Inode{}, nil)
if err != nil { if err != nil {
......
...@@ -6,17 +6,12 @@ package pathfs ...@@ -6,17 +6,12 @@ package pathfs
import ( import (
"io/ioutil" "io/ioutil"
"os"
"testing" "testing"
"github.com/hanwen/go-fuse/v2/internal/testutil"
) )
func TestCopyFile(t *testing.T) { func TestCopyFile(t *testing.T) {
d1 := testutil.TempDir() d1 := t.TempDir()
defer os.RemoveAll(d1) d2 := t.TempDir()
d2 := testutil.TempDir()
defer os.RemoveAll(d2)
fs1 := NewLoopbackFileSystem(d1) fs1 := NewLoopbackFileSystem(d1)
fs2 := NewLoopbackFileSystem(d2) fs2 := NewLoopbackFileSystem(d2)
......
...@@ -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 := testutil.TempDir() wd := t.TempDir()
opts.Debug = testutil.VerboseTest() opts.Debug = testutil.VerboseTest()
fs := &ownerFs{NewDefaultFileSystem()} fs := &ownerFs{NewDefaultFileSystem()}
...@@ -50,7 +50,6 @@ func setupOwnerTest(t *testing.T, opts *nodefs.Options) (workdir string, cleanup ...@@ -50,7 +50,6 @@ func setupOwnerTest(t *testing.T, opts *nodefs.Options) (workdir string, cleanup
} }
return wd, func() { return wd, func() {
state.Unmount() state.Unmount()
os.RemoveAll(wd)
} }
} }
......
...@@ -16,7 +16,6 @@ import ( ...@@ -16,7 +16,6 @@ import (
"github.com/hanwen/go-fuse/v2/fuse" "github.com/hanwen/go-fuse/v2/fuse"
"github.com/hanwen/go-fuse/v2/fuse/nodefs" "github.com/hanwen/go-fuse/v2/fuse/nodefs"
"github.com/hanwen/go-fuse/v2/internal/testutil"
) )
var xattrGolden = map[string][]byte{ var xattrGolden = map[string][]byte{
...@@ -103,7 +102,7 @@ func (fs *XAttrTestFs) RemoveXAttr(name string, attr string, context *fuse.Conte ...@@ -103,7 +102,7 @@ func (fs *XAttrTestFs) RemoveXAttr(name string, attr string, context *fuse.Conte
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 = testutil.TempDir() mountPoint = t.TempDir()
nfs := NewPathNodeFs(xfs, nil) nfs := NewPathNodeFs(xfs, nil)
state, _, err := nodefs.MountRoot(mountPoint, nfs.Root(), state, _, err := nodefs.MountRoot(mountPoint, nfs.Root(),
...@@ -115,7 +114,6 @@ func xattrTestCase(t *testing.T, nm string, m map[string][]byte) (mountPoint str ...@@ -115,7 +114,6 @@ func xattrTestCase(t *testing.T, nm string, m map[string][]byte) (mountPoint str
go state.Serve() go state.Serve()
return mountPoint, func() { return mountPoint, func() {
state.Unmount() state.Unmount()
os.RemoveAll(mountPoint)
} }
} }
......
...@@ -37,7 +37,7 @@ func (fs *cacheFs) Open(name string, flags uint32, context *fuse.Context) (fuseF ...@@ -37,7 +37,7 @@ 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 := testutil.TempDir() dir := t.TempDir()
os.Mkdir(dir+"/mnt", 0755) os.Mkdir(dir+"/mnt", 0755)
os.Mkdir(dir+"/orig", 0755) os.Mkdir(dir+"/orig", 0755)
...@@ -65,10 +65,7 @@ func setupCacheTest(t *testing.T) (string, *pathfs.PathNodeFs, func()) { ...@@ -65,10 +65,7 @@ func setupCacheTest(t *testing.T) (string, *pathfs.PathNodeFs, func()) {
t.Fatal("WaitMount", err) t.Fatal("WaitMount", err)
} }
return dir, pfs, func() { return dir, pfs, func() {
err := state.Unmount() state.Unmount()
if err == nil {
os.RemoveAll(dir)
}
} }
} }
...@@ -186,8 +183,7 @@ func TestNonseekable(t *testing.T) { ...@@ -186,8 +183,7 @@ func TestNonseekable(t *testing.T) {
fs := &nonseekFs{FileSystem: pathfs.NewDefaultFileSystem()} fs := &nonseekFs{FileSystem: pathfs.NewDefaultFileSystem()}
fs.Length = 200 * 1024 fs.Length = 200 * 1024
dir := testutil.TempDir() dir := t.TempDir()
defer os.RemoveAll(dir)
nfs := pathfs.NewPathNodeFs(fs, nil) nfs := pathfs.NewPathNodeFs(fs, nil)
opts := nodefs.NewOptions() opts := nodefs.NewOptions()
opts.Debug = testutil.VerboseTest() opts.Debug = testutil.VerboseTest()
...@@ -216,8 +212,7 @@ func TestNonseekable(t *testing.T) { ...@@ -216,8 +212,7 @@ func TestNonseekable(t *testing.T) {
} }
func TestGetAttrRace(t *testing.T) { func TestGetAttrRace(t *testing.T) {
dir := testutil.TempDir() dir := t.TempDir()
defer os.RemoveAll(dir)
os.Mkdir(dir+"/mnt", 0755) os.Mkdir(dir+"/mnt", 0755)
os.Mkdir(dir+"/orig", 0755) os.Mkdir(dir+"/orig", 0755)
......
...@@ -52,13 +52,7 @@ func (d *DataNode) Read(_ nodefs.File, dest []byte, off int64, _ *fuse.Context) ...@@ -52,13 +52,7 @@ func (d *DataNode) Read(_ nodefs.File, dest []byte, off int64, _ *fuse.Context)
// TestCacheControl verifies that FUSE server process can store/retrieve kernel data cache. // TestCacheControl verifies that FUSE server process can store/retrieve kernel data cache.
func TestCacheControl(t *testing.T) { func TestCacheControl(t *testing.T) {
dir := testutil.TempDir() dir := t.TempDir()
defer func() {
err := os.Remove(dir)
if err != nil {
t.Fatal(err)
}
}()
// setup a filesystem with 1 file // setup a filesystem with 1 file
root := nodefs.NewDefaultNode() root := nodefs.NewDefaultNode()
......
...@@ -16,8 +16,7 @@ import ( ...@@ -16,8 +16,7 @@ import (
) )
func TestDefaultNodeGetAttr(t *testing.T) { func TestDefaultNodeGetAttr(t *testing.T) {
dir := testutil.TempDir() dir := t.TempDir()
defer os.RemoveAll(dir)
opts := &nodefs.Options{ opts := &nodefs.Options{
// Note: defaultNode.GetAttr() calling file.GetAttr() is only useful if // Note: defaultNode.GetAttr() calling file.GetAttr() is only useful if
......
...@@ -6,7 +6,6 @@ package test ...@@ -6,7 +6,6 @@ package test
import ( import (
"io/ioutil" "io/ioutil"
"os"
"testing" "testing"
"github.com/hanwen/go-fuse/v2/fuse" "github.com/hanwen/go-fuse/v2/fuse"
...@@ -42,7 +41,7 @@ func defaultReadTest(t *testing.T) (root string, cleanup func()) { ...@@ -42,7 +41,7 @@ func defaultReadTest(t *testing.T) (root string, cleanup func()) {
} }
var err error var err error
dir := testutil.TempDir() dir := t.TempDir()
pathfs := pathfs.NewPathNodeFs(fs, nil) pathfs := pathfs.NewPathNodeFs(fs, nil)
opts := nodefs.NewOptions() opts := nodefs.NewOptions()
opts.Debug = testutil.VerboseTest() opts.Debug = testutil.VerboseTest()
...@@ -57,7 +56,6 @@ func defaultReadTest(t *testing.T) (root string, cleanup func()) { ...@@ -57,7 +56,6 @@ func defaultReadTest(t *testing.T) (root string, cleanup func()) {
} }
return dir, func() { return dir, func() {
state.Unmount() state.Unmount()
os.Remove(dir)
} }
} }
......
...@@ -34,8 +34,7 @@ func (f *flipNode) GetAttr(out *fuse.Attr, file nodefs.File, c *fuse.Context) fu ...@@ -34,8 +34,7 @@ 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 := testutil.TempDir() dir := t.TempDir()
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})
......
...@@ -123,8 +123,7 @@ func TestFlockInvoked(t *testing.T) { ...@@ -123,8 +123,7 @@ func TestFlockInvoked(t *testing.T) {
t.Skip("flock command not found.") t.Skip("flock command not found.")
} }
dir := testutil.TempDir() dir := t.TempDir()
defer os.RemoveAll(dir)
opts := &nodefs.Options{ opts := &nodefs.Options{
Owner: fuse.CurrentOwner(), Owner: fuse.CurrentOwner(),
...@@ -188,17 +187,8 @@ func TestNoLockSupport(t *testing.T) { ...@@ -188,17 +187,8 @@ func TestNoLockSupport(t *testing.T) {
t.Skip("flock command not found.") t.Skip("flock command not found.")
} }
tmp, err := ioutil.TempDir("", "TestNoLockSupport") tmp := t.TempDir()
if err != nil { mnt := t.TempDir()
t.Fatal(err)
}
mnt, err := ioutil.TempDir("", "TestNoLockSupport")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmp)
defer os.RemoveAll(mnt)
opts := &nodefs.Options{ opts := &nodefs.Options{
Owner: fuse.CurrentOwner(), Owner: fuse.CurrentOwner(),
......
...@@ -143,7 +143,7 @@ func NewFile() *MutableDataFile { ...@@ -143,7 +143,7 @@ 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 = testutil.TempDir() dir = t.TempDir()
nfs := pathfs.NewPathNodeFs(fs, nil) nfs := pathfs.NewPathNodeFs(fs, nil)
opts := nodefs.NewOptions() opts := nodefs.NewOptions()
opts.Debug = testutil.VerboseTest() opts.Debug = testutil.VerboseTest()
...@@ -161,8 +161,6 @@ func setupFAttrTest(t *testing.T, fs pathfs.FileSystem) (dir string, clean func( ...@@ -161,8 +161,6 @@ func setupFAttrTest(t *testing.T, fs pathfs.FileSystem) (dir string, clean func(
clean = func() { clean = 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 {
os.RemoveAll(dir)
} }
} }
......
...@@ -17,7 +17,6 @@ import ( ...@@ -17,7 +17,6 @@ import (
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"github.com/hanwen/go-fuse/v2/fuse" "github.com/hanwen/go-fuse/v2/fuse"
"github.com/hanwen/go-fuse/v2/internal/testutil"
) )
var enableOverlayfsTest bool var enableOverlayfsTest bool
...@@ -147,11 +146,9 @@ func TestOverlayfs(t *testing.T) { ...@@ -147,11 +146,9 @@ func TestOverlayfs(t *testing.T) {
tc.Mkdir(tc.origSubdir, 0777) tc.Mkdir(tc.origSubdir, 0777)
tc.WriteFile(filepath.Join(tc.origSubdir, testfile), content, 0700) tc.WriteFile(filepath.Join(tc.origSubdir, testfile), content, 0700)
tmpMergedDir := testutil.TempDir() tmpMergedDir := t.TempDir()
defer os.RemoveAll(tmpMergedDir) tmpWorkDir := t.TempDir()
tmpWorkDir := testutil.TempDir() tmpUpperDir := t.TempDir()
defer os.RemoveAll(tmpWorkDir)
tmpUpperDir := testutil.TempDir()
defer os.RemoveAll(tmpUpperDir) defer os.RemoveAll(tmpUpperDir)
if err := unix.Mount("overlay", tmpMergedDir, "overlay", 0, if err := unix.Mount("overlay", tmpMergedDir, "overlay", 0,
fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", tc.mnt, tmpUpperDir, tmpWorkDir)); err != nil { fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", tc.mnt, tmpUpperDir, tmpWorkDir)); err != nil {
......
...@@ -77,7 +77,7 @@ func NewTestCase(t *testing.T) *testCase { ...@@ -77,7 +77,7 @@ func NewTestCase(t *testing.T) *testCase {
const subdir string = "subdir" const subdir string = "subdir"
var err error var err error
tc.tmpDir = testutil.TempDir() tc.tmpDir = t.TempDir()
tc.orig = tc.tmpDir + "/orig" tc.orig = tc.tmpDir + "/orig"
tc.mnt = tc.tmpDir + "/mnt" tc.mnt = tc.tmpDir + "/mnt"
...@@ -125,7 +125,6 @@ func (tc *testCase) Cleanup() { ...@@ -125,7 +125,6 @@ func (tc *testCase) Cleanup() {
if err != nil { if err != nil {
tc.tester.Fatalf("Unmount failed: %v", err) tc.tester.Fatalf("Unmount failed: %v", err)
} }
os.RemoveAll(tc.tmpDir)
} }
func (tc *testCase) rootNode() *nodefs.Inode { func (tc *testCase) rootNode() *nodefs.Inode {
...@@ -774,8 +773,7 @@ func TestNonVerboseFStatFs(t *testing.T) { ...@@ -774,8 +773,7 @@ func TestNonVerboseFStatFs(t *testing.T) {
} }
func TestOriginalIsSymlink(t *testing.T) { func TestOriginalIsSymlink(t *testing.T) {
tmpDir := testutil.TempDir() tmpDir := t.TempDir()
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 {
......
...@@ -15,7 +15,6 @@ import ( ...@@ -15,7 +15,6 @@ import (
"github.com/hanwen/go-fuse/v2/fuse" "github.com/hanwen/go-fuse/v2/fuse"
"github.com/hanwen/go-fuse/v2/fuse/nodefs" "github.com/hanwen/go-fuse/v2/fuse/nodefs"
"github.com/hanwen/go-fuse/v2/fuse/pathfs" "github.com/hanwen/go-fuse/v2/fuse/pathfs"
"github.com/hanwen/go-fuse/v2/internal/testutil"
) )
func TestMountOnExisting(t *testing.T) { func TestMountOnExisting(t *testing.T) {
...@@ -171,8 +170,7 @@ func TestDeletedUnmount(t *testing.T) { ...@@ -171,8 +170,7 @@ func TestDeletedUnmount(t *testing.T) {
} }
func TestDefaultNodeMount(t *testing.T) { func TestDefaultNodeMount(t *testing.T) {
dir := testutil.TempDir() dir := t.TempDir()
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)
if err != nil { if err != nil {
...@@ -198,8 +196,7 @@ func TestDefaultNodeMount(t *testing.T) { ...@@ -198,8 +196,7 @@ func TestDefaultNodeMount(t *testing.T) {
} }
func TestLiveness(t *testing.T) { func TestLiveness(t *testing.T) {
dir := testutil.TempDir() dir := t.TempDir()
defer os.RemoveAll(dir)
root := nodefs.NewDefaultNode() root := nodefs.NewDefaultNode()
s, _, err := nodefs.MountRoot(dir, root, nil) s, _, err := nodefs.MountRoot(dir, root, nil)
if err != nil { if err != nil {
......
...@@ -28,13 +28,7 @@ func (d *truncatableFile) Truncate(file nodefs.File, size uint64, context *fuse. ...@@ -28,13 +28,7 @@ func (d *truncatableFile) Truncate(file nodefs.File, size uint64, context *fuse.
// TestNilFileTruncation verifies that the FUSE server process does not // TestNilFileTruncation verifies that the FUSE server process does not
// crash when file truncation is performed on nil file handles. // crash when file truncation is performed on nil file handles.
func TestNilFileTruncation(t *testing.T) { func TestNilFileTruncation(t *testing.T) {
dir := testutil.TempDir() dir := t.TempDir()
defer func() {
err := os.Remove(dir)
if err != nil {
t.Fatal(err)
}
}()
root := nodefs.NewDefaultNode() root := nodefs.NewDefaultNode()
opts := nodefs.NewOptions() opts := nodefs.NewOptions()
......
...@@ -11,7 +11,6 @@ import ( ...@@ -11,7 +11,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"os"
"testing" "testing"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
...@@ -58,13 +57,7 @@ func verifyFileRead(path string, dataOK string) error { ...@@ -58,13 +57,7 @@ func verifyFileRead(path string, dataOK string) error {
} }
func TestNodeParallelLookup(t *testing.T) { func TestNodeParallelLookup(t *testing.T) {
dir := testutil.TempDir() dir := t.TempDir()
defer func() {
err := os.Remove(dir)
if err != nil {
t.Fatal(err)
}
}()
root := &tRoot{ root := &tRoot{
Node: nodefs.NewDefaultNode(), Node: nodefs.NewDefaultNode(),
......
...@@ -61,7 +61,7 @@ func (n *rootNode) Lookup(out *fuse.Attr, name string, context *fuse.Context) (* ...@@ -61,7 +61,7 @@ func (n *rootNode) Lookup(out *fuse.Attr, name string, context *fuse.Context) (*
} }
func TestUpdateNode(t *testing.T) { func TestUpdateNode(t *testing.T) {
dir := testutil.TempDir() dir := t.TempDir()
root := &rootNode{ root := &rootNode{
Node: nodefs.NewDefaultNode(), Node: nodefs.NewDefaultNode(),
backing: map[string]string{"a": "aaa"}, backing: map[string]string{"a": "aaa"},
......
...@@ -6,7 +6,6 @@ package test ...@@ -6,7 +6,6 @@ package test
import ( import (
"io/ioutil" "io/ioutil"
"os"
"sync/atomic" "sync/atomic"
"testing" "testing"
...@@ -51,13 +50,7 @@ func (d *NoFileNode) Open(flags uint32, context *fuse.Context) (nodefs.File, fus ...@@ -51,13 +50,7 @@ func (d *NoFileNode) Open(flags uint32, context *fuse.Context) (nodefs.File, fus
} }
func TestNoFile(t *testing.T) { func TestNoFile(t *testing.T) {
dir := testutil.TempDir() dir := t.TempDir()
defer func() {
err := os.Remove(dir)
if err != nil {
t.Fatal(err)
}
}()
// setup a filesystem with 2 files: // setup a filesystem with 2 files:
// //
......
...@@ -78,7 +78,7 @@ type NotifyTest struct { ...@@ -78,7 +78,7 @@ 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()
me.dir = testutil.TempDir() me.dir = t.TempDir()
entryTTL := 100 * time.Millisecond entryTTL := 100 * time.Millisecond
opts := &nodefs.Options{ opts := &nodefs.Options{
EntryTimeout: entryTTL, EntryTimeout: entryTTL,
......
...@@ -34,7 +34,7 @@ func (fs *umaskFS) Mkdir(name string, mode uint32, context *fuse.Context) (code ...@@ -34,7 +34,7 @@ func (fs *umaskFS) Mkdir(name string, mode uint32, context *fuse.Context) (code
} }
func TestUmask(t *testing.T) { func TestUmask(t *testing.T) {
tmpDir := testutil.TempDir() tmpDir := t.TempDir()
orig := tmpDir + "/orig" orig := tmpDir + "/orig"
mnt := tmpDir + "/mnt" mnt := tmpDir + "/mnt"
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
package test package test
import ( import (
"os"
"path/filepath" "path/filepath"
"syscall" "syscall"
"testing" "testing"
...@@ -40,8 +39,7 @@ func (n *xattrChildNode) GetXAttr(attr string, context *fuse.Context) ([]byte, f ...@@ -40,8 +39,7 @@ func (n *xattrChildNode) GetXAttr(attr string, context *fuse.Context) ([]byte, f
} }
func TestDefaultXAttr(t *testing.T) { func TestDefaultXAttr(t *testing.T) {
dir := testutil.TempDir() dir := t.TempDir()
defer os.RemoveAll(dir)
root := &xattrNode{ root := &xattrNode{
Node: nodefs.NewDefaultNode(), Node: nodefs.NewDefaultNode(),
...@@ -70,8 +68,7 @@ func TestDefaultXAttr(t *testing.T) { ...@@ -70,8 +68,7 @@ func TestDefaultXAttr(t *testing.T) {
} }
func TestEmptyXAttr(t *testing.T) { func TestEmptyXAttr(t *testing.T) {
dir := testutil.TempDir() dir := t.TempDir()
defer os.RemoveAll(dir)
root := &xattrNode{ root := &xattrNode{
Node: nodefs.NewDefaultNode(), Node: nodefs.NewDefaultNode(),
......
// 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
}
...@@ -33,12 +33,11 @@ func (tc *testCase) Clean() { ...@@ -33,12 +33,11 @@ func (tc *testCase) Clean() {
tc.server.Unmount() tc.server.Unmount()
tc.server = nil tc.server = nil
} }
os.RemoveAll(tc.dir)
} }
func newTestCase(t *testing.T, populate bool) *testCase { func newTestCase(t *testing.T, populate bool) *testCase {
t.Helper() t.Helper()
dir := testutil.TempDir() dir := t.TempDir()
dirs := []string{"ro", "rw", "mnt"} dirs := []string{"ro", "rw", "mnt"}
if populate { if populate {
dirs = append(dirs, "ro/dir") dirs = append(dirs, "ro/dir")
......
...@@ -19,7 +19,7 @@ const testTtl = 100 * time.Millisecond ...@@ -19,7 +19,7 @@ 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()) {
root := &MultiZipFs{} root := &MultiZipFs{}
mountPoint = testutil.TempDir() mountPoint = t.TempDir()
dt := testTtl dt := testTtl
opts := &fs.Options{ opts := &fs.Options{
...@@ -34,7 +34,6 @@ func setupMzfs(t *testing.T) (mountPoint string, state *fuse.Server, cleanup fun ...@@ -34,7 +34,6 @@ func setupMzfs(t *testing.T) (mountPoint string, state *fuse.Server, cleanup fun
} }
return mountPoint, server, func() { return mountPoint, server, func() {
server.Unmount() server.Unmount()
os.RemoveAll(mountPoint)
} }
} }
......
...@@ -67,8 +67,7 @@ func TestTar(t *testing.T) { ...@@ -67,8 +67,7 @@ func TestTar(t *testing.T) {
root := &tarRoot{rc: &addClose{buf}} root := &tarRoot{rc: &addClose{buf}}
mnt := testutil.TempDir() mnt := t.TempDir()
defer os.Remove(mnt)
opts := &fs.Options{} opts := &fs.Options{}
opts.Debug = testutil.VerboseTest() opts.Debug = testutil.VerboseTest()
s, err := fs.Mount(mnt, root, opts) s, err := fs.Mount(mnt, root, opts)
......
...@@ -33,14 +33,13 @@ func setupZipfs(t *testing.T) (mountPoint string, cleanup func()) { ...@@ -33,14 +33,13 @@ func setupZipfs(t *testing.T) (mountPoint string, cleanup func()) {
t.Fatalf("NewArchiveFileSystem failed: %v", err) t.Fatalf("NewArchiveFileSystem failed: %v", err)
} }
mountPoint = testutil.TempDir() mountPoint = t.TempDir()
opts := &fs.Options{} opts := &fs.Options{}
opts.Debug = testutil.VerboseTest() opts.Debug = testutil.VerboseTest()
server, err := fs.Mount(mountPoint, root, opts) server, err := fs.Mount(mountPoint, root, opts)
return mountPoint, func() { return mountPoint, func() {
server.Unmount() server.Unmount()
os.RemoveAll(mountPoint)
} }
} }
......
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