Implemented BirthtimeIs for darwin.
parent
9489817fc6
commit
31da208636
|
@ -58,4 +58,28 @@ func mtimeIs(c interface{}, expected time.Time) error {
|
||||||
// Match os.FileInfo values that specify a file birth time equal to the given
|
// 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
|
// time. On platforms where there is no birth time available, match all
|
||||||
// os.FileInfo values.
|
// os.FileInfo values.
|
||||||
func BirthtimeIs(expected time.Time) oglematchers.Matcher
|
func BirthtimeIs(expected time.Time) oglematchers.Matcher {
|
||||||
|
return oglematchers.NewMatcher(
|
||||||
|
func(c interface{}) error { return birthtimeIs(c, expected) },
|
||||||
|
fmt.Sprintf("birthtime is %v", expected))
|
||||||
|
}
|
||||||
|
|
||||||
|
func birthtimeIs(c interface{}, expected time.Time) 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -24,3 +24,9 @@ func extractMtime(sys interface{}) (mtime time.Time, ok bool) {
|
||||||
ok = true
|
ok = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func extractBirthtime(sys interface{}) (birthtime time.Time, ok bool) {
|
||||||
|
birthtime = time.Unix(sys.(*syscall.Stat_t).Birthtimespec.Unix())
|
||||||
|
ok = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue