Added an NlinkIs matcher.
parent
31da208636
commit
e283dcf1bc
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue