mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 09:04:52 +01:00
fstest: create AssertTimeEqualWithPrecision from CheckTimeEqualWithPrecision
This commit is contained in:
parent
3f654dac37
commit
bbb6f94377
@ -166,8 +166,7 @@ func TestNewObject(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
tFile := fi.ModTime()
|
||||
|
||||
dt, ok := fstest.CheckTimeEqualWithPrecision(tObj, tFile, time.Second)
|
||||
assert.True(t, ok, fmt.Sprintf("%s: Modification time difference too big |%s| > %s (%s vs %s) (precision %s)", o.Remote(), dt, time.Second, tObj, tFile, time.Second))
|
||||
fstest.AssertTimeEqualWithPrecision(t, o.Remote(), tFile, tObj, time.Second)
|
||||
|
||||
// check object not found
|
||||
o, err = f.NewObject(context.Background(), "not found.txt")
|
||||
|
@ -166,10 +166,7 @@ func TestLsLong(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Error parsing %q: %v", m, err)
|
||||
} else {
|
||||
dt, ok := fstest.CheckTimeEqualWithPrecision(expected, modTime, precision)
|
||||
if !ok {
|
||||
t.Errorf("%s: Modification time difference too big |%s| > %s (%s vs %s) (precision %s)", filename, dt, precision, modTime, expected, precision)
|
||||
}
|
||||
fstest.AssertTimeEqualWithPrecision(t, filename, expected, modTime, precision)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,10 +117,16 @@ func CheckTimeEqualWithPrecision(t0, t1 time.Time, precision time.Duration) (tim
|
||||
return dt, true
|
||||
}
|
||||
|
||||
// AssertTimeEqualWithPrecision checks that want is within precision
|
||||
// of got, asserting that with t and logging remote
|
||||
func AssertTimeEqualWithPrecision(t *testing.T, remote string, want, got time.Time, precision time.Duration) {
|
||||
dt, ok := CheckTimeEqualWithPrecision(want, got, precision)
|
||||
assert.True(t, ok, fmt.Sprintf("%s: Modification time difference too big |%s| > %s (want %s vs got %s) (precision %s)", remote, dt, precision, want, got, precision))
|
||||
}
|
||||
|
||||
// CheckModTime checks the mod time to the given precision
|
||||
func (i *Item) CheckModTime(t *testing.T, obj fs.Object, modTime time.Time, precision time.Duration) {
|
||||
dt, ok := CheckTimeEqualWithPrecision(modTime, i.ModTime, precision)
|
||||
assert.True(t, ok, fmt.Sprintf("%s: Modification time difference too big |%s| > %s (%s vs %s) (precision %s)", obj.Remote(), dt, precision, modTime, i.ModTime, precision))
|
||||
AssertTimeEqualWithPrecision(t, obj.Remote(), i.ModTime, modTime, precision)
|
||||
}
|
||||
|
||||
// CheckHashes checks all the hashes the object supports are correct
|
||||
|
Loading…
Reference in New Issue
Block a user