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

nodefs: use testMount in tests

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