Fixed several mtime assertions.
parent
a6dd3d2147
commit
d6e247cc46
|
@ -28,28 +28,32 @@ import (
|
||||||
// also that it matches.
|
// also that it matches.
|
||||||
func MtimeIs(expected time.Time) oglematchers.Matcher {
|
func MtimeIs(expected time.Time) oglematchers.Matcher {
|
||||||
return oglematchers.NewMatcher(
|
return oglematchers.NewMatcher(
|
||||||
func(c interface{}) error { return mtimeIs(c, expected) },
|
func(c interface{}) error { return mtimeIsWithin(c, expected, 0) },
|
||||||
fmt.Sprintf("mtime is %v", expected))
|
fmt.Sprintf("mtime is %v", expected))
|
||||||
}
|
}
|
||||||
|
|
||||||
func mtimeIs(c interface{}, expected time.Time) error {
|
// Like MtimeIs, but allows for a tolerance.
|
||||||
|
func MtimeIsWithin(expected time.Time, d time.Duration) oglematchers.Matcher {
|
||||||
|
return oglematchers.NewMatcher(
|
||||||
|
func(c interface{}) error { return mtimeIsWithin(c, expected, d) },
|
||||||
|
fmt.Sprintf("mtime is within %v of %v", d, expected))
|
||||||
|
}
|
||||||
|
|
||||||
|
func mtimeIsWithin(c interface{}, expected time.Time, d time.Duration) error {
|
||||||
fi, ok := c.(os.FileInfo)
|
fi, ok := c.(os.FileInfo)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("which is of type %v", reflect.TypeOf(c))
|
return fmt.Errorf("which is of type %v", reflect.TypeOf(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check ModTime().
|
// Check ModTime().
|
||||||
if fi.ModTime() != expected {
|
diff := fi.ModTime().Sub(expected)
|
||||||
d := fi.ModTime().Sub(expected)
|
absDiff := diff
|
||||||
return fmt.Errorf("which has mtime %v, off by %v", fi.ModTime(), d)
|
if absDiff < 0 {
|
||||||
|
absDiff = -absDiff
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Sys().
|
if !(absDiff < d) {
|
||||||
if sysMtime, ok := extractMtime(fi.Sys()); ok {
|
return fmt.Errorf("which has mtime %v, off by %v", fi.ModTime(), diff)
|
||||||
if sysMtime != expected {
|
|
||||||
d := sysMtime.Sub(expected)
|
|
||||||
return fmt.Errorf("which has Sys() mtime %v, off by %v", sysMtime, d)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -35,6 +35,9 @@ import (
|
||||||
|
|
||||||
func TestMemFS(t *testing.T) { RunTests(t) }
|
func TestMemFS(t *testing.T) { RunTests(t) }
|
||||||
|
|
||||||
|
// TODO(jacobsa): Comments.
|
||||||
|
const timeSlop = 5 * time.Millisecond
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Helpers
|
// Helpers
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -125,7 +128,7 @@ func (t *MemFSTest) Mkdir_OneLevel() {
|
||||||
ExpectEq("dir", fi.Name())
|
ExpectEq("dir", fi.Name())
|
||||||
ExpectEq(0, fi.Size())
|
ExpectEq(0, fi.Size())
|
||||||
ExpectEq(os.ModeDir|applyUmask(0754), fi.Mode())
|
ExpectEq(os.ModeDir|applyUmask(0754), fi.Mode())
|
||||||
ExpectThat(fi, fusetesting.MtimeIs(createTime))
|
ExpectThat(fi, fusetesting.MtimeIsWithin(createTime, timeSlop))
|
||||||
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
||||||
ExpectTrue(fi.IsDir())
|
ExpectTrue(fi.IsDir())
|
||||||
|
|
||||||
|
@ -181,7 +184,7 @@ func (t *MemFSTest) Mkdir_TwoLevels() {
|
||||||
ExpectEq("dir", fi.Name())
|
ExpectEq("dir", fi.Name())
|
||||||
ExpectEq(0, fi.Size())
|
ExpectEq(0, fi.Size())
|
||||||
ExpectEq(os.ModeDir|applyUmask(0754), fi.Mode())
|
ExpectEq(os.ModeDir|applyUmask(0754), fi.Mode())
|
||||||
ExpectThat(fi, fusetesting.MtimeIs(createTime))
|
ExpectThat(fi, fusetesting.MtimeIsWithin(createTime, timeSlop))
|
||||||
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
||||||
ExpectTrue(fi.IsDir())
|
ExpectTrue(fi.IsDir())
|
||||||
|
|
||||||
|
@ -290,7 +293,7 @@ func (t *MemFSTest) CreateNewFile_InRoot() {
|
||||||
ExpectEq("foo", fi.Name())
|
ExpectEq("foo", fi.Name())
|
||||||
ExpectEq(len(contents), fi.Size())
|
ExpectEq(len(contents), fi.Size())
|
||||||
ExpectEq(applyUmask(0400), fi.Mode())
|
ExpectEq(applyUmask(0400), fi.Mode())
|
||||||
ExpectThat(fi, fusetesting.MtimeIs(createTime))
|
ExpectThat(fi, fusetesting.MtimeIsWithin(createTime, timeSlop))
|
||||||
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
||||||
ExpectFalse(fi.IsDir())
|
ExpectFalse(fi.IsDir())
|
||||||
|
|
||||||
|
@ -332,7 +335,7 @@ func (t *MemFSTest) CreateNewFile_InSubDir() {
|
||||||
ExpectEq("foo", fi.Name())
|
ExpectEq("foo", fi.Name())
|
||||||
ExpectEq(len(contents), fi.Size())
|
ExpectEq(len(contents), fi.Size())
|
||||||
ExpectEq(applyUmask(0400), fi.Mode())
|
ExpectEq(applyUmask(0400), fi.Mode())
|
||||||
ExpectThat(fi, fusetesting.MtimeIs(createTime))
|
ExpectThat(fi, fusetesting.MtimeIsWithin(createTime, timeSlop))
|
||||||
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
||||||
ExpectFalse(fi.IsDir())
|
ExpectFalse(fi.IsDir())
|
||||||
|
|
||||||
|
@ -379,7 +382,7 @@ func (t *MemFSTest) ModifyExistingFile_InRoot() {
|
||||||
ExpectEq("foo", fi.Name())
|
ExpectEq("foo", fi.Name())
|
||||||
ExpectEq(len("Hello, world!"), fi.Size())
|
ExpectEq(len("Hello, world!"), fi.Size())
|
||||||
ExpectEq(applyUmask(0600), fi.Mode())
|
ExpectEq(applyUmask(0600), fi.Mode())
|
||||||
ExpectThat(fi, fusetesting.MtimeIs(modifyTime))
|
ExpectThat(fi, fusetesting.MtimeIsWithin(modifyTime, timeSlop))
|
||||||
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
||||||
ExpectFalse(fi.IsDir())
|
ExpectFalse(fi.IsDir())
|
||||||
|
|
||||||
|
@ -431,7 +434,7 @@ func (t *MemFSTest) ModifyExistingFile_InSubDir() {
|
||||||
ExpectEq("foo", fi.Name())
|
ExpectEq("foo", fi.Name())
|
||||||
ExpectEq(len("Hello, world!"), fi.Size())
|
ExpectEq(len("Hello, world!"), fi.Size())
|
||||||
ExpectEq(applyUmask(0600), fi.Mode())
|
ExpectEq(applyUmask(0600), fi.Mode())
|
||||||
ExpectThat(fi, fusetesting.MtimeIs(modifyTime))
|
ExpectThat(fi, fusetesting.MtimeIsWithin(modifyTime, timeSlop))
|
||||||
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
||||||
ExpectFalse(fi.IsDir())
|
ExpectFalse(fi.IsDir())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue