Updated hello_fs_test.
parent
08f495e8b0
commit
f099d9868f
|
@ -17,20 +17,16 @@ package hellofs_test
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/jacobsa/fuse"
|
"github.com/jacobsa/fuse"
|
||||||
|
"github.com/jacobsa/fuse/samples"
|
||||||
"github.com/jacobsa/fuse/samples/hellofs"
|
"github.com/jacobsa/fuse/samples/hellofs"
|
||||||
"github.com/googlecloudplatform/gcsfuse/timeutil"
|
|
||||||
. "github.com/jacobsa/oglematchers"
|
. "github.com/jacobsa/oglematchers"
|
||||||
. "github.com/jacobsa/ogletest"
|
. "github.com/jacobsa/ogletest"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHelloFS(t *testing.T) { RunTests(t) }
|
func TestHelloFS(t *testing.T) { RunTests(t) }
|
||||||
|
@ -40,8 +36,7 @@ func TestHelloFS(t *testing.T) { RunTests(t) }
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
type HelloFSTest struct {
|
type HelloFSTest struct {
|
||||||
clock timeutil.SimulatedClock
|
samples.SampleTest
|
||||||
mfs *fuse.MountedFileSystem
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetUpInterface = &HelloFSTest{}
|
var _ SetUpInterface = &HelloFSTest{}
|
||||||
|
@ -50,53 +45,15 @@ var _ TearDownInterface = &HelloFSTest{}
|
||||||
func init() { RegisterTestSuite(&HelloFSTest{}) }
|
func init() { RegisterTestSuite(&HelloFSTest{}) }
|
||||||
|
|
||||||
func (t *HelloFSTest) SetUp(ti *TestInfo) {
|
func (t *HelloFSTest) 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("", "hello_fs_test")
|
|
||||||
if err != nil {
|
|
||||||
panic("ioutil.TempDir: " + err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mount a file system.
|
|
||||||
fs := &hellofs.HelloFS{
|
fs := &hellofs.HelloFS{
|
||||||
Clock: &t.clock,
|
Clock: &t.Clock,
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.mfs, err = fuse.Mount(mountPoint, fs, &fuse.MountConfig{}); err != nil {
|
t.SampleTest.Initialize(fs, &fuse.MountConfig{})
|
||||||
panic("Mount: " + err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = t.mfs.WaitForReady(context.Background()); err != nil {
|
|
||||||
panic("MountedFileSystem.WaitForReady: " + err.Error())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *HelloFSTest) TearDown() {
|
func (t *HelloFSTest) TearDown() {
|
||||||
// Unmount the file system. Try again on "resource busy" errors.
|
t.SampleTest.Destroy()
|
||||||
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())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -104,7 +61,7 @@ func (t *HelloFSTest) TearDown() {
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
func (t *HelloFSTest) ReadDir_Root() {
|
func (t *HelloFSTest) ReadDir_Root() {
|
||||||
entries, err := ioutil.ReadDir(t.mfs.Dir())
|
entries, err := ioutil.ReadDir(t.Dir)
|
||||||
|
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
AssertEq(2, len(entries))
|
AssertEq(2, len(entries))
|
||||||
|
@ -115,7 +72,7 @@ func (t *HelloFSTest) ReadDir_Root() {
|
||||||
ExpectEq("dir", fi.Name())
|
ExpectEq("dir", fi.Name())
|
||||||
ExpectEq(0, fi.Size())
|
ExpectEq(0, fi.Size())
|
||||||
ExpectEq(os.ModeDir|0555, fi.Mode())
|
ExpectEq(os.ModeDir|0555, fi.Mode())
|
||||||
ExpectEq(0, t.clock.Now().Sub(fi.ModTime()), "ModTime: %v", fi.ModTime())
|
ExpectEq(0, t.Clock.Now().Sub(fi.ModTime()), "ModTime: %v", fi.ModTime())
|
||||||
ExpectTrue(fi.IsDir())
|
ExpectTrue(fi.IsDir())
|
||||||
|
|
||||||
// hello
|
// hello
|
||||||
|
@ -123,12 +80,12 @@ func (t *HelloFSTest) ReadDir_Root() {
|
||||||
ExpectEq("hello", fi.Name())
|
ExpectEq("hello", fi.Name())
|
||||||
ExpectEq(len("Hello, world!"), fi.Size())
|
ExpectEq(len("Hello, world!"), fi.Size())
|
||||||
ExpectEq(0444, fi.Mode())
|
ExpectEq(0444, fi.Mode())
|
||||||
ExpectEq(0, t.clock.Now().Sub(fi.ModTime()), "ModTime: %v", fi.ModTime())
|
ExpectEq(0, t.Clock.Now().Sub(fi.ModTime()), "ModTime: %v", fi.ModTime())
|
||||||
ExpectFalse(fi.IsDir())
|
ExpectFalse(fi.IsDir())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *HelloFSTest) ReadDir_Dir() {
|
func (t *HelloFSTest) ReadDir_Dir() {
|
||||||
entries, err := ioutil.ReadDir(path.Join(t.mfs.Dir(), "dir"))
|
entries, err := ioutil.ReadDir(path.Join(t.Dir, "dir"))
|
||||||
|
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
AssertEq(1, len(entries))
|
AssertEq(1, len(entries))
|
||||||
|
@ -139,76 +96,76 @@ func (t *HelloFSTest) ReadDir_Dir() {
|
||||||
ExpectEq("world", fi.Name())
|
ExpectEq("world", fi.Name())
|
||||||
ExpectEq(len("Hello, world!"), fi.Size())
|
ExpectEq(len("Hello, world!"), fi.Size())
|
||||||
ExpectEq(0444, fi.Mode())
|
ExpectEq(0444, fi.Mode())
|
||||||
ExpectEq(0, t.clock.Now().Sub(fi.ModTime()), "ModTime: %v", fi.ModTime())
|
ExpectEq(0, t.Clock.Now().Sub(fi.ModTime()), "ModTime: %v", fi.ModTime())
|
||||||
ExpectFalse(fi.IsDir())
|
ExpectFalse(fi.IsDir())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *HelloFSTest) ReadDir_NonExistent() {
|
func (t *HelloFSTest) ReadDir_NonExistent() {
|
||||||
_, err := ioutil.ReadDir(path.Join(t.mfs.Dir(), "foobar"))
|
_, err := ioutil.ReadDir(path.Join(t.Dir, "foobar"))
|
||||||
|
|
||||||
AssertNe(nil, err)
|
AssertNe(nil, err)
|
||||||
ExpectThat(err, Error(HasSubstr("no such file")))
|
ExpectThat(err, Error(HasSubstr("no such file")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *HelloFSTest) Stat_Hello() {
|
func (t *HelloFSTest) Stat_Hello() {
|
||||||
fi, err := os.Stat(path.Join(t.mfs.Dir(), "hello"))
|
fi, err := os.Stat(path.Join(t.Dir, "hello"))
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
ExpectEq("hello", fi.Name())
|
ExpectEq("hello", fi.Name())
|
||||||
ExpectEq(len("Hello, world!"), fi.Size())
|
ExpectEq(len("Hello, world!"), fi.Size())
|
||||||
ExpectEq(0444, fi.Mode())
|
ExpectEq(0444, fi.Mode())
|
||||||
ExpectEq(0, t.clock.Now().Sub(fi.ModTime()), "ModTime: %v", fi.ModTime())
|
ExpectEq(0, t.Clock.Now().Sub(fi.ModTime()), "ModTime: %v", fi.ModTime())
|
||||||
ExpectFalse(fi.IsDir())
|
ExpectFalse(fi.IsDir())
|
||||||
ExpectEq(1, fi.Sys().(*syscall.Stat_t).Nlink)
|
ExpectEq(1, fi.Sys().(*syscall.Stat_t).Nlink)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *HelloFSTest) Stat_Dir() {
|
func (t *HelloFSTest) Stat_Dir() {
|
||||||
fi, err := os.Stat(path.Join(t.mfs.Dir(), "dir"))
|
fi, err := os.Stat(path.Join(t.Dir, "dir"))
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
ExpectEq("dir", fi.Name())
|
ExpectEq("dir", fi.Name())
|
||||||
ExpectEq(0, fi.Size())
|
ExpectEq(0, fi.Size())
|
||||||
ExpectEq(0555|os.ModeDir, fi.Mode())
|
ExpectEq(0555|os.ModeDir, fi.Mode())
|
||||||
ExpectEq(0, t.clock.Now().Sub(fi.ModTime()), "ModTime: %v", fi.ModTime())
|
ExpectEq(0, t.Clock.Now().Sub(fi.ModTime()), "ModTime: %v", fi.ModTime())
|
||||||
ExpectTrue(fi.IsDir())
|
ExpectTrue(fi.IsDir())
|
||||||
ExpectEq(1, fi.Sys().(*syscall.Stat_t).Nlink)
|
ExpectEq(1, fi.Sys().(*syscall.Stat_t).Nlink)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *HelloFSTest) Stat_World() {
|
func (t *HelloFSTest) Stat_World() {
|
||||||
fi, err := os.Stat(path.Join(t.mfs.Dir(), "dir/world"))
|
fi, err := os.Stat(path.Join(t.Dir, "dir/world"))
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
ExpectEq("world", fi.Name())
|
ExpectEq("world", fi.Name())
|
||||||
ExpectEq(len("Hello, world!"), fi.Size())
|
ExpectEq(len("Hello, world!"), fi.Size())
|
||||||
ExpectEq(0444, fi.Mode())
|
ExpectEq(0444, fi.Mode())
|
||||||
ExpectEq(0, t.clock.Now().Sub(fi.ModTime()), "ModTime: %v", fi.ModTime())
|
ExpectEq(0, t.Clock.Now().Sub(fi.ModTime()), "ModTime: %v", fi.ModTime())
|
||||||
ExpectFalse(fi.IsDir())
|
ExpectFalse(fi.IsDir())
|
||||||
ExpectEq(1, fi.Sys().(*syscall.Stat_t).Nlink)
|
ExpectEq(1, fi.Sys().(*syscall.Stat_t).Nlink)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *HelloFSTest) Stat_NonExistent() {
|
func (t *HelloFSTest) Stat_NonExistent() {
|
||||||
_, err := os.Stat(path.Join(t.mfs.Dir(), "foobar"))
|
_, err := os.Stat(path.Join(t.Dir, "foobar"))
|
||||||
|
|
||||||
AssertNe(nil, err)
|
AssertNe(nil, err)
|
||||||
ExpectThat(err, Error(HasSubstr("no such file")))
|
ExpectThat(err, Error(HasSubstr("no such file")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *HelloFSTest) ReadFile_Hello() {
|
func (t *HelloFSTest) ReadFile_Hello() {
|
||||||
slice, err := ioutil.ReadFile(path.Join(t.mfs.Dir(), "hello"))
|
slice, err := ioutil.ReadFile(path.Join(t.Dir, "hello"))
|
||||||
|
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
ExpectEq("Hello, world!", string(slice))
|
ExpectEq("Hello, world!", string(slice))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *HelloFSTest) ReadFile_Dir() {
|
func (t *HelloFSTest) ReadFile_Dir() {
|
||||||
_, err := ioutil.ReadFile(path.Join(t.mfs.Dir(), "dir"))
|
_, err := ioutil.ReadFile(path.Join(t.Dir, "dir"))
|
||||||
|
|
||||||
AssertNe(nil, err)
|
AssertNe(nil, err)
|
||||||
ExpectThat(err, Error(HasSubstr("is a directory")))
|
ExpectThat(err, Error(HasSubstr("is a directory")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *HelloFSTest) ReadFile_World() {
|
func (t *HelloFSTest) ReadFile_World() {
|
||||||
slice, err := ioutil.ReadFile(path.Join(t.mfs.Dir(), "dir/world"))
|
slice, err := ioutil.ReadFile(path.Join(t.Dir, "dir/world"))
|
||||||
|
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
ExpectEq("Hello, world!", string(slice))
|
ExpectEq("Hello, world!", string(slice))
|
||||||
|
@ -221,7 +178,7 @@ func (t *HelloFSTest) OpenAndRead() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Open the file.
|
// Open the file.
|
||||||
f, err := os.Open(path.Join(t.mfs.Dir(), "hello"))
|
f, err := os.Open(path.Join(t.Dir, "hello"))
|
||||||
defer func() {
|
defer func() {
|
||||||
if f != nil {
|
if f != nil {
|
||||||
ExpectEq(nil, f.Close())
|
ExpectEq(nil, f.Close())
|
||||||
|
@ -268,7 +225,7 @@ func (t *HelloFSTest) OpenAndRead() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *HelloFSTest) Open_NonExistent() {
|
func (t *HelloFSTest) Open_NonExistent() {
|
||||||
_, err := os.Open(path.Join(t.mfs.Dir(), "foobar"))
|
_, err := os.Open(path.Join(t.Dir, "foobar"))
|
||||||
|
|
||||||
AssertNe(nil, err)
|
AssertNe(nil, err)
|
||||||
ExpectThat(err, Error(HasSubstr("no such file")))
|
ExpectThat(err, Error(HasSubstr("no such file")))
|
||||||
|
|
|
@ -77,6 +77,13 @@ func (t *SampleTest) initialize(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait for it to be read.
|
||||||
|
err = t.mfs.WaitForReady(t.Ctx)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("WaitForReady: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue