Fixed test failures on OS X.

geesefs-0-30-9
Aaron Jacobs 2015-08-14 09:26:12 +10:00
parent 8f220f0e15
commit 560105cab6
2 changed files with 31 additions and 22 deletions

View File

@ -57,30 +57,39 @@ func mtimeIsWithin(c interface{}, expected time.Time, d time.Duration) error {
return nil
}
// Match os.FileInfo values that specify a file birth time equal to the given
// time. On platforms where there is no birth time available, match all
// os.FileInfo values.
func BirthtimeIs(expected time.Time) oglematchers.Matcher {
// Match os.FileInfo values that specify a file birth time within the supplied
// radius of the given time. On platforms where there is no birth time
// available, match all os.FileInfo values.
func BirthtimeIsWithin(
expected time.Time,
d time.Duration) oglematchers.Matcher {
return oglematchers.NewMatcher(
func(c interface{}) error { return birthtimeIs(c, expected) },
fmt.Sprintf("birthtime is %v", expected))
func(c interface{}) error { return birthtimeIsWithin(c, expected, d) },
fmt.Sprintf("birthtime is within %v of %v", d, expected))
}
func birthtimeIs(c interface{}, expected time.Time) error {
func birthtimeIsWithin(
c interface{},
expected time.Time,
d time.Duration) error {
fi, ok := c.(os.FileInfo)
if !ok {
return fmt.Errorf("which is of type %v", reflect.TypeOf(c))
}
// Check Sys().
if sysBirthtime, ok := extractBirthtime(fi.Sys()); ok {
if sysBirthtime != expected {
d := sysBirthtime.Sub(expected)
return fmt.Errorf(
"which has Sys() birthtime %v, off by %v",
sysBirthtime,
d)
}
t, ok := extractBirthtime(fi.Sys())
if !ok {
return nil
}
diff := t.Sub(expected)
absDiff := diff
if absDiff < 0 {
absDiff = -absDiff
}
if !(absDiff < d) {
return fmt.Errorf("which has birth time %v, off by %v", t, diff)
}
return nil

View File

@ -131,7 +131,7 @@ func (t *MemFSTest) Mkdir_OneLevel() {
ExpectEq(0, fi.Size())
ExpectEq(os.ModeDir|applyUmask(0754), fi.Mode())
ExpectThat(fi, fusetesting.MtimeIsWithin(createTime, timeSlop))
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
ExpectThat(fi, fusetesting.BirthtimeIsWithin(createTime, timeSlop))
ExpectTrue(fi.IsDir())
ExpectNe(0, stat.Ino)
@ -187,7 +187,7 @@ func (t *MemFSTest) Mkdir_TwoLevels() {
ExpectEq(0, fi.Size())
ExpectEq(os.ModeDir|applyUmask(0754), fi.Mode())
ExpectThat(fi, fusetesting.MtimeIsWithin(createTime, timeSlop))
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
ExpectThat(fi, fusetesting.BirthtimeIsWithin(createTime, timeSlop))
ExpectTrue(fi.IsDir())
ExpectNe(0, stat.Ino)
@ -296,7 +296,7 @@ func (t *MemFSTest) CreateNewFile_InRoot() {
ExpectEq(len(contents), fi.Size())
ExpectEq(applyUmask(0400), fi.Mode())
ExpectThat(fi, fusetesting.MtimeIsWithin(createTime, timeSlop))
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
ExpectThat(fi, fusetesting.BirthtimeIsWithin(createTime, timeSlop))
ExpectFalse(fi.IsDir())
ExpectNe(0, stat.Ino)
@ -338,7 +338,7 @@ func (t *MemFSTest) CreateNewFile_InSubDir() {
ExpectEq(len(contents), fi.Size())
ExpectEq(applyUmask(0400), fi.Mode())
ExpectThat(fi, fusetesting.MtimeIsWithin(createTime, timeSlop))
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
ExpectThat(fi, fusetesting.BirthtimeIsWithin(createTime, timeSlop))
ExpectFalse(fi.IsDir())
ExpectNe(0, stat.Ino)
@ -385,7 +385,7 @@ func (t *MemFSTest) ModifyExistingFile_InRoot() {
ExpectEq(len("Hello, world!"), fi.Size())
ExpectEq(applyUmask(0600), fi.Mode())
ExpectThat(fi, fusetesting.MtimeIsWithin(modifyTime, timeSlop))
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
ExpectThat(fi, fusetesting.BirthtimeIsWithin(createTime, timeSlop))
ExpectFalse(fi.IsDir())
ExpectNe(0, stat.Ino)
@ -437,7 +437,7 @@ func (t *MemFSTest) ModifyExistingFile_InSubDir() {
ExpectEq(len("Hello, world!"), fi.Size())
ExpectEq(applyUmask(0600), fi.Mode())
ExpectThat(fi, fusetesting.MtimeIsWithin(modifyTime, timeSlop))
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
ExpectThat(fi, fusetesting.BirthtimeIsWithin(createTime, timeSlop))
ExpectFalse(fi.IsDir())
ExpectNe(0, stat.Ino)