Fixed test failures on OS X.
parent
8f220f0e15
commit
560105cab6
|
@ -57,30 +57,39 @@ func mtimeIsWithin(c interface{}, expected time.Time, d time.Duration) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match os.FileInfo values that specify a file birth time equal to the given
|
// Match os.FileInfo values that specify a file birth time within the supplied
|
||||||
// time. On platforms where there is no birth time available, match all
|
// radius of the given time. On platforms where there is no birth time
|
||||||
// os.FileInfo values.
|
// available, match all os.FileInfo values.
|
||||||
func BirthtimeIs(expected time.Time) oglematchers.Matcher {
|
func BirthtimeIsWithin(
|
||||||
|
expected time.Time,
|
||||||
|
d time.Duration) oglematchers.Matcher {
|
||||||
return oglematchers.NewMatcher(
|
return oglematchers.NewMatcher(
|
||||||
func(c interface{}) error { return birthtimeIs(c, expected) },
|
func(c interface{}) error { return birthtimeIsWithin(c, expected, d) },
|
||||||
fmt.Sprintf("birthtime is %v", expected))
|
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)
|
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 Sys().
|
t, ok := extractBirthtime(fi.Sys())
|
||||||
if sysBirthtime, ok := extractBirthtime(fi.Sys()); ok {
|
if !ok {
|
||||||
if sysBirthtime != expected {
|
return nil
|
||||||
d := sysBirthtime.Sub(expected)
|
|
||||||
return fmt.Errorf(
|
|
||||||
"which has Sys() birthtime %v, off by %v",
|
|
||||||
sysBirthtime,
|
|
||||||
d)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
return nil
|
||||||
|
|
|
@ -131,7 +131,7 @@ func (t *MemFSTest) Mkdir_OneLevel() {
|
||||||
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.MtimeIsWithin(createTime, timeSlop))
|
ExpectThat(fi, fusetesting.MtimeIsWithin(createTime, timeSlop))
|
||||||
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
ExpectThat(fi, fusetesting.BirthtimeIsWithin(createTime, timeSlop))
|
||||||
ExpectTrue(fi.IsDir())
|
ExpectTrue(fi.IsDir())
|
||||||
|
|
||||||
ExpectNe(0, stat.Ino)
|
ExpectNe(0, stat.Ino)
|
||||||
|
@ -187,7 +187,7 @@ func (t *MemFSTest) Mkdir_TwoLevels() {
|
||||||
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.MtimeIsWithin(createTime, timeSlop))
|
ExpectThat(fi, fusetesting.MtimeIsWithin(createTime, timeSlop))
|
||||||
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
ExpectThat(fi, fusetesting.BirthtimeIsWithin(createTime, timeSlop))
|
||||||
ExpectTrue(fi.IsDir())
|
ExpectTrue(fi.IsDir())
|
||||||
|
|
||||||
ExpectNe(0, stat.Ino)
|
ExpectNe(0, stat.Ino)
|
||||||
|
@ -296,7 +296,7 @@ func (t *MemFSTest) CreateNewFile_InRoot() {
|
||||||
ExpectEq(len(contents), fi.Size())
|
ExpectEq(len(contents), fi.Size())
|
||||||
ExpectEq(applyUmask(0400), fi.Mode())
|
ExpectEq(applyUmask(0400), fi.Mode())
|
||||||
ExpectThat(fi, fusetesting.MtimeIsWithin(createTime, timeSlop))
|
ExpectThat(fi, fusetesting.MtimeIsWithin(createTime, timeSlop))
|
||||||
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
ExpectThat(fi, fusetesting.BirthtimeIsWithin(createTime, timeSlop))
|
||||||
ExpectFalse(fi.IsDir())
|
ExpectFalse(fi.IsDir())
|
||||||
|
|
||||||
ExpectNe(0, stat.Ino)
|
ExpectNe(0, stat.Ino)
|
||||||
|
@ -338,7 +338,7 @@ func (t *MemFSTest) CreateNewFile_InSubDir() {
|
||||||
ExpectEq(len(contents), fi.Size())
|
ExpectEq(len(contents), fi.Size())
|
||||||
ExpectEq(applyUmask(0400), fi.Mode())
|
ExpectEq(applyUmask(0400), fi.Mode())
|
||||||
ExpectThat(fi, fusetesting.MtimeIsWithin(createTime, timeSlop))
|
ExpectThat(fi, fusetesting.MtimeIsWithin(createTime, timeSlop))
|
||||||
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
ExpectThat(fi, fusetesting.BirthtimeIsWithin(createTime, timeSlop))
|
||||||
ExpectFalse(fi.IsDir())
|
ExpectFalse(fi.IsDir())
|
||||||
|
|
||||||
ExpectNe(0, stat.Ino)
|
ExpectNe(0, stat.Ino)
|
||||||
|
@ -385,7 +385,7 @@ func (t *MemFSTest) ModifyExistingFile_InRoot() {
|
||||||
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.MtimeIsWithin(modifyTime, timeSlop))
|
ExpectThat(fi, fusetesting.MtimeIsWithin(modifyTime, timeSlop))
|
||||||
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
ExpectThat(fi, fusetesting.BirthtimeIsWithin(createTime, timeSlop))
|
||||||
ExpectFalse(fi.IsDir())
|
ExpectFalse(fi.IsDir())
|
||||||
|
|
||||||
ExpectNe(0, stat.Ino)
|
ExpectNe(0, stat.Ino)
|
||||||
|
@ -437,7 +437,7 @@ func (t *MemFSTest) ModifyExistingFile_InSubDir() {
|
||||||
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.MtimeIsWithin(modifyTime, timeSlop))
|
ExpectThat(fi, fusetesting.MtimeIsWithin(modifyTime, timeSlop))
|
||||||
ExpectThat(fi, fusetesting.BirthtimeIs(createTime))
|
ExpectThat(fi, fusetesting.BirthtimeIsWithin(createTime, timeSlop))
|
||||||
ExpectFalse(fi.IsDir())
|
ExpectFalse(fi.IsDir())
|
||||||
|
|
||||||
ExpectNe(0, stat.Ino)
|
ExpectNe(0, stat.Ino)
|
||||||
|
|
Loading…
Reference in New Issue