"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
Make directory listing checks more reliable and easier to read
Nick Craig-Wooda77659e47d9f
diff --git a/fstest/fstest.go b/fstest/fstest.goindex ff81a1dfb..4e85ac146 100644--- a/fstest/fstest.go+++ b/fstest/fstest.go@@ -14,6 +14,7 @@ import ("os""path/filepath""regexp"+ "runtime""sort""strings""testing"@@ -143,6 +144,30 @@ func (is *Items) Done(t *testing.T) {assert.Equal(t, 0, len(is.byName), fmt.Sprintf("%d objects not found", len(is.byName)))}+// makeListingFromItems returns a string representation of the items+func makeListingFromItems(items []Item) string {+ nameLengths := make([]string, len(items))+ for i, item := range items {+ remote := item.Path+ if item.WinPath != "" && runtime.GOOS == "windows" {+ remote = item.WinPath+ }+ nameLengths[i] = fmt.Sprintf("%s (%d)", remote, item.Size)+ }+ sort.Strings(nameLengths)+ return strings.Join(nameLengths, ", ")+}++// makeListingFromObjects returns a string representation of the objects+func makeListingFromObjects(objs []fs.Object) string {+ nameLengths := make([]string, len(objs))+ for i, obj := range objs {+ nameLengths[i] = fmt.Sprintf("%s (%d)", obj.Remote(), obj.Size())+ }+ sort.Strings(nameLengths)+ return strings.Join(nameLengths, ", ")+}+// CheckListingWithPrecision checks the fs to see if it has the// expected contents with the given precision.//@@ -157,12 +182,15 @@ func CheckListingWithPrecision(t *testing.T, f fs.Fs, items []Item, expectedDirsvar err errorvar retries = *listRetriessleep := time.Second / 2+ wantListing := makeListingFromItems(items)+ gotListing := "<unset>"for i := 1; i <= retries; i++ {objs, dirs, err = fs.NewLister().Start(f, "").GetAll()if err != nil && err != fs.ErrorDirNotFound {t.Fatalf("Error listing: %v", err)}- if len(objs) == len(items) && (expectedDirs == nil || len(dirs) == 0 || len(dirs) == len(expectedDirs)) {+ gotListing = makeListingFromObjects(objs)+ if wantListing == gotListing && (expectedDirs == nil || len(dirs) == 0 || len(dirs) == len(expectedDirs)) {// Put an extra sleep in if we did any retries just to make sure it really// is consistent (here is looking at you Amazon Drive!)if i != 1 {@@ -180,6 +208,7 @@ func CheckListingWithPrecision(t *testing.T, f fs.Fs, items []Item, expectedDirsdoDirCacheFlush()}}+ assert.Equal(t, wantListing, gotListing, "listing incorrect")for _, obj := range objs {require.NotNil(t, obj)is.Find(t, obj, precision)