🧪 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

@ -93,16 +93,16 @@ func TestSymlink(t *testing.T) {
file2d := fstest.NewItem("symlink.txt", "hello", modTime1) file2d := fstest.NewItem("symlink.txt", "hello", modTime1)
// Check with no symlink flags // Check with no symlink flags
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
fstest.CheckItems(t, r.Fremote) r.CheckRemoteItems(t)
// Set fs into "-L" mode // Set fs into "-L" mode
f.opt.FollowSymlinks = true f.opt.FollowSymlinks = true
f.opt.TranslateSymlinks = false f.opt.TranslateSymlinks = false
f.lstat = os.Stat f.lstat = os.Stat
fstest.CheckItems(t, r.Flocal, file1, file2d) r.CheckLocalItems(t, file1, file2d)
fstest.CheckItems(t, r.Fremote) r.CheckRemoteItems(t)
// Set fs into "-l" mode // Set fs into "-l" mode
f.opt.FollowSymlinks = false f.opt.FollowSymlinks = false
@ -111,7 +111,7 @@ func TestSymlink(t *testing.T) {
fstest.CheckListingWithPrecision(t, r.Flocal, []fstest.Item{file1, file2}, nil, fs.ModTimeNotSupported) fstest.CheckListingWithPrecision(t, r.Flocal, []fstest.Item{file1, file2}, nil, fs.ModTimeNotSupported)
if haveLChtimes { if haveLChtimes {
fstest.CheckItems(t, r.Flocal, file1, file2) r.CheckLocalItems(t, file1, file2)
} }
// Create a symlink // Create a symlink
@ -119,7 +119,7 @@ func TestSymlink(t *testing.T) {
file3 := r.WriteObjectTo(ctx, r.Flocal, "symlink2.txt"+linkSuffix, "file.txt", modTime3, false) file3 := r.WriteObjectTo(ctx, r.Flocal, "symlink2.txt"+linkSuffix, "file.txt", modTime3, false)
fstest.CheckListingWithPrecision(t, r.Flocal, []fstest.Item{file1, file2, file3}, nil, fs.ModTimeNotSupported) fstest.CheckListingWithPrecision(t, r.Flocal, []fstest.Item{file1, file2, file3}, nil, fs.ModTimeNotSupported)
if haveLChtimes { if haveLChtimes {
fstest.CheckItems(t, r.Flocal, file1, file2, file3) r.CheckLocalItems(t, file1, file2, file3)
} }
// Check it got the correct contents // Check it got the correct contents

View File

@ -77,7 +77,7 @@ func TestTouchUpdateTimestamp(t *testing.T) {
srcFileName := "a" srcFileName := "a"
content := "aaa" content := "aaa"
file1 := r.WriteObject(context.Background(), srcFileName, content, t1) file1 := r.WriteObject(context.Background(), srcFileName, content, t1)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
timeAsArgument = "121212" timeAsArgument = "121212"
err := Touch(context.Background(), r.Fremote, "a") err := Touch(context.Background(), r.Fremote, "a")
@ -92,7 +92,7 @@ func TestTouchUpdateTimestampWithCFlag(t *testing.T) {
srcFileName := "a" srcFileName := "a"
content := "aaa" content := "aaa"
file1 := r.WriteObject(context.Background(), srcFileName, content, t1) file1 := r.WriteObject(context.Background(), srcFileName, content, t1)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
notCreateNewFile = true notCreateNewFile = true
timeAsArgument = "121212" timeAsArgument = "121212"

View File

@ -99,8 +99,8 @@ func testCheck(t *testing.T, checkFunction func(ctx context.Context, opt *operat
} }
file1 := r.WriteBoth(ctx, "rutabaga", "is tasty", t3) file1 := r.WriteBoth(ctx, "rutabaga", "is tasty", t3)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
check(1, 0, 1, false, map[string]string{ check(1, 0, 1, false, map[string]string{
"combined": "= rutabaga\n", "combined": "= rutabaga\n",
"missingonsrc": "", "missingonsrc": "",
@ -111,7 +111,7 @@ func testCheck(t *testing.T, checkFunction func(ctx context.Context, opt *operat
}) })
file2 := r.WriteFile("potato2", "------------------------------------------------------------", t1) file2 := r.WriteFile("potato2", "------------------------------------------------------------", t1)
fstest.CheckItems(t, r.Flocal, file1, file2) r.CheckLocalItems(t, file1, file2)
check(2, 1, 1, false, map[string]string{ check(2, 1, 1, false, map[string]string{
"combined": "+ potato2\n= rutabaga\n", "combined": "+ potato2\n= rutabaga\n",
"missingonsrc": "", "missingonsrc": "",
@ -122,7 +122,7 @@ func testCheck(t *testing.T, checkFunction func(ctx context.Context, opt *operat
}) })
file3 := r.WriteObject(ctx, "empty space", "-", t2) file3 := r.WriteObject(ctx, "empty space", "-", t2)
fstest.CheckItems(t, r.Fremote, file1, file3) r.CheckRemoteItems(t, file1, file3)
check(3, 2, 1, false, map[string]string{ check(3, 2, 1, false, map[string]string{
"combined": "- empty space\n+ potato2\n= rutabaga\n", "combined": "- empty space\n+ potato2\n= rutabaga\n",
"missingonsrc": "empty space\n", "missingonsrc": "empty space\n",
@ -138,7 +138,7 @@ func testCheck(t *testing.T, checkFunction func(ctx context.Context, opt *operat
} else { } else {
r.WriteObject(ctx, "potato2", "------------------------------------------------------------", t1) r.WriteObject(ctx, "potato2", "------------------------------------------------------------", t1)
} }
fstest.CheckItems(t, r.Fremote, file1, file2r, file3) r.CheckRemoteItems(t, file1, file2r, file3)
check(4, 1, 2, false, map[string]string{ check(4, 1, 2, false, map[string]string{
"combined": "- empty space\n= potato2\n= rutabaga\n", "combined": "- empty space\n= potato2\n= rutabaga\n",
"missingonsrc": "empty space\n", "missingonsrc": "empty space\n",
@ -150,7 +150,7 @@ func testCheck(t *testing.T, checkFunction func(ctx context.Context, opt *operat
file3r := file3 file3r := file3
file3l := r.WriteFile("empty space", "DIFFER", t2) file3l := r.WriteFile("empty space", "DIFFER", t2)
fstest.CheckItems(t, r.Flocal, file1, file2, file3l) r.CheckLocalItems(t, file1, file2, file3l)
check(5, 1, 3, false, map[string]string{ check(5, 1, 3, false, map[string]string{
"combined": "* empty space\n= potato2\n= rutabaga\n", "combined": "* empty space\n= potato2\n= rutabaga\n",
"missingonsrc": "", "missingonsrc": "",
@ -161,7 +161,7 @@ func testCheck(t *testing.T, checkFunction func(ctx context.Context, opt *operat
}) })
file4 := r.WriteObject(ctx, "remotepotato", "------------------------------------------------------------", t1) file4 := r.WriteObject(ctx, "remotepotato", "------------------------------------------------------------", t1)
fstest.CheckItems(t, r.Fremote, file1, file2r, file3r, file4) r.CheckRemoteItems(t, file1, file2r, file3r, file4)
check(6, 2, 3, false, map[string]string{ check(6, 2, 3, false, map[string]string{
"combined": "* empty space\n= potato2\n= rutabaga\n- remotepotato\n", "combined": "* empty space\n= potato2\n= rutabaga\n- remotepotato\n",
"missingonsrc": "remotepotato\n", "missingonsrc": "remotepotato\n",
@ -440,7 +440,7 @@ func testCheckSum(t *testing.T, download bool) {
fcsums := makeSums(operations.HashSums{ fcsums := makeSums(operations.HashSums{
"banana": testDigest1, "banana": testDigest1,
}) })
fstest.CheckItems(t, r.Fremote, fcsums, file1) r.CheckRemoteItems(t, fcsums, file1)
check(1, 1, 0, wantType{ check(1, 1, 0, wantType{
"combined": "= banana\n", "combined": "= banana\n",
"missingonsrc": "", "missingonsrc": "",
@ -454,7 +454,7 @@ func testCheckSum(t *testing.T, download bool) {
fcsums = makeSums(operations.HashSums{ fcsums = makeSums(operations.HashSums{
"banana": testDigest1, "banana": testDigest1,
}) })
fstest.CheckItems(t, r.Fremote, fcsums, file1, file2) r.CheckRemoteItems(t, fcsums, file1, file2)
check(2, 2, 1, wantType{ check(2, 2, 1, wantType{
"combined": "- potato\n= banana\n", "combined": "- potato\n= banana\n",
"missingonsrc": "potato\n", "missingonsrc": "potato\n",
@ -468,7 +468,7 @@ func testCheckSum(t *testing.T, download bool) {
"banana": testDigest1, "banana": testDigest1,
"potato": testDigest2, "potato": testDigest2,
}) })
fstest.CheckItems(t, r.Fremote, fcsums, file1, file2) r.CheckRemoteItems(t, fcsums, file1, file2)
check(3, 2, 0, wantType{ check(3, 2, 0, wantType{
"combined": "= potato\n= banana\n", "combined": "= potato\n= banana\n",
"missingonsrc": "", "missingonsrc": "",
@ -482,7 +482,7 @@ func testCheckSum(t *testing.T, download bool) {
"banana": testDigest2, "banana": testDigest2,
"potato": testDigest2, "potato": testDigest2,
}) })
fstest.CheckItems(t, r.Fremote, fcsums, file1, file2) r.CheckRemoteItems(t, fcsums, file1, file2)
check(4, 2, 1, wantType{ check(4, 2, 1, wantType{
"combined": "* banana\n= potato\n", "combined": "* banana\n= potato\n",
"missingonsrc": "", "missingonsrc": "",
@ -497,7 +497,7 @@ func testCheckSum(t *testing.T, download bool) {
"potato": testDigest2, "potato": testDigest2,
"orange": testDigest2, "orange": testDigest2,
}) })
fstest.CheckItems(t, r.Fremote, fcsums, file1, file2) r.CheckRemoteItems(t, fcsums, file1, file2)
check(5, 2, 1, wantType{ check(5, 2, 1, wantType{
"combined": "+ orange\n= potato\n= banana\n", "combined": "+ orange\n= potato\n= banana\n",
"missingonsrc": "", "missingonsrc": "",
@ -512,7 +512,7 @@ func testCheckSum(t *testing.T, download bool) {
"potato": testDigest1, "potato": testDigest1,
"orange": testDigest2, "orange": testDigest2,
}) })
fstest.CheckItems(t, r.Fremote, fcsums, file1, file2) r.CheckRemoteItems(t, fcsums, file1, file2)
check(6, 2, 2, wantType{ check(6, 2, 2, wantType{
"combined": "+ orange\n* potato\n= banana\n", "combined": "+ orange\n* potato\n= banana\n",
"missingonsrc": "", "missingonsrc": "",
@ -529,7 +529,7 @@ func testCheckSum(t *testing.T, download bool) {
"banana": testDigest1Upper, "banana": testDigest1Upper,
"potato": testDigest2Mixed, "potato": testDigest2Mixed,
}) })
fstest.CheckItems(t, r.Fremote, fcsums, file1, file2) r.CheckRemoteItems(t, fcsums, file1, file2)
check(7, 2, 0, wantType{ check(7, 2, 0, wantType{
"combined": "= banana\n= potato\n", "combined": "= banana\n= potato\n",
"missingonsrc": "", "missingonsrc": "",

View File

@ -57,7 +57,7 @@ func TestDeduplicateInteractive(t *testing.T) {
err := operations.Deduplicate(context.Background(), r.Fremote, operations.DeduplicateInteractive, false) err := operations.Deduplicate(context.Background(), r.Fremote, operations.DeduplicateInteractive, false)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
} }
func TestDeduplicateSkip(t *testing.T) { func TestDeduplicateSkip(t *testing.T) {
@ -148,7 +148,7 @@ func TestDeduplicateNewest(t *testing.T) {
err := operations.Deduplicate(context.Background(), r.Fremote, operations.DeduplicateNewest, false) err := operations.Deduplicate(context.Background(), r.Fremote, operations.DeduplicateNewest, false)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Fremote, file3) r.CheckRemoteItems(t, file3)
} }
func TestDeduplicateNewestByHash(t *testing.T) { func TestDeduplicateNewestByHash(t *testing.T) {
@ -162,12 +162,12 @@ func TestDeduplicateNewestByHash(t *testing.T) {
file2 := r.WriteObject(context.Background(), "also/one", contents, t2) file2 := r.WriteObject(context.Background(), "also/one", contents, t2)
file3 := r.WriteObject(context.Background(), "another", contents, t3) file3 := r.WriteObject(context.Background(), "another", contents, t3)
file4 := r.WriteObject(context.Background(), "not-one", "stuff", t3) file4 := r.WriteObject(context.Background(), "not-one", "stuff", t3)
fstest.CheckItems(t, r.Fremote, file1, file2, file3, file4) r.CheckRemoteItems(t, file1, file2, file3, file4)
err := operations.Deduplicate(context.Background(), r.Fremote, operations.DeduplicateNewest, true) err := operations.Deduplicate(context.Background(), r.Fremote, operations.DeduplicateNewest, true)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Fremote, file3, file4) r.CheckRemoteItems(t, file3, file4)
} }
func TestDeduplicateOldest(t *testing.T) { func TestDeduplicateOldest(t *testing.T) {
@ -183,7 +183,7 @@ func TestDeduplicateOldest(t *testing.T) {
err := operations.Deduplicate(context.Background(), r.Fremote, operations.DeduplicateOldest, false) err := operations.Deduplicate(context.Background(), r.Fremote, operations.DeduplicateOldest, false)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
} }
func TestDeduplicateLargest(t *testing.T) { func TestDeduplicateLargest(t *testing.T) {
@ -199,7 +199,7 @@ func TestDeduplicateLargest(t *testing.T) {
err := operations.Deduplicate(context.Background(), r.Fremote, operations.DeduplicateLargest, false) err := operations.Deduplicate(context.Background(), r.Fremote, operations.DeduplicateLargest, false)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Fremote, file3) r.CheckRemoteItems(t, file3)
} }
func TestDeduplicateSmallest(t *testing.T) { func TestDeduplicateSmallest(t *testing.T) {
@ -215,7 +215,7 @@ func TestDeduplicateSmallest(t *testing.T) {
err := operations.Deduplicate(context.Background(), r.Fremote, operations.DeduplicateSmallest, false) err := operations.Deduplicate(context.Background(), r.Fremote, operations.DeduplicateSmallest, false)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
} }
func TestDeduplicateRename(t *testing.T) { func TestDeduplicateRename(t *testing.T) {
@ -281,7 +281,7 @@ func TestMergeDirs(t *testing.T) {
file2.Path = "dupe1/two.txt" file2.Path = "dupe1/two.txt"
file3.Path = "dupe1/three.txt" file3.Path = "dupe1/three.txt"
fstest.CheckItems(t, r.Fremote, file1, file2, file3) r.CheckRemoteItems(t, file1, file2, file3)
objs, dirs, err = walk.GetAll(context.Background(), r.Fremote, "", true, 1) objs, dirs, err = walk.GetAll(context.Background(), r.Fremote, "", true, 1)
require.NoError(t, err) require.NoError(t, err)

View File

@ -34,7 +34,7 @@ func TestListDirSorted(t *testing.T) {
r.WriteObject(context.Background(), "sub dir/ignore dir/should be ignored", "to ignore", t1), r.WriteObject(context.Background(), "sub dir/ignore dir/should be ignored", "to ignore", t1),
r.WriteObject(context.Background(), "sub dir/sub sub dir/hello world3", "hello world", t1), r.WriteObject(context.Background(), "sub dir/sub sub dir/hello world3", "hello world", t1),
} }
fstest.CheckItems(t, r.Fremote, files...) r.CheckRemoteItems(t, files...)
var items fs.DirEntries var items fs.DirEntries
var err error var err error

View File

@ -41,7 +41,7 @@ func TestListJSON(t *testing.T) {
file1 := r.WriteBoth(ctx, "file1", "file1", t1) file1 := r.WriteBoth(ctx, "file1", "file1", t1)
file2 := r.WriteBoth(ctx, "sub/file2", "sub/file2", t2) file2 := r.WriteBoth(ctx, "sub/file2", "sub/file2", t2)
fstest.CheckItems(t, r.Fremote, file1, file2) r.CheckRemoteItems(t, file1, file2)
precision := fs.GetModifyWindow(ctx, r.Fremote) precision := fs.GetModifyWindow(ctx, r.Fremote)
for _, test := range []struct { for _, test := range []struct {
@ -236,7 +236,7 @@ func TestStatJSON(t *testing.T) {
file1 := r.WriteBoth(ctx, "file1", "file1", t1) file1 := r.WriteBoth(ctx, "file1", "file1", t1)
file2 := r.WriteBoth(ctx, "sub/file2", "sub/file2", t2) file2 := r.WriteBoth(ctx, "sub/file2", "sub/file2", t2)
fstest.CheckItems(t, r.Fremote, file1, file2) r.CheckRemoteItems(t, file1, file2)
precision := fs.GetModifyWindow(ctx, r.Fremote) precision := fs.GetModifyWindow(ctx, r.Fremote)
for _, test := range []struct { for _, test := range []struct {

View File

@ -125,8 +125,8 @@ func TestMultithreadCopy(t *testing.T) {
contents := random.String(test.size) contents := random.String(test.size)
t1 := fstest.Time("2001-02-03T04:05:06.499999999Z") t1 := fstest.Time("2001-02-03T04:05:06.499999999Z")
file1 := r.WriteObject(ctx, "file1", contents, t1) file1 := r.WriteObject(ctx, "file1", contents, t1)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
fstest.CheckItems(t, r.Flocal) r.CheckLocalItems(t)
src, err := r.Fremote.NewObject(ctx, "file1") src, err := r.Fremote.NewObject(ctx, "file1")
require.NoError(t, err) require.NoError(t, err)

View File

@ -80,7 +80,7 @@ func TestLsd(t *testing.T) {
defer r.Finalise() defer r.Finalise()
file1 := r.WriteObject(ctx, "sub dir/hello world", "hello world", t1) file1 := r.WriteObject(ctx, "sub dir/hello world", "hello world", t1)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
var buf bytes.Buffer var buf bytes.Buffer
err := operations.ListDir(ctx, r.Fremote, &buf) err := operations.ListDir(ctx, r.Fremote, &buf)
@ -96,7 +96,7 @@ func TestLs(t *testing.T) {
file1 := r.WriteBoth(ctx, "potato2", "------------------------------------------------------------", t1) file1 := r.WriteBoth(ctx, "potato2", "------------------------------------------------------------", t1)
file2 := r.WriteBoth(ctx, "empty space", "-", t2) file2 := r.WriteBoth(ctx, "empty space", "-", t2)
fstest.CheckItems(t, r.Fremote, file1, file2) r.CheckRemoteItems(t, file1, file2)
var buf bytes.Buffer var buf bytes.Buffer
err := operations.List(ctx, r.Fremote, &buf) err := operations.List(ctx, r.Fremote, &buf)
@ -114,7 +114,7 @@ func TestLsWithFilesFrom(t *testing.T) {
file1 := r.WriteBoth(ctx, "potato2", "------------------------------------------------------------", t1) file1 := r.WriteBoth(ctx, "potato2", "------------------------------------------------------------", t1)
file2 := r.WriteBoth(ctx, "empty space", "-", t2) file2 := r.WriteBoth(ctx, "empty space", "-", t2)
fstest.CheckItems(t, r.Fremote, file1, file2) r.CheckRemoteItems(t, file1, file2)
// Set the --files-from equivalent // Set the --files-from equivalent
f, err := filter.NewFilter(nil) f, err := filter.NewFilter(nil)
@ -146,7 +146,7 @@ func TestLsLong(t *testing.T) {
file1 := r.WriteBoth(ctx, "potato2", "------------------------------------------------------------", t1) file1 := r.WriteBoth(ctx, "potato2", "------------------------------------------------------------", t1)
file2 := r.WriteBoth(ctx, "empty space", "-", t2) file2 := r.WriteBoth(ctx, "empty space", "-", t2)
fstest.CheckItems(t, r.Fremote, file1, file2) r.CheckRemoteItems(t, file1, file2)
var buf bytes.Buffer var buf bytes.Buffer
err := operations.ListLong(ctx, r.Fremote, &buf) err := operations.ListLong(ctx, r.Fremote, &buf)
@ -189,7 +189,7 @@ func TestHashSums(t *testing.T) {
file1 := r.WriteBoth(ctx, "potato2", "------------------------------------------------------------", t1) file1 := r.WriteBoth(ctx, "potato2", "------------------------------------------------------------", t1)
file2 := r.WriteBoth(ctx, "empty space", "-", t2) file2 := r.WriteBoth(ctx, "empty space", "-", t2)
fstest.CheckItems(t, r.Fremote, file1, file2) r.CheckRemoteItems(t, file1, file2)
hashes := r.Fremote.Hashes() hashes := r.Fremote.Hashes()
@ -350,7 +350,7 @@ func TestCount(t *testing.T) {
file2 := r.WriteBoth(ctx, "empty space", "-", t2) file2 := r.WriteBoth(ctx, "empty space", "-", t2)
file3 := r.WriteBoth(ctx, "sub dir/potato3", "hello", t2) file3 := r.WriteBoth(ctx, "sub dir/potato3", "hello", t2)
fstest.CheckItems(t, r.Fremote, file1, file2, file3) r.CheckRemoteItems(t, file1, file2, file3)
// Check the MaxDepth too // Check the MaxDepth too
ci.MaxDepth = 1 ci.MaxDepth = 1
@ -372,11 +372,11 @@ func TestDelete(t *testing.T) {
file1 := r.WriteObject(ctx, "small", "1234567890", t2) // 10 bytes file1 := r.WriteObject(ctx, "small", "1234567890", t2) // 10 bytes
file2 := r.WriteObject(ctx, "medium", "------------------------------------------------------------", t1) // 60 bytes file2 := r.WriteObject(ctx, "medium", "------------------------------------------------------------", t1) // 60 bytes
file3 := r.WriteObject(ctx, "large", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", t1) // 100 bytes file3 := r.WriteObject(ctx, "large", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", t1) // 100 bytes
fstest.CheckItems(t, r.Fremote, file1, file2, file3) r.CheckRemoteItems(t, file1, file2, file3)
err = operations.Delete(ctx, r.Fremote) err = operations.Delete(ctx, r.Fremote)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Fremote, file3) r.CheckRemoteItems(t, file3)
} }
func TestRetry(t *testing.T) { func TestRetry(t *testing.T) {
@ -413,7 +413,7 @@ func TestCat(t *testing.T) {
file1 := r.WriteBoth(ctx, "file1", "ABCDEFGHIJ", t1) file1 := r.WriteBoth(ctx, "file1", "ABCDEFGHIJ", t1)
file2 := r.WriteBoth(ctx, "file2", "012345678", t2) file2 := r.WriteBoth(ctx, "file2", "012345678", t2)
fstest.CheckItems(t, r.Fremote, file1, file2) r.CheckRemoteItems(t, file1, file2)
for _, test := range []struct { for _, test := range []struct {
offset int64 offset int64
@ -678,7 +678,7 @@ func TestCopyURL(t *testing.T) {
file1 := r.WriteFile("file1", contents, t1) file1 := r.WriteFile("file1", contents, t1)
file2 := r.WriteFile("file2", contents, t1) file2 := r.WriteFile("file2", contents, t1)
r.Mkdir(ctx, r.Fremote) r.Mkdir(ctx, r.Fremote)
fstest.CheckItems(t, r.Fremote) r.CheckRemoteItems(t)
// check when reading from regular HTTP server // check when reading from regular HTTP server
status := 0 status := 0
@ -773,28 +773,28 @@ func TestMoveFile(t *testing.T) {
defer r.Finalise() defer r.Finalise()
file1 := r.WriteFile("file1", "file1 contents", t1) file1 := r.WriteFile("file1", "file1 contents", t1)
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
file2 := file1 file2 := file1
file2.Path = "sub/file2" file2.Path = "sub/file2"
err := operations.MoveFile(ctx, r.Fremote, r.Flocal, file2.Path, file1.Path) err := operations.MoveFile(ctx, r.Fremote, r.Flocal, file2.Path, file1.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Flocal) r.CheckLocalItems(t)
fstest.CheckItems(t, r.Fremote, file2) r.CheckRemoteItems(t, file2)
r.WriteFile("file1", "file1 contents", t1) r.WriteFile("file1", "file1 contents", t1)
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
err = operations.MoveFile(ctx, r.Fremote, r.Flocal, file2.Path, file1.Path) err = operations.MoveFile(ctx, r.Fremote, r.Flocal, file2.Path, file1.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Flocal) r.CheckLocalItems(t)
fstest.CheckItems(t, r.Fremote, file2) r.CheckRemoteItems(t, file2)
err = operations.MoveFile(ctx, r.Fremote, r.Fremote, file2.Path, file2.Path) err = operations.MoveFile(ctx, r.Fremote, r.Fremote, file2.Path, file2.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Flocal) r.CheckLocalItems(t)
fstest.CheckItems(t, r.Fremote, file2) r.CheckRemoteItems(t, file2)
} }
func TestMoveFileWithIgnoreExisting(t *testing.T) { func TestMoveFileWithIgnoreExisting(t *testing.T) {
@ -803,24 +803,24 @@ func TestMoveFileWithIgnoreExisting(t *testing.T) {
r := fstest.NewRun(t) r := fstest.NewRun(t)
defer r.Finalise() defer r.Finalise()
file1 := r.WriteFile("file1", "file1 contents", t1) file1 := r.WriteFile("file1", "file1 contents", t1)
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
ci.IgnoreExisting = true ci.IgnoreExisting = true
err := operations.MoveFile(ctx, r.Fremote, r.Flocal, file1.Path, file1.Path) err := operations.MoveFile(ctx, r.Fremote, r.Flocal, file1.Path, file1.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Flocal) r.CheckLocalItems(t)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
// Recreate file with updated content // Recreate file with updated content
file1b := r.WriteFile("file1", "file1 modified", t2) file1b := r.WriteFile("file1", "file1 modified", t2)
fstest.CheckItems(t, r.Flocal, file1b) r.CheckLocalItems(t, file1b)
// Ensure modified file did not transfer and was not deleted // Ensure modified file did not transfer and was not deleted
err = operations.MoveFile(ctx, r.Fremote, r.Flocal, file1.Path, file1b.Path) err = operations.MoveFile(ctx, r.Fremote, r.Flocal, file1.Path, file1b.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Flocal, file1b) r.CheckLocalItems(t, file1b)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
} }
func TestCaseInsensitiveMoveFile(t *testing.T) { func TestCaseInsensitiveMoveFile(t *testing.T) {
@ -832,31 +832,31 @@ func TestCaseInsensitiveMoveFile(t *testing.T) {
} }
file1 := r.WriteFile("file1", "file1 contents", t1) file1 := r.WriteFile("file1", "file1 contents", t1)
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
file2 := file1 file2 := file1
file2.Path = "sub/file2" file2.Path = "sub/file2"
err := operations.MoveFile(ctx, r.Fremote, r.Flocal, file2.Path, file1.Path) err := operations.MoveFile(ctx, r.Fremote, r.Flocal, file2.Path, file1.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Flocal) r.CheckLocalItems(t)
fstest.CheckItems(t, r.Fremote, file2) r.CheckRemoteItems(t, file2)
r.WriteFile("file1", "file1 contents", t1) r.WriteFile("file1", "file1 contents", t1)
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
err = operations.MoveFile(ctx, r.Fremote, r.Flocal, file2.Path, file1.Path) err = operations.MoveFile(ctx, r.Fremote, r.Flocal, file2.Path, file1.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Flocal) r.CheckLocalItems(t)
fstest.CheckItems(t, r.Fremote, file2) r.CheckRemoteItems(t, file2)
file2Capitalized := file2 file2Capitalized := file2
file2Capitalized.Path = "sub/File2" file2Capitalized.Path = "sub/File2"
err = operations.MoveFile(ctx, r.Fremote, r.Fremote, file2Capitalized.Path, file2.Path) err = operations.MoveFile(ctx, r.Fremote, r.Fremote, file2Capitalized.Path, file2.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Flocal) r.CheckLocalItems(t)
fstest.CheckItems(t, r.Fremote, file2Capitalized) r.CheckRemoteItems(t, file2Capitalized)
} }
func TestMoveFileBackupDir(t *testing.T) { func TestMoveFileBackupDir(t *testing.T) {
@ -871,16 +871,16 @@ func TestMoveFileBackupDir(t *testing.T) {
ci.BackupDir = r.FremoteName + "/backup" ci.BackupDir = r.FremoteName + "/backup"
file1 := r.WriteFile("dst/file1", "file1 contents", t1) file1 := r.WriteFile("dst/file1", "file1 contents", t1)
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
file1old := r.WriteObject(ctx, "dst/file1", "file1 contents old", t1) file1old := r.WriteObject(ctx, "dst/file1", "file1 contents old", t1)
fstest.CheckItems(t, r.Fremote, file1old) r.CheckRemoteItems(t, file1old)
err := operations.MoveFile(ctx, r.Fremote, r.Flocal, file1.Path, file1.Path) err := operations.MoveFile(ctx, r.Fremote, r.Flocal, file1.Path, file1.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Flocal) r.CheckLocalItems(t)
file1old.Path = "backup/dst/file1" file1old.Path = "backup/dst/file1"
fstest.CheckItems(t, r.Fremote, file1old, file1) r.CheckRemoteItems(t, file1old, file1)
} }
func TestCopyFile(t *testing.T) { func TestCopyFile(t *testing.T) {
@ -889,25 +889,25 @@ func TestCopyFile(t *testing.T) {
defer r.Finalise() defer r.Finalise()
file1 := r.WriteFile("file1", "file1 contents", t1) file1 := r.WriteFile("file1", "file1 contents", t1)
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
file2 := file1 file2 := file1
file2.Path = "sub/file2" file2.Path = "sub/file2"
err := operations.CopyFile(ctx, r.Fremote, r.Flocal, file2.Path, file1.Path) err := operations.CopyFile(ctx, r.Fremote, r.Flocal, file2.Path, file1.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
fstest.CheckItems(t, r.Fremote, file2) r.CheckRemoteItems(t, file2)
err = operations.CopyFile(ctx, r.Fremote, r.Flocal, file2.Path, file1.Path) err = operations.CopyFile(ctx, r.Fremote, r.Flocal, file2.Path, file1.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
fstest.CheckItems(t, r.Fremote, file2) r.CheckRemoteItems(t, file2)
err = operations.CopyFile(ctx, r.Fremote, r.Fremote, file2.Path, file2.Path) err = operations.CopyFile(ctx, r.Fremote, r.Fremote, file2.Path, file2.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
fstest.CheckItems(t, r.Fremote, file2) r.CheckRemoteItems(t, file2)
} }
func TestCopyFileBackupDir(t *testing.T) { func TestCopyFileBackupDir(t *testing.T) {
@ -922,16 +922,16 @@ func TestCopyFileBackupDir(t *testing.T) {
ci.BackupDir = r.FremoteName + "/backup" ci.BackupDir = r.FremoteName + "/backup"
file1 := r.WriteFile("dst/file1", "file1 contents", t1) file1 := r.WriteFile("dst/file1", "file1 contents", t1)
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
file1old := r.WriteObject(ctx, "dst/file1", "file1 contents old", t1) file1old := r.WriteObject(ctx, "dst/file1", "file1 contents old", t1)
fstest.CheckItems(t, r.Fremote, file1old) r.CheckRemoteItems(t, file1old)
err := operations.CopyFile(ctx, r.Fremote, r.Flocal, file1.Path, file1.Path) err := operations.CopyFile(ctx, r.Fremote, r.Flocal, file1.Path, file1.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
file1old.Path = "backup/dst/file1" file1old.Path = "backup/dst/file1"
fstest.CheckItems(t, r.Fremote, file1old, file1) r.CheckRemoteItems(t, file1old, file1)
} }
// Test with CompareDest set // Test with CompareDest set
@ -947,7 +947,7 @@ func TestCopyFileCompareDest(t *testing.T) {
// check empty dest, empty compare // check empty dest, empty compare
file1 := r.WriteFile("one", "one", t1) file1 := r.WriteFile("one", "one", t1)
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
err = operations.CopyFile(ctx, fdst, r.Flocal, file1.Path, file1.Path) err = operations.CopyFile(ctx, fdst, r.Flocal, file1.Path, file1.Path)
require.NoError(t, err) require.NoError(t, err)
@ -955,12 +955,12 @@ func TestCopyFileCompareDest(t *testing.T) {
file1dst := file1 file1dst := file1
file1dst.Path = "dst/one" file1dst.Path = "dst/one"
fstest.CheckItems(t, r.Fremote, file1dst) r.CheckRemoteItems(t, file1dst)
// check old dest, empty compare // check old dest, empty compare
file1b := r.WriteFile("one", "onet2", t2) file1b := r.WriteFile("one", "onet2", t2)
fstest.CheckItems(t, r.Fremote, file1dst) r.CheckRemoteItems(t, file1dst)
fstest.CheckItems(t, r.Flocal, file1b) r.CheckLocalItems(t, file1b)
err = operations.CopyFile(ctx, fdst, r.Flocal, file1b.Path, file1b.Path) err = operations.CopyFile(ctx, fdst, r.Flocal, file1b.Path, file1b.Path)
require.NoError(t, err) require.NoError(t, err)
@ -968,41 +968,41 @@ func TestCopyFileCompareDest(t *testing.T) {
file1bdst := file1b file1bdst := file1b
file1bdst.Path = "dst/one" file1bdst.Path = "dst/one"
fstest.CheckItems(t, r.Fremote, file1bdst) r.CheckRemoteItems(t, file1bdst)
// check old dest, new compare // check old dest, new compare
file3 := r.WriteObject(ctx, "dst/one", "one", t1) file3 := r.WriteObject(ctx, "dst/one", "one", t1)
file2 := r.WriteObject(ctx, "CompareDest/one", "onet2", t2) file2 := r.WriteObject(ctx, "CompareDest/one", "onet2", t2)
file1c := r.WriteFile("one", "onet2", t2) file1c := r.WriteFile("one", "onet2", t2)
fstest.CheckItems(t, r.Fremote, file2, file3) r.CheckRemoteItems(t, file2, file3)
fstest.CheckItems(t, r.Flocal, file1c) r.CheckLocalItems(t, file1c)
err = operations.CopyFile(ctx, fdst, r.Flocal, file1c.Path, file1c.Path) err = operations.CopyFile(ctx, fdst, r.Flocal, file1c.Path, file1c.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Fremote, file2, file3) r.CheckRemoteItems(t, file2, file3)
// check empty dest, new compare // check empty dest, new compare
file4 := r.WriteObject(ctx, "CompareDest/two", "two", t2) file4 := r.WriteObject(ctx, "CompareDest/two", "two", t2)
file5 := r.WriteFile("two", "two", t2) file5 := r.WriteFile("two", "two", t2)
fstest.CheckItems(t, r.Fremote, file2, file3, file4) r.CheckRemoteItems(t, file2, file3, file4)
fstest.CheckItems(t, r.Flocal, file1c, file5) r.CheckLocalItems(t, file1c, file5)
err = operations.CopyFile(ctx, fdst, r.Flocal, file5.Path, file5.Path) err = operations.CopyFile(ctx, fdst, r.Flocal, file5.Path, file5.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Fremote, file2, file3, file4) r.CheckRemoteItems(t, file2, file3, file4)
// check new dest, new compare // check new dest, new compare
err = operations.CopyFile(ctx, fdst, r.Flocal, file5.Path, file5.Path) err = operations.CopyFile(ctx, fdst, r.Flocal, file5.Path, file5.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Fremote, file2, file3, file4) r.CheckRemoteItems(t, file2, file3, file4)
// check empty dest, old compare // check empty dest, old compare
file5b := r.WriteFile("two", "twot3", t3) file5b := r.WriteFile("two", "twot3", t3)
fstest.CheckItems(t, r.Fremote, file2, file3, file4) r.CheckRemoteItems(t, file2, file3, file4)
fstest.CheckItems(t, r.Flocal, file1c, file5b) r.CheckLocalItems(t, file1c, file5b)
err = operations.CopyFile(ctx, fdst, r.Flocal, file5b.Path, file5b.Path) err = operations.CopyFile(ctx, fdst, r.Flocal, file5b.Path, file5b.Path)
require.NoError(t, err) require.NoError(t, err)
@ -1010,7 +1010,7 @@ func TestCopyFileCompareDest(t *testing.T) {
file5bdst := file5b file5bdst := file5b
file5bdst.Path = "dst/two" file5bdst.Path = "dst/two"
fstest.CheckItems(t, r.Fremote, file2, file3, file4, file5bdst) r.CheckRemoteItems(t, file2, file3, file4, file5bdst)
} }
// Test with CopyDest set // Test with CopyDest set
@ -1031,7 +1031,7 @@ func TestCopyFileCopyDest(t *testing.T) {
// check empty dest, empty copy // check empty dest, empty copy
file1 := r.WriteFile("one", "one", t1) file1 := r.WriteFile("one", "one", t1)
fstest.CheckItems(t, r.Flocal, file1) r.CheckLocalItems(t, file1)
err = operations.CopyFile(ctx, fdst, r.Flocal, file1.Path, file1.Path) err = operations.CopyFile(ctx, fdst, r.Flocal, file1.Path, file1.Path)
require.NoError(t, err) require.NoError(t, err)
@ -1039,12 +1039,12 @@ func TestCopyFileCopyDest(t *testing.T) {
file1dst := file1 file1dst := file1
file1dst.Path = "dst/one" file1dst.Path = "dst/one"
fstest.CheckItems(t, r.Fremote, file1dst) r.CheckRemoteItems(t, file1dst)
// check old dest, empty copy // check old dest, empty copy
file1b := r.WriteFile("one", "onet2", t2) file1b := r.WriteFile("one", "onet2", t2)
fstest.CheckItems(t, r.Fremote, file1dst) r.CheckRemoteItems(t, file1dst)
fstest.CheckItems(t, r.Flocal, file1b) r.CheckLocalItems(t, file1b)
err = operations.CopyFile(ctx, fdst, r.Flocal, file1b.Path, file1b.Path) err = operations.CopyFile(ctx, fdst, r.Flocal, file1b.Path, file1b.Path)
require.NoError(t, err) require.NoError(t, err)
@ -1052,7 +1052,7 @@ func TestCopyFileCopyDest(t *testing.T) {
file1bdst := file1b file1bdst := file1b
file1bdst.Path = "dst/one" file1bdst.Path = "dst/one"
fstest.CheckItems(t, r.Fremote, file1bdst) r.CheckRemoteItems(t, file1bdst)
// check old dest, new copy, backup-dir // check old dest, new copy, backup-dir
@ -1061,8 +1061,8 @@ func TestCopyFileCopyDest(t *testing.T) {
file3 := r.WriteObject(ctx, "dst/one", "one", t1) file3 := r.WriteObject(ctx, "dst/one", "one", t1)
file2 := r.WriteObject(ctx, "CopyDest/one", "onet2", t2) file2 := r.WriteObject(ctx, "CopyDest/one", "onet2", t2)
file1c := r.WriteFile("one", "onet2", t2) file1c := r.WriteFile("one", "onet2", t2)
fstest.CheckItems(t, r.Fremote, file2, file3) r.CheckRemoteItems(t, file2, file3)
fstest.CheckItems(t, r.Flocal, file1c) r.CheckLocalItems(t, file1c)
err = operations.CopyFile(ctx, fdst, r.Flocal, file1c.Path, file1c.Path) err = operations.CopyFile(ctx, fdst, r.Flocal, file1c.Path, file1c.Path)
require.NoError(t, err) require.NoError(t, err)
@ -1071,14 +1071,14 @@ func TestCopyFileCopyDest(t *testing.T) {
file2dst.Path = "dst/one" file2dst.Path = "dst/one"
file3.Path = "BackupDir/one" file3.Path = "BackupDir/one"
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3) r.CheckRemoteItems(t, file2, file2dst, file3)
ci.BackupDir = "" ci.BackupDir = ""
// check empty dest, new copy // check empty dest, new copy
file4 := r.WriteObject(ctx, "CopyDest/two", "two", t2) file4 := r.WriteObject(ctx, "CopyDest/two", "two", t2)
file5 := r.WriteFile("two", "two", t2) file5 := r.WriteFile("two", "two", t2)
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4) r.CheckRemoteItems(t, file2, file2dst, file3, file4)
fstest.CheckItems(t, r.Flocal, file1c, file5) r.CheckLocalItems(t, file1c, file5)
err = operations.CopyFile(ctx, fdst, r.Flocal, file5.Path, file5.Path) err = operations.CopyFile(ctx, fdst, r.Flocal, file5.Path, file5.Path)
require.NoError(t, err) require.NoError(t, err)
@ -1086,19 +1086,19 @@ func TestCopyFileCopyDest(t *testing.T) {
file4dst := file4 file4dst := file4
file4dst.Path = "dst/two" file4dst.Path = "dst/two"
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst) r.CheckRemoteItems(t, file2, file2dst, file3, file4, file4dst)
// check new dest, new copy // check new dest, new copy
err = operations.CopyFile(ctx, fdst, r.Flocal, file5.Path, file5.Path) err = operations.CopyFile(ctx, fdst, r.Flocal, file5.Path, file5.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst) r.CheckRemoteItems(t, file2, file2dst, file3, file4, file4dst)
// check empty dest, old copy // check empty dest, old copy
file6 := r.WriteObject(ctx, "CopyDest/three", "three", t2) file6 := r.WriteObject(ctx, "CopyDest/three", "three", t2)
file7 := r.WriteFile("three", "threet3", t3) file7 := r.WriteFile("three", "threet3", t3)
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst, file6) r.CheckRemoteItems(t, file2, file2dst, file3, file4, file4dst, file6)
fstest.CheckItems(t, r.Flocal, file1c, file5, file7) r.CheckLocalItems(t, file1c, file5, file7)
err = operations.CopyFile(ctx, fdst, r.Flocal, file7.Path, file7.Path) err = operations.CopyFile(ctx, fdst, r.Flocal, file7.Path, file7.Path)
require.NoError(t, err) require.NoError(t, err)
@ -1106,7 +1106,7 @@ func TestCopyFileCopyDest(t *testing.T) {
file7dst := file7 file7dst := file7
file7dst.Path = "dst/three" file7dst.Path = "dst/three"
fstest.CheckItems(t, r.Fremote, file2, file2dst, file3, file4, file4dst, file6, file7dst) r.CheckRemoteItems(t, file2, file2dst, file3, file4, file4dst, file6, file7dst)
} }
// testFsInfo is for unit testing fs.Info // testFsInfo is for unit testing fs.Info
@ -1468,7 +1468,7 @@ func TestRcat(t *testing.T) {
file1 := fstest.NewItem(path1, data1, t1) file1 := fstest.NewItem(path1, data1, t1)
file2 := fstest.NewItem(path2, data2, t2) file2 := fstest.NewItem(path2, data2, t2)
fstest.CheckItems(t, r.Fremote, file1, file2) r.CheckRemoteItems(t, file1, file2)
} }
for i := 0; i < 4; i++ { for i := 0; i < 4; i++ {
@ -1504,7 +1504,7 @@ func TestRcatSize(t *testing.T) {
assert.Equal(t, file2.Path, obj.Remote()) assert.Equal(t, file2.Path, obj.Remote())
// Check files exist // Check files exist
fstest.CheckItems(t, r.Fremote, file1, file2) r.CheckRemoteItems(t, file1, file2)
} }
func TestCopyFileMaxTransfer(t *testing.T) { func TestCopyFileMaxTransfer(t *testing.T) {
@ -1535,8 +1535,8 @@ func TestCopyFileMaxTransfer(t *testing.T) {
accounting.Stats(ctx).ResetCounters() accounting.Stats(ctx).ResetCounters()
err = operations.CopyFile(ctx, r.Fremote, r.Flocal, file1.Path, file1.Path) err = operations.CopyFile(ctx, r.Fremote, r.Flocal, file1.Path, file1.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Flocal, file1, file2, file3, file4) r.CheckLocalItems(t, file1, file2, file3, file4)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
// file2: show a large file does not get transferred // file2: show a large file does not get transferred
accounting.Stats(ctx).ResetCounters() accounting.Stats(ctx).ResetCounters()
@ -1544,8 +1544,8 @@ func TestCopyFileMaxTransfer(t *testing.T) {
require.NotNil(t, err, "Did not get expected max transfer limit error") require.NotNil(t, err, "Did not get expected max transfer limit error")
assert.Contains(t, err.Error(), "Max transfer limit reached") assert.Contains(t, err.Error(), "Max transfer limit reached")
assert.True(t, fserrors.IsFatalError(err), fmt.Sprintf("Not fatal error: %v: %#v:", err, err)) assert.True(t, fserrors.IsFatalError(err), fmt.Sprintf("Not fatal error: %v: %#v:", err, err))
fstest.CheckItems(t, r.Flocal, file1, file2, file3, file4) r.CheckLocalItems(t, file1, file2, file3, file4)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
// Cutoff mode: Cautious // Cutoff mode: Cautious
ci.CutoffMode = fs.CutoffModeCautious ci.CutoffMode = fs.CutoffModeCautious
@ -1556,8 +1556,8 @@ func TestCopyFileMaxTransfer(t *testing.T) {
require.NotNil(t, err) require.NotNil(t, err)
assert.Contains(t, err.Error(), "Max transfer limit reached") assert.Contains(t, err.Error(), "Max transfer limit reached")
assert.True(t, fserrors.IsNoRetryError(err)) assert.True(t, fserrors.IsNoRetryError(err))
fstest.CheckItems(t, r.Flocal, file1, file2, file3, file4) r.CheckLocalItems(t, file1, file2, file3, file4)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
if strings.HasPrefix(r.Fremote.Name(), "TestChunker") { if strings.HasPrefix(r.Fremote.Name(), "TestChunker") {
t.Log("skipping remainder of test for chunker as it involves multiple transfers") t.Log("skipping remainder of test for chunker as it involves multiple transfers")
@ -1571,8 +1571,8 @@ func TestCopyFileMaxTransfer(t *testing.T) {
accounting.Stats(ctx).ResetCounters() accounting.Stats(ctx).ResetCounters()
err = operations.CopyFile(ctx, r.Fremote, r.Flocal, file4.Path, file4.Path) err = operations.CopyFile(ctx, r.Fremote, r.Flocal, file4.Path, file4.Path)
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Flocal, file1, file2, file3, file4) r.CheckLocalItems(t, file1, file2, file3, file4)
fstest.CheckItems(t, r.Fremote, file1, file4) r.CheckRemoteItems(t, file1, file4)
} }
func TestTouchDir(t *testing.T) { func TestTouchDir(t *testing.T) {
@ -1587,7 +1587,7 @@ func TestTouchDir(t *testing.T) {
file1 := r.WriteBoth(ctx, "potato2", "------------------------------------------------------------", t1) file1 := r.WriteBoth(ctx, "potato2", "------------------------------------------------------------", t1)
file2 := r.WriteBoth(ctx, "empty space", "-", t2) file2 := r.WriteBoth(ctx, "empty space", "-", t2)
file3 := r.WriteBoth(ctx, "sub dir/potato3", "hello", t2) file3 := r.WriteBoth(ctx, "sub dir/potato3", "hello", t2)
fstest.CheckItems(t, r.Fremote, file1, file2, file3) r.CheckRemoteItems(t, file1, file2, file3)
timeValue := time.Date(2010, 9, 8, 7, 6, 5, 4, time.UTC) timeValue := time.Date(2010, 9, 8, 7, 6, 5, 4, time.UTC)
err := operations.TouchDir(ctx, r.Fremote, timeValue, true) err := operations.TouchDir(ctx, r.Fremote, timeValue, true)
@ -1599,6 +1599,6 @@ func TestTouchDir(t *testing.T) {
file1.ModTime = timeValue file1.ModTime = timeValue
file2.ModTime = timeValue file2.ModTime = timeValue
file3.ModTime = timeValue file3.ModTime = timeValue
fstest.CheckItems(t, r.Fremote, file1, file2, file3) r.CheckRemoteItems(t, file1, file2, file3)
} }
} }

View File

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

View File

@ -33,8 +33,8 @@ func TestRcCopy(t *testing.T) {
file2 := r.WriteFile("subdir/file2", "file2 contents", t2) file2 := r.WriteFile("subdir/file2", "file2 contents", t2)
file3 := r.WriteObject(context.Background(), "subdir/subsubdir/file3", "file3 contents", t3) file3 := r.WriteObject(context.Background(), "subdir/subsubdir/file3", "file3 contents", t3)
fstest.CheckItems(t, r.Flocal, file1, file2) r.CheckLocalItems(t, file1, file2)
fstest.CheckItems(t, r.Fremote, file1, file3) r.CheckRemoteItems(t, file1, file3)
in := rc.Params{ in := rc.Params{
"srcFs": r.LocalName, "srcFs": r.LocalName,
@ -44,8 +44,8 @@ func TestRcCopy(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, rc.Params(nil), out) assert.Equal(t, rc.Params(nil), out)
fstest.CheckItems(t, r.Flocal, file1, file2) r.CheckLocalItems(t, file1, file2)
fstest.CheckItems(t, r.Fremote, file1, file2, file3) r.CheckRemoteItems(t, file1, file2, file3)
} }
// sync/move: move a directory from source remote to destination remote // sync/move: move a directory from source remote to destination remote
@ -58,8 +58,8 @@ func TestRcMove(t *testing.T) {
file2 := r.WriteFile("subdir/file2", "file2 contents", t2) file2 := r.WriteFile("subdir/file2", "file2 contents", t2)
file3 := r.WriteObject(context.Background(), "subdir/subsubdir/file3", "file3 contents", t3) file3 := r.WriteObject(context.Background(), "subdir/subsubdir/file3", "file3 contents", t3)
fstest.CheckItems(t, r.Flocal, file1, file2) r.CheckLocalItems(t, file1, file2)
fstest.CheckItems(t, r.Fremote, file1, file3) r.CheckRemoteItems(t, file1, file3)
in := rc.Params{ in := rc.Params{
"srcFs": r.LocalName, "srcFs": r.LocalName,
@ -69,8 +69,8 @@ func TestRcMove(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, rc.Params(nil), out) assert.Equal(t, rc.Params(nil), out)
fstest.CheckItems(t, r.Flocal) r.CheckLocalItems(t)
fstest.CheckItems(t, r.Fremote, file1, file2, file3) r.CheckRemoteItems(t, file1, file2, file3)
} }
// sync/sync: sync a directory from source remote to destination remote // sync/sync: sync a directory from source remote to destination remote
@ -83,8 +83,8 @@ func TestRcSync(t *testing.T) {
file2 := r.WriteFile("subdir/file2", "file2 contents", t2) file2 := r.WriteFile("subdir/file2", "file2 contents", t2)
file3 := r.WriteObject(context.Background(), "subdir/subsubdir/file3", "file3 contents", t3) file3 := r.WriteObject(context.Background(), "subdir/subsubdir/file3", "file3 contents", t3)
fstest.CheckItems(t, r.Flocal, file1, file2) r.CheckLocalItems(t, file1, file2)
fstest.CheckItems(t, r.Fremote, file1, file3) r.CheckRemoteItems(t, file1, file3)
in := rc.Params{ in := rc.Params{
"srcFs": r.LocalName, "srcFs": r.LocalName,
@ -94,6 +94,6 @@ func TestRcSync(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, rc.Params(nil), out) assert.Equal(t, rc.Params(nil), out)
fstest.CheckItems(t, r.Flocal, file1, file2) r.CheckLocalItems(t, file1, file2)
fstest.CheckItems(t, r.Fremote, file1, file2) r.CheckRemoteItems(t, file1, file2)
} }

File diff suppressed because it is too large Load Diff

View File

@ -345,6 +345,12 @@ func CheckListing(t *testing.T, f fs.Fs, items []Item) {
CheckListingWithPrecision(t, f, items, nil, precision) CheckListingWithPrecision(t, f, items, nil, precision)
} }
// CheckItemsWithPrecision checks the fs with the specified precision
// to see if it has the expected items.
func CheckItemsWithPrecision(t *testing.T, f fs.Fs, precision time.Duration, items ...Item) {
CheckListingWithPrecision(t, f, items, nil, precision)
}
// CheckItems checks the fs to see if it has only the items passed in // CheckItems checks the fs to see if it has only the items passed in
// using a precision of fs.Config.ModifyWindow // using a precision of fs.Config.ModifyWindow
func CheckItems(t *testing.T, f fs.Fs, items ...Item) { func CheckItems(t *testing.T, f fs.Fs, items ...Item) {

View File

@ -55,6 +55,7 @@ type Run struct {
Flocal fs.Fs Flocal fs.Fs
Fremote fs.Fs Fremote fs.Fs
FremoteName string FremoteName string
Precision time.Duration
cleanRemote func() cleanRemote func()
mkdir map[string]bool // whether the remote has been made yet for the fs name mkdir map[string]bool // whether the remote has been made yet for the fs name
Logf, Fatalf func(text string, args ...interface{}) Logf, Fatalf func(text string, args ...interface{})
@ -107,6 +108,9 @@ func newRun() *Run {
if err != nil { if err != nil {
r.Fatalf("Failed to make %q: %v", r.LocalName, err) r.Fatalf("Failed to make %q: %v", r.LocalName, err)
} }
r.Precision = fs.GetModifyWindow(context.Background(), r.Fremote, r.Flocal)
return r return r
} }
@ -326,6 +330,38 @@ func (r *Run) CheckWithDuplicates(t *testing.T, items ...Item) {
assert.Equal(t, want, got) 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 // Clean the temporary directory
func (r *Run) cleanTempDir() { func (r *Run) cleanTempDir() {
err := os.RemoveAll(r.LocalName) err := os.RemoveAll(r.LocalName)

View File

@ -6,7 +6,6 @@ import (
"os" "os"
"testing" "testing"
"github.com/rclone/rclone/fstest"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -45,7 +44,7 @@ func TestDirHandleReaddir(t *testing.T) {
file1 := r.WriteObject(context.Background(), "dir/file1", "file1 contents", t1) file1 := r.WriteObject(context.Background(), "dir/file1", "file1 contents", t1)
file2 := r.WriteObject(context.Background(), "dir/file2", "file2- contents", t2) file2 := r.WriteObject(context.Background(), "dir/file2", "file2- contents", t2)
file3 := r.WriteObject(context.Background(), "dir/subdir/file3", "file3-- contents", t3) file3 := r.WriteObject(context.Background(), "dir/subdir/file3", "file3-- contents", t3)
fstest.CheckItems(t, r.Fremote, file1, file2, file3) r.CheckRemoteItems(t, file1, file2, file3)
node, err := vfs.Stat("dir") node, err := vfs.Stat("dir")
require.NoError(t, err) require.NoError(t, err)

View File

@ -19,7 +19,7 @@ func dirCreate(t *testing.T) (r *fstest.Run, vfs *VFS, dir *Dir, item fstest.Ite
r, vfs, cleanup = newTestVFS(t) r, vfs, cleanup = newTestVFS(t)
file1 := r.WriteObject(context.Background(), "dir/file1", "file1 contents", t1) file1 := r.WriteObject(context.Background(), "dir/file1", "file1 contents", t1)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
node, err := vfs.Stat("dir") node, err := vfs.Stat("dir")
require.NoError(t, err) require.NoError(t, err)
@ -145,7 +145,7 @@ func TestDirWalk(t *testing.T) {
defer cleanup() defer cleanup()
file2 := r.WriteObject(context.Background(), "fil/a/b/c", "super long file", t1) file2 := r.WriteObject(context.Background(), "fil/a/b/c", "super long file", t1)
fstest.CheckItems(t, r.Fremote, file1, file2) r.CheckRemoteItems(t, file1, file2)
root, err := vfs.Root() root, err := vfs.Root()
require.NoError(t, err) require.NoError(t, err)
@ -259,7 +259,7 @@ func TestDirReadDirAll(t *testing.T) {
file1 := r.WriteObject(context.Background(), "dir/file1", "file1 contents", t1) file1 := r.WriteObject(context.Background(), "dir/file1", "file1 contents", t1)
file2 := r.WriteObject(context.Background(), "dir/file2", "file2- contents", t2) file2 := r.WriteObject(context.Background(), "dir/file2", "file2- contents", t2)
file3 := r.WriteObject(context.Background(), "dir/subdir/file3", "file3-- contents", t3) file3 := r.WriteObject(context.Background(), "dir/subdir/file3", "file3-- contents", t3)
fstest.CheckItems(t, r.Fremote, file1, file2, file3) r.CheckRemoteItems(t, file1, file2, file3)
node, err := vfs.Stat("dir") node, err := vfs.Stat("dir")
require.NoError(t, err) require.NoError(t, err)

View File

@ -24,7 +24,7 @@ func fileCreate(t *testing.T, mode vfscommon.CacheMode) (r *fstest.Run, vfs *VFS
r, vfs, cleanup = newTestVFSOpt(t, &opt) r, vfs, cleanup = newTestVFSOpt(t, &opt)
file1 := r.WriteObject(context.Background(), "dir/file1", "file1 contents", t1) file1 := r.WriteObject(context.Background(), "dir/file1", "file1 contents", t1)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
node, err := vfs.Stat("dir/file1") node, err := vfs.Stat("dir/file1")
require.NoError(t, err) require.NoError(t, err)
@ -137,7 +137,7 @@ func testFileSetModTime(t *testing.T, cacheMode vfscommon.CacheMode, open bool,
} }
file1 = fstest.NewItem(file1.Path, contents, t2) file1 = fstest.NewItem(file1.Path, contents, t2)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
vfs.Opt.ReadOnly = true vfs.Opt.ReadOnly = true
err = file.SetModTime(t2) err = file.SetModTime(t2)
@ -255,7 +255,7 @@ func TestFileRemove(t *testing.T) {
err := file.Remove() err := file.Remove()
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Fremote) r.CheckRemoteItems(t)
vfs.Opt.ReadOnly = true vfs.Opt.ReadOnly = true
err = file.Remove() err = file.Remove()
@ -269,7 +269,7 @@ func TestFileRemoveAll(t *testing.T) {
err := file.RemoveAll() err := file.RemoveAll()
require.NoError(t, err) require.NoError(t, err)
fstest.CheckItems(t, r.Fremote) r.CheckRemoteItems(t)
vfs.Opt.ReadOnly = true vfs.Opt.ReadOnly = true
err = file.RemoveAll() err = file.RemoveAll()
@ -340,14 +340,14 @@ func testFileRename(t *testing.T, mode vfscommon.CacheMode, inCache bool, forceC
dir := file.Dir() dir := file.Dir()
// start with "dir/file1" // start with "dir/file1"
fstest.CheckItems(t, r.Fremote, item) r.CheckRemoteItems(t, item)
// rename file to "newLeaf" // rename file to "newLeaf"
err = dir.Rename("file1", "newLeaf", rootDir) err = dir.Rename("file1", "newLeaf", rootDir)
require.NoError(t, err) require.NoError(t, err)
item.Path = "newLeaf" item.Path = "newLeaf"
fstest.CheckItems(t, r.Fremote, item) r.CheckRemoteItems(t, item)
// check file in cache // check file in cache
if inCache { if inCache {
@ -363,7 +363,7 @@ func testFileRename(t *testing.T, mode vfscommon.CacheMode, inCache bool, forceC
require.NoError(t, err) require.NoError(t, err)
item.Path = "dir/file1" item.Path = "dir/file1"
fstest.CheckItems(t, r.Fremote, item) r.CheckRemoteItems(t, item)
// check file in cache // check file in cache
if inCache { if inCache {

View File

@ -16,7 +16,7 @@ func readHandleCreate(t *testing.T) (r *fstest.Run, vfs *VFS, fh *ReadFileHandle
r, vfs, cleanup = newTestVFS(t) r, vfs, cleanup = newTestVFS(t)
file1 := r.WriteObject(context.Background(), "dir/file1", "0123456789abcdef", t1) file1 := r.WriteObject(context.Background(), "dir/file1", "0123456789abcdef", t1)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
h, err := vfs.OpenFile("dir/file1", os.O_RDONLY, 0777) h, err := vfs.OpenFile("dir/file1", os.O_RDONLY, 0777)
require.NoError(t, err) require.NoError(t, err)

View File

@ -38,7 +38,7 @@ func rwHandleCreateFlags(t *testing.T, create bool, filename string, flags int)
if create { if create {
file1 := r.WriteObject(context.Background(), filename, "0123456789abcdef", t1) file1 := r.WriteObject(context.Background(), filename, "0123456789abcdef", t1)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
} }
h, err := vfs.OpenFile(filename, flags, 0777) h, err := vfs.OpenFile(filename, flags, 0777)
@ -690,7 +690,7 @@ func TestRWFileModTimeWithOpenWriters(t *testing.T) {
file1 := fstest.NewItem("file1", "hi", mtime) file1 := fstest.NewItem("file1", "hi", mtime)
vfs.WaitForWriters(waitForWritersDelay) vfs.WaitForWriters(waitForWritersDelay)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
} }
func TestRWCacheRename(t *testing.T) { func TestRWCacheRename(t *testing.T) {

View File

@ -23,7 +23,7 @@ func TestCaseSensitivity(t *testing.T) {
ctx := context.Background() ctx := context.Background()
file1 := r.WriteObject(ctx, "FiLeA", "data1", t1) file1 := r.WriteObject(ctx, "FiLeA", "data1", t1)
file2 := r.WriteObject(ctx, "FiLeB", "data2", t2) file2 := r.WriteObject(ctx, "FiLeB", "data2", t2)
fstest.CheckItems(t, r.Fremote, file1, file2) r.CheckRemoteItems(t, file1, file2)
// Create file3 with name differing from file2 name only by case. // Create file3 with name differing from file2 name only by case.
// On a case-Sensitive remote this will be a separate file. // On a case-Sensitive remote this will be a separate file.
@ -65,7 +65,7 @@ func TestCaseSensitivity(t *testing.T) {
} }
// Continue with test as the underlying remote is fully case-Sensitive. // Continue with test as the underlying remote is fully case-Sensitive.
fstest.CheckItems(t, r.Fremote, file1, file2, file3) r.CheckRemoteItems(t, file1, file2, file3)
// See how VFS handles case-INsensitive flag // See how VFS handles case-INsensitive flag
assertFileDataVFS(t, vfsCI, "FiLeA", "data1") assertFileDataVFS(t, vfsCI, "FiLeA", "data1")

View File

@ -194,7 +194,7 @@ func TestVFSStat(t *testing.T) {
file1 := r.WriteObject(context.Background(), "file1", "file1 contents", t1) file1 := r.WriteObject(context.Background(), "file1", "file1 contents", t1)
file2 := r.WriteObject(context.Background(), "dir/file2", "file2 contents", t2) file2 := r.WriteObject(context.Background(), "dir/file2", "file2 contents", t2)
fstest.CheckItems(t, r.Fremote, file1, file2) r.CheckRemoteItems(t, file1, file2)
node, err := vfs.Stat("file1") node, err := vfs.Stat("file1")
require.NoError(t, err) require.NoError(t, err)
@ -230,7 +230,7 @@ func TestVFSStatParent(t *testing.T) {
file1 := r.WriteObject(context.Background(), "file1", "file1 contents", t1) file1 := r.WriteObject(context.Background(), "file1", "file1 contents", t1)
file2 := r.WriteObject(context.Background(), "dir/file2", "file2 contents", t2) file2 := r.WriteObject(context.Background(), "dir/file2", "file2 contents", t2)
fstest.CheckItems(t, r.Fremote, file1, file2) r.CheckRemoteItems(t, file1, file2)
node, leaf, err := vfs.StatParent("file1") node, leaf, err := vfs.StatParent("file1")
require.NoError(t, err) require.NoError(t, err)
@ -263,7 +263,7 @@ func TestVFSOpenFile(t *testing.T) {
file1 := r.WriteObject(context.Background(), "file1", "file1 contents", t1) file1 := r.WriteObject(context.Background(), "file1", "file1 contents", t1)
file2 := r.WriteObject(context.Background(), "dir/file2", "file2 contents", t2) file2 := r.WriteObject(context.Background(), "dir/file2", "file2 contents", t2)
fstest.CheckItems(t, r.Fremote, file1, file2) r.CheckRemoteItems(t, file1, file2)
fd, err := vfs.OpenFile("file1", os.O_RDONLY, 0777) fd, err := vfs.OpenFile("file1", os.O_RDONLY, 0777)
require.NoError(t, err) require.NoError(t, err)
@ -302,17 +302,17 @@ func TestVFSRename(t *testing.T) {
} }
file1 := r.WriteObject(context.Background(), "dir/file2", "file2 contents", t2) file1 := r.WriteObject(context.Background(), "dir/file2", "file2 contents", t2)
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
err := vfs.Rename("dir/file2", "dir/file1") err := vfs.Rename("dir/file2", "dir/file1")
require.NoError(t, err) require.NoError(t, err)
file1.Path = "dir/file1" file1.Path = "dir/file1"
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
err = vfs.Rename("dir/file1", "file0") err = vfs.Rename("dir/file1", "file0")
require.NoError(t, err) require.NoError(t, err)
file1.Path = "file0" file1.Path = "file0"
fstest.CheckItems(t, r.Fremote, file1) r.CheckRemoteItems(t, file1)
err = vfs.Rename("not found/file0", "file0") err = vfs.Rename("not found/file0", "file0")
assert.Equal(t, os.ErrNotExist, err) assert.Equal(t, os.ErrNotExist, err)