Began on a memfs test.

geesefs-0-30-9
Aaron Jacobs 2015-03-02 14:11:09 +11:00
parent 3379842d1e
commit 9fb1bc6bff
1 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,93 @@
// Copyright 2015 Google Inc. All Rights Reserved.
// Author: jacobsa@google.com (Aaron Jacobs)
package memfs_test
import (
"io/ioutil"
"log"
"strings"
"testing"
"time"
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse/samples/memfs"
"github.com/jacobsa/gcsfuse/timeutil"
. "github.com/jacobsa/ogletest"
"golang.org/x/net/context"
)
func TestMemFS(t *testing.T) { RunTests(t) }
////////////////////////////////////////////////////////////////////////
// Boilerplate
////////////////////////////////////////////////////////////////////////
type MemFSTest struct {
clock timeutil.SimulatedClock
mfs *fuse.MountedFileSystem
}
var _ SetUpInterface = &MemFSTest{}
var _ TearDownInterface = &MemFSTest{}
func init() { RegisterTestSuite(&MemFSTest{}) }
func (t *MemFSTest) SetUp(ti *TestInfo) {
var err error
// Set up a fixed, non-zero time.
t.clock.SetTime(time.Now())
// Set up a temporary directory for mounting.
mountPoint, err := ioutil.TempDir("", "memfs_test")
if err != nil {
panic("ioutil.TempDir: " + err.Error())
}
// Mount a file system.
fs := memfs.NewMemFS(&t.clock)
if t.mfs, err = fuse.Mount(mountPoint, fs); err != nil {
panic("Mount: " + err.Error())
}
if err = t.mfs.WaitForReady(context.Background()); err != nil {
panic("MountedFileSystem.WaitForReady: " + err.Error())
}
}
func (t *MemFSTest) TearDown() {
// Unmount the file system. Try again on "resource busy" errors.
delay := 10 * time.Millisecond
for {
err := t.mfs.Unmount()
if err == nil {
break
}
if strings.Contains(err.Error(), "resource busy") {
log.Println("Resource busy error while unmounting; trying again")
time.Sleep(delay)
delay = time.Duration(1.3 * float64(delay))
continue
}
panic("MountedFileSystem.Unmount: " + err.Error())
}
if err := t.mfs.Join(context.Background()); err != nil {
panic("MountedFileSystem.Join: " + err.Error())
}
}
////////////////////////////////////////////////////////////////////////
// Test functions
////////////////////////////////////////////////////////////////////////
func (t *MemFSTest) ContentsOfEmptyFileSystem() {
AssertTrue(false, "TODO")
}
func (t *MemFSTest) DoesFoo() {
AssertTrue(false, "TODO")
}