🧪 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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 410 additions and 410 deletions

View file

@ -75,8 +75,8 @@ func TestRcCopyfile(t *testing.T) {
defer r.Finalise()
file1 := r.WriteFile("file1", "file1 contents", t1)
r.Mkdir(context.Background(), r.Fremote)
fstest.CheckItems(t, r.Flocal, file1)
fstest.CheckItems(t, r.Fremote)
r.CheckLocalItems(t, file1)
r.CheckRemoteItems(t)
in := rc.Params{
"srcFs": r.LocalName,
@ -88,9 +88,9 @@ func TestRcCopyfile(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, rc.Params(nil), out)
fstest.CheckItems(t, r.Flocal, file1)
r.CheckLocalItems(t, file1)
file1.Path = "file1-renamed"
fstest.CheckItems(t, r.Fremote, file1)
r.CheckRemoteItems(t, file1)
}
// operations/copyurl: Copy the URL to the object
@ -100,7 +100,7 @@ func TestRcCopyurl(t *testing.T) {
contents := "file1 contents\n"
file1 := r.WriteFile("file1", contents, t1)
r.Mkdir(context.Background(), r.Fremote)
fstest.CheckItems(t, r.Fremote)
r.CheckRemoteItems(t)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte(contents))
@ -164,7 +164,7 @@ func TestRcDelete(t *testing.T) {
file1 := r.WriteObject(context.Background(), "small", "1234567890", t2) // 10 bytes
file2 := r.WriteObject(context.Background(), "medium", "------------------------------------------------------------", t1) // 60 bytes
file3 := r.WriteObject(context.Background(), "large", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", t1) // 100 bytes
fstest.CheckItems(t, r.Fremote, file1, file2, file3)
r.CheckRemoteItems(t, file1, file2, file3)
in := rc.Params{
"fs": r.FremoteName,
@ -173,7 +173,7 @@ func TestRcDelete(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, rc.Params(nil), out)
fstest.CheckItems(t, r.Fremote)
r.CheckRemoteItems(t)
}
// operations/deletefile: Remove the single file pointed to
@ -183,7 +183,7 @@ func TestRcDeletefile(t *testing.T) {
file1 := r.WriteObject(context.Background(), "small", "1234567890", t2) // 10 bytes
file2 := r.WriteObject(context.Background(), "medium", "------------------------------------------------------------", t1) // 60 bytes
fstest.CheckItems(t, r.Fremote, file1, file2)
r.CheckRemoteItems(t, file1, file2)
in := rc.Params{
"fs": r.FremoteName,
@ -193,7 +193,7 @@ func TestRcDeletefile(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, rc.Params(nil), out)
fstest.CheckItems(t, r.Fremote, file2)
r.CheckRemoteItems(t, file2)
}
// operations/list: List the given remote and path in JSON format.
@ -204,7 +204,7 @@ func TestRcList(t *testing.T) {
file1 := r.WriteObject(context.Background(), "a", "a", t1)
file2 := r.WriteObject(context.Background(), "subdir/b", "bb", t2)
fstest.CheckItems(t, r.Fremote, file1, file2)
r.CheckRemoteItems(t, file1, file2)
in := rc.Params{
"fs": r.FremoteName,
@ -268,7 +268,7 @@ func TestRcStat(t *testing.T) {
file1 := r.WriteObject(context.Background(), "subdir/a", "a", t1)
fstest.CheckItems(t, r.Fremote, file1)
r.CheckRemoteItems(t, file1)
fetch := func(t *testing.T, remotePath string) *operations.ListJSONItem {
in := rc.Params{
@ -340,8 +340,8 @@ func TestRcMovefile(t *testing.T) {
defer r.Finalise()
file1 := r.WriteFile("file1", "file1 contents", t1)
r.Mkdir(context.Background(), r.Fremote)
fstest.CheckItems(t, r.Flocal, file1)
fstest.CheckItems(t, r.Fremote)
r.CheckLocalItems(t, file1)
r.CheckRemoteItems(t)
in := rc.Params{
"srcFs": r.LocalName,
@ -353,9 +353,9 @@ func TestRcMovefile(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, rc.Params(nil), out)
fstest.CheckItems(t, r.Flocal)
r.CheckLocalItems(t)
file1.Path = "file1-renamed"
fstest.CheckItems(t, r.Fremote, file1)
r.CheckRemoteItems(t, file1)
}
// operations/purge: Remove a directory or container and all of its contents
@ -443,7 +443,7 @@ func TestRcSize(t *testing.T) {
file1 := r.WriteObject(context.Background(), "small", "1234567890", t2) // 10 bytes
file2 := r.WriteObject(context.Background(), "subdir/medium", "------------------------------------------------------------", t1) // 60 bytes
file3 := r.WriteObject(context.Background(), "subdir/subsubdir/large", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", t1) // 50 bytes
fstest.CheckItems(t, r.Fremote, file1, file2, file3)
r.CheckRemoteItems(t, file1, file2, file3)
in := rc.Params{
"fs": r.FremoteName,