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

nodefs: use testMount in tests

parent f73926e3
...@@ -9,13 +9,11 @@ import ( ...@@ -9,13 +9,11 @@ import (
"context" "context"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os"
"sync" "sync"
"syscall" "syscall"
"testing" "testing"
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/internal/testutil"
) )
type keepCacheFile struct { type keepCacheFile struct {
...@@ -27,6 +25,10 @@ type keepCacheFile struct { ...@@ -27,6 +25,10 @@ type keepCacheFile struct {
count int count int
} }
var _ = (Reader)((*keepCacheFile)(nil))
var _ = (Opener)((*keepCacheFile)(nil))
var _ = (Getattrer)((*keepCacheFile)(nil))
func (f *keepCacheFile) setContent(delta int) { func (f *keepCacheFile) setContent(delta int) {
f.mu.Lock() f.mu.Lock()
defer f.mu.Unlock() defer f.mu.Unlock()
...@@ -61,10 +63,6 @@ func (f *keepCacheFile) Read(ctx context.Context, fh FileHandle, dest []byte, of ...@@ -61,10 +63,6 @@ func (f *keepCacheFile) Read(ctx context.Context, fh FileHandle, dest []byte, of
return fuse.ReadResultData(f.content[off:]), OK return fuse.ReadResultData(f.content[off:]), OK
} }
var _ = (Reader)((*keepCacheFile)(nil))
var _ = (Opener)((*keepCacheFile)(nil))
var _ = (Getattrer)((*keepCacheFile)(nil))
type keepCacheRoot struct { type keepCacheRoot struct {
Inode Inode
...@@ -93,18 +91,9 @@ func (r *keepCacheRoot) OnAdd(ctx context.Context) { ...@@ -93,18 +91,9 @@ func (r *keepCacheRoot) OnAdd(ctx context.Context) {
// invalidation triggers if mtime or file size is changed, so only // invalidation triggers if mtime or file size is changed, so only
// change content but no metadata. // change content but no metadata.
func TestKeepCache(t *testing.T) { func TestKeepCache(t *testing.T) {
mntDir := testutil.TempDir()
defer os.RemoveAll(mntDir)
root := &keepCacheRoot{} root := &keepCacheRoot{}
server, err := Mount(mntDir, root, &Options{ mntDir, clean := testMount(t, root, nil)
MountOptions: fuse.MountOptions{ defer clean()
Debug: testutil.VerboseTest(),
},
FirstAutomaticIno: 1,
// no caching.
})
defer server.Unmount()
c1, err := ioutil.ReadFile(mntDir + "/keep") c1, err := ioutil.ReadFile(mntDir + "/keep")
if err != nil { if err != nil {
t.Fatalf("read keep 1: %v", err) t.Fatalf("read keep 1: %v", err)
......
...@@ -13,7 +13,6 @@ import ( ...@@ -13,7 +13,6 @@ import (
"testing" "testing"
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/internal/testutil"
) )
type dioRoot struct { type dioRoot struct {
...@@ -55,18 +54,8 @@ func (f *dioFile) Open(ctx context.Context, flags uint32) (fh FileHandle, fuseFl ...@@ -55,18 +54,8 @@ func (f *dioFile) Open(ctx context.Context, flags uint32) (fh FileHandle, fuseFl
func TestDirectIO(t *testing.T) { func TestDirectIO(t *testing.T) {
root := &dioRoot{} root := &dioRoot{}
mntDir := testutil.TempDir() mntDir, clean := testMount(t, root, nil)
defer clean()
defer os.RemoveAll(mntDir)
server, err := Mount(mntDir, root, &Options{
MountOptions: fuse.MountOptions{
Debug: testutil.VerboseTest(),
},
FirstAutomaticIno: 1,
// no caching.
})
defer server.Unmount()
f, err := os.Open(mntDir + "/file") f, err := os.Open(mntDir + "/file")
if err != nil { if err != nil {
......
...@@ -6,14 +6,12 @@ package nodefs ...@@ -6,14 +6,12 @@ package nodefs
import ( import (
"context" "context"
"os"
"os/exec" "os/exec"
"syscall" "syscall"
"testing" "testing"
"time" "time"
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/internal/testutil"
) )
type interruptRoot struct { type interruptRoot struct {
...@@ -54,22 +52,18 @@ func (o *interruptOps) Open(ctx context.Context, flags uint32) (FileHandle, uint ...@@ -54,22 +52,18 @@ func (o *interruptOps) Open(ctx context.Context, flags uint32) (FileHandle, uint
// This currently doesn't test functionality, but is useful to investigate how // This currently doesn't test functionality, but is useful to investigate how
// INTERRUPT opcodes are handled. // INTERRUPT opcodes are handled.
func TestInterrupt(t *testing.T) { func TestInterrupt(t *testing.T) {
mntDir := testutil.TempDir()
defer os.Remove(mntDir)
root := &interruptRoot{} root := &interruptRoot{}
oneSec := time.Second oneSec := time.Second
server, err := Mount(mntDir, root, &Options{ mntDir, clean := testMount(t, root, &Options{
MountOptions: fuse.MountOptions{
Debug: testutil.VerboseTest(),
},
EntryTimeout: &oneSec, EntryTimeout: &oneSec,
AttrTimeout: &oneSec, AttrTimeout: &oneSec,
}) })
if err != nil { defer func() {
t.Fatal(err) if clean != nil {
} clean()
defer server.Unmount() }
}()
cmd := exec.Command("cat", mntDir+"/file") cmd := exec.Command("cat", mntDir+"/file")
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
...@@ -81,7 +75,9 @@ func TestInterrupt(t *testing.T) { ...@@ -81,7 +75,9 @@ func TestInterrupt(t *testing.T) {
t.Errorf("Kill: %v", err) t.Errorf("Kill: %v", err)
} }
server.Unmount() clean()
clean = nil
if !root.child.interrupted { if !root.child.interrupted {
t.Errorf("open request was not interrupted") t.Errorf("open request was not interrupted")
} }
......
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