Added an NlinkIs matcher.

geesefs-0-30-9
Aaron Jacobs 2015-03-16 12:38:17 +11:00
parent 31da208636
commit e283dcf1bc
2 changed files with 28 additions and 0 deletions

View File

@ -83,3 +83,25 @@ func birthtimeIs(c interface{}, expected time.Time) error {
return nil
}
// Match os.FileInfo values that specify a number of links equal to the given
// number. On platforms where there is no nlink field available, match all
// os.FileInfo values.
func NlinkIs(expected uint64) oglematchers.Matcher {
return oglematchers.NewMatcher(
func(c interface{}) error { return nlinkIs(c, expected) },
fmt.Sprintf("nlink is %v", expected))
}
func nlinkIs(c interface{}, expected uint64) error {
fi, ok := c.(os.FileInfo)
if !ok {
return fmt.Errorf("which is of type %v", reflect.TypeOf(c))
}
if actual, ok := extractNlink(fi.Sys()); ok && actual != expected {
return fmt.Errorf("which has nlink == %v", actual)
}
return nil
}

View File

@ -30,3 +30,9 @@ func extractBirthtime(sys interface{}) (birthtime time.Time, ok bool) {
ok = true
return
}
func extractNlink(sys interface{}) (nlink uint64, ok bool) {
nlink = uint64(sys.(*syscall.Stat_t).Nlink)
ok = true
return
}