mirror of
https://github.com/rclone/rclone.git
synced 2025-02-16 18:41:54 +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)
|
require.NoError(t, err)
|
||||||
tFile := fi.ModTime()
|
tFile := fi.ModTime()
|
||||||
|
|
||||||
dt, ok := fstest.CheckTimeEqualWithPrecision(tObj, tFile, time.Second)
|
fstest.AssertTimeEqualWithPrecision(t, o.Remote(), tFile, tObj, 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))
|
|
||||||
|
|
||||||
// check object not found
|
// check object not found
|
||||||
o, err = f.NewObject(context.Background(), "not found.txt")
|
o, err = f.NewObject(context.Background(), "not found.txt")
|
||||||
|
@ -166,10 +166,7 @@ func TestLsLong(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error parsing %q: %v", m, err)
|
t.Errorf("Error parsing %q: %v", m, err)
|
||||||
} else {
|
} else {
|
||||||
dt, ok := fstest.CheckTimeEqualWithPrecision(expected, modTime, precision)
|
fstest.AssertTimeEqualWithPrecision(t, filename, 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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,10 +117,16 @@ func CheckTimeEqualWithPrecision(t0, t1 time.Time, precision time.Duration) (tim
|
|||||||
return dt, true
|
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
|
// 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) {
|
func (i *Item) CheckModTime(t *testing.T, obj fs.Object, modTime time.Time, precision time.Duration) {
|
||||||
dt, ok := CheckTimeEqualWithPrecision(modTime, i.ModTime, precision)
|
AssertTimeEqualWithPrecision(t, obj.Remote(), i.ModTime, 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))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckHashes checks all the hashes the object supports are correct
|
// CheckHashes checks all the hashes the object supports are correct
|
||||||
|
Loading…
Reference in New Issue
Block a user