Commit e283dcf1 authored by Aaron Jacobs's avatar Aaron Jacobs

Added an NlinkIs matcher.

parent 31da2086
......@@ -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
}
......@@ -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
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment