diff --git a/fusetesting/stat.go b/fusetesting/stat.go index c1d282c..8077624 100644 --- a/fusetesting/stat.go +++ b/fusetesting/stat.go @@ -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 // time. On platforms where there is no birth time available, match all // 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 +} diff --git a/fusetesting/stat_darwin.go b/fusetesting/stat_darwin.go index c8785d5..2b84caf 100644 --- a/fusetesting/stat_darwin.go +++ b/fusetesting/stat_darwin.go @@ -24,3 +24,9 @@ func extractMtime(sys interface{}) (mtime time.Time, ok bool) { ok = true return } + +func extractBirthtime(sys interface{}) (birthtime time.Time, ok bool) { + birthtime = time.Unix(sys.(*syscall.Stat_t).Birthtimespec.Unix()) + ok = true + return +}