Implemented MtimeIs.
parent
72b8c3e9a0
commit
47570943e4
|
@ -15,17 +15,47 @@
|
||||||
package fusetesting
|
package fusetesting
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jacobsa/oglematchers"
|
"github.com/jacobsa/oglematchers"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Match *os.FileInfo values that specify an mtime equal to the given time. On
|
// Match os.FileInfo values that specify an mtime equal to the given time. On
|
||||||
// platforms where the Sys() method returns a struct containing an mtime, check
|
// platforms where the Sys() method returns a struct containing an mtime, check
|
||||||
// also that it matches.
|
// also that it matches.
|
||||||
func MtimeIs(expected time.Time) oglematchers.Matcher
|
func MtimeIs(expected time.Time) oglematchers.Matcher {
|
||||||
|
return oglematchers.NewMatcher(
|
||||||
|
func(c interface{}) error { return mtimeIs(c, expected) },
|
||||||
|
fmt.Sprintf("mtime is %v", expected))
|
||||||
|
}
|
||||||
|
|
||||||
// Match *os.FileInfo values that specify a file birth time equal to the given
|
func mtimeIs(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 ModTime().
|
||||||
|
if fi.ModTime() != expected {
|
||||||
|
d := fi.ModTime().Sub(expected)
|
||||||
|
return fmt.Errorf("which has mtime %v, off by %v", fi.ModTime(), d)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check Sys().
|
||||||
|
if sysMtime, ok := extractMtime(fi.Sys()); ok {
|
||||||
|
if sysMtime != expected {
|
||||||
|
d := sysMtime.Sub(expected)
|
||||||
|
return fmt.Errorf("which has Sys() mtime %v, off by %v", sysMtime, d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
Loading…
Reference in New Issue