From bbb6f94377644078e33daa364a16c5324a488bbd Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 21 Apr 2020 15:46:01 +0100 Subject: [PATCH] fstest: create AssertTimeEqualWithPrecision from CheckTimeEqualWithPrecision --- backend/http/http_internal_test.go | 3 +-- fs/operations/operations_test.go | 5 +---- fstest/fstest.go | 10 ++++++++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/backend/http/http_internal_test.go b/backend/http/http_internal_test.go index e89e58b7b..e62a02b98 100644 --- a/backend/http/http_internal_test.go +++ b/backend/http/http_internal_test.go @@ -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") diff --git a/fs/operations/operations_test.go b/fs/operations/operations_test.go index 3616a8db0..8b8cae348 100644 --- a/fs/operations/operations_test.go +++ b/fs/operations/operations_test.go @@ -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) } } diff --git a/fstest/fstest.go b/fstest/fstest.go index 81eefc828..ec5242895 100644 --- a/fstest/fstest.go +++ b/fstest/fstest.go @@ -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