From 3b5a04f79d3cb6c96cfb5334450c03dff27344a6 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Mon, 16 Mar 2015 12:42:02 +1100 Subject: [PATCH] Use the new matchers. --- samples/memfs/memfs_test.go | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/samples/memfs/memfs_test.go b/samples/memfs/memfs_test.go index f73fcee..a1b89f6 100644 --- a/samples/memfs/memfs_test.go +++ b/samples/memfs/memfs_test.go @@ -28,6 +28,7 @@ import ( "time" "github.com/jacobsa/fuse" + "github.com/jacobsa/fuse/fusetesting" "github.com/jacobsa/fuse/samples/memfs" "github.com/jacobsa/gcsfuse/timeutil" . "github.com/jacobsa/oglematchers" @@ -69,10 +70,6 @@ func currentGid() uint32 { return uint32(gid) } -func timespecToTime(ts syscall.Timespec) time.Time { - return time.Unix(ts.Sec, ts.Nsec) -} - //////////////////////////////////////////////////////////////////////// // Boilerplate //////////////////////////////////////////////////////////////////////// @@ -187,7 +184,8 @@ func (t *MemFSTest) Mkdir_OneLevel() { ExpectEq("dir", fi.Name()) ExpectEq(0, fi.Size()) ExpectEq(os.ModeDir|0754, fi.Mode()) - ExpectEq(0, fi.ModTime().Sub(createTime)) + ExpectThat(fi, fusetesting.MtimeIs(createTime)) + ExpectThat(fi, fusetesting.BirthtimeIs(createTime)) ExpectTrue(fi.IsDir()) ExpectNe(0, stat.Ino) @@ -195,8 +193,6 @@ func (t *MemFSTest) Mkdir_OneLevel() { ExpectEq(currentUid(), stat.Uid) ExpectEq(currentGid(), stat.Gid) ExpectEq(0, stat.Size) - ExpectEq(0, timespecToTime(stat.Mtimespec).Sub(createTime)) - ExpectEq(0, timespecToTime(stat.Birthtimespec).Sub(createTime)) // Check the root's mtime. fi, err = os.Stat(t.mfs.Dir()) @@ -250,7 +246,8 @@ func (t *MemFSTest) Mkdir_TwoLevels() { ExpectEq("dir", fi.Name()) ExpectEq(0, fi.Size()) ExpectEq(os.ModeDir|0754, fi.Mode()) - ExpectEq(0, fi.ModTime().Sub(createTime)) + ExpectThat(fi, fusetesting.MtimeIs(createTime)) + ExpectThat(fi, fusetesting.BirthtimeIs(createTime)) ExpectTrue(fi.IsDir()) ExpectNe(0, stat.Ino) @@ -258,8 +255,6 @@ func (t *MemFSTest) Mkdir_TwoLevels() { ExpectEq(currentUid(), stat.Uid) ExpectEq(currentGid(), stat.Gid) ExpectEq(0, stat.Size) - ExpectEq(0, timespecToTime(stat.Mtimespec).Sub(createTime)) - ExpectEq(0, timespecToTime(stat.Birthtimespec).Sub(createTime)) // Check the parent's mtime. fi, err = os.Stat(path.Join(t.mfs.Dir(), "parent")) @@ -363,7 +358,8 @@ func (t *MemFSTest) CreateNewFile_InRoot() { ExpectEq("foo", fi.Name()) ExpectEq(len(contents), fi.Size()) ExpectEq(0400, fi.Mode()) - ExpectEq(0, fi.ModTime().Sub(createTime)) + ExpectThat(fi, fusetesting.MtimeIs(createTime)) + ExpectThat(fi, fusetesting.BirthtimeIs(createTime)) ExpectFalse(fi.IsDir()) ExpectNe(0, stat.Ino) @@ -371,8 +367,6 @@ func (t *MemFSTest) CreateNewFile_InRoot() { ExpectEq(currentUid(), stat.Uid) ExpectEq(currentGid(), stat.Gid) ExpectEq(len(contents), stat.Size) - ExpectEq(0, timespecToTime(stat.Mtimespec).Sub(createTime)) - ExpectEq(0, timespecToTime(stat.Birthtimespec).Sub(createTime)) // Read it back. slice, err := ioutil.ReadFile(fileName) @@ -409,7 +403,8 @@ func (t *MemFSTest) CreateNewFile_InSubDir() { ExpectEq("foo", fi.Name()) ExpectEq(len(contents), fi.Size()) ExpectEq(0400, fi.Mode()) - ExpectEq(0, fi.ModTime().Sub(createTime)) + ExpectThat(fi, fusetesting.MtimeIs(createTime)) + ExpectThat(fi, fusetesting.BirthtimeIs(createTime)) ExpectFalse(fi.IsDir()) ExpectNe(0, stat.Ino) @@ -417,8 +412,6 @@ func (t *MemFSTest) CreateNewFile_InSubDir() { ExpectEq(currentUid(), stat.Uid) ExpectEq(currentGid(), stat.Gid) ExpectEq(len(contents), stat.Size) - ExpectEq(0, timespecToTime(stat.Mtimespec).Sub(createTime)) - ExpectEq(0, timespecToTime(stat.Birthtimespec).Sub(createTime)) // Read it back. slice, err := ioutil.ReadFile(fileName) @@ -463,7 +456,8 @@ func (t *MemFSTest) ModifyExistingFile_InRoot() { ExpectEq("foo", fi.Name()) ExpectEq(len("Hello, world!"), fi.Size()) ExpectEq(0600, fi.Mode()) - ExpectEq(0, fi.ModTime().Sub(modifyTime)) + ExpectThat(fi, fusetesting.MtimeIs(modifyTime)) + ExpectThat(fi, fusetesting.BirthtimeIs(createTime)) ExpectFalse(fi.IsDir()) ExpectNe(0, stat.Ino) @@ -471,8 +465,6 @@ func (t *MemFSTest) ModifyExistingFile_InRoot() { ExpectEq(currentUid(), stat.Uid) ExpectEq(currentGid(), stat.Gid) ExpectEq(len("Hello, world!"), stat.Size) - ExpectEq(0, timespecToTime(stat.Mtimespec).Sub(modifyTime)) - ExpectEq(0, timespecToTime(stat.Birthtimespec).Sub(createTime)) // Read the file back. slice, err := ioutil.ReadFile(fileName) @@ -522,7 +514,8 @@ func (t *MemFSTest) ModifyExistingFile_InSubDir() { ExpectEq("foo", fi.Name()) ExpectEq(len("Hello, world!"), fi.Size()) ExpectEq(0600, fi.Mode()) - ExpectEq(0, fi.ModTime().Sub(modifyTime)) + ExpectThat(fi, fusetesting.MtimeIs(modifyTime)) + ExpectThat(fi, fusetesting.BirthtimeIs(createTime)) ExpectFalse(fi.IsDir()) ExpectNe(0, stat.Ino) @@ -530,8 +523,6 @@ func (t *MemFSTest) ModifyExistingFile_InSubDir() { ExpectEq(currentUid(), stat.Uid) ExpectEq(currentGid(), stat.Gid) ExpectEq(len("Hello, world!"), stat.Size) - ExpectEq(0, timespecToTime(stat.Mtimespec).Sub(modifyTime)) - ExpectEq(0, timespecToTime(stat.Birthtimespec).Sub(createTime)) // Read the file back. slice, err := ioutil.ReadFile(fileName)