1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-06 00:03:32 +00:00

🧪 fstest: fix time tests on Windows and add convenience methods to check local and remote fs with precision

Previously only the fs being checked on gets passed to
GetModifyWindow(). However, in most tests, the test files are
generated in the local fs and transferred to the remote fs. So the
local fs time precision has to be taken into account.

This meant that on Windows the time tests failed because the
local fs has a time precision of 100ns. Checking remote items uploaded
from local fs on Windows also requires a modify window of 100ns.
This commit is contained in:
database64128
2021-11-09 19:43:36 +08:00
committed by GitHub
parent 9beb0677e4
commit a7a8372976
20 changed files with 410 additions and 410 deletions

View File

@@ -55,6 +55,7 @@ type Run struct {
Flocal fs.Fs
Fremote fs.Fs
FremoteName string
Precision time.Duration
cleanRemote func()
mkdir map[string]bool // whether the remote has been made yet for the fs name
Logf, Fatalf func(text string, args ...interface{})
@@ -107,6 +108,9 @@ func newRun() *Run {
if err != nil {
r.Fatalf("Failed to make %q: %v", r.LocalName, err)
}
r.Precision = fs.GetModifyWindow(context.Background(), r.Fremote, r.Flocal)
return r
}
@@ -326,6 +330,38 @@ func (r *Run) CheckWithDuplicates(t *testing.T, items ...Item) {
assert.Equal(t, want, got)
}
// CheckLocalItems checks the local fs with proper precision
// to see if it has the expected items.
func (r *Run) CheckLocalItems(t *testing.T, items ...Item) {
CheckItemsWithPrecision(t, r.Flocal, r.Precision, items...)
}
// CheckRemoteItems checks the remote fs with proper precision
// to see if it has the expected items.
func (r *Run) CheckRemoteItems(t *testing.T, items ...Item) {
CheckItemsWithPrecision(t, r.Fremote, r.Precision, items...)
}
// CheckLocalListing checks the local fs with proper precision
// to see if it has the expected contents.
//
// If expectedDirs is non nil then we check those too. Note that no
// directories returned is also OK as some remotes don't return
// directories.
func (r *Run) CheckLocalListing(t *testing.T, items []Item, expectedDirs []string) {
CheckListingWithPrecision(t, r.Flocal, items, expectedDirs, r.Precision)
}
// CheckRemoteListing checks the remote fs with proper precision
// to see if it has the expected contents.
//
// If expectedDirs is non nil then we check those too. Note that no
// directories returned is also OK as some remotes don't return
// directories.
func (r *Run) CheckRemoteListing(t *testing.T, items []Item, expectedDirs []string) {
CheckListingWithPrecision(t, r.Fremote, items, expectedDirs, r.Precision)
}
// Clean the temporary directory
func (r *Run) cleanTempDir() {
err := os.RemoveAll(r.LocalName)