Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

operations: fix HashSum tests after removing ERROR and UNSUPPORTED

Nick Craig-Woodedf8978d1598
diff --git a/fs/operations/operations_test.go b/fs/operations/operations_test.go
index 4c43a66cd..703aa20f2 100644
--- a/fs/operations/operations_test.go
+++ b/fs/operations/operations_test.go
@@ -190,144 +190,101 @@ func TestHashSums(t *testing.T) {
fstest.CheckItems(t, r.Fremote, file1, file2)
- // MD5 Sum without download
+ hashes := r.Fremote.Hashes()
- var buf bytes.Buffer
- err := operations.HashLister(ctx, hash.MD5, false, true, r.Fremote, &buf)
- require.NoError(t, err)
- res := buf.String()
- if !strings.Contains(res, "336d5ebc5436534e61d16e63ddfca327 empty space\n") &&
- !strings.Contains(res, " UNSUPPORTED empty space\n") &&
- !strings.Contains(res, " empty space\n") {
- t.Errorf("empty space missing: %q", res)
- }
- if !strings.Contains(res, "d6548b156ea68a4e003e786df99eee76 potato2\n") &&
- !strings.Contains(res, " UNSUPPORTED potato2\n") &&
- !strings.Contains(res, " potato2\n") {
- t.Errorf("potato2 missing: %q", res)
- }
-
- // MD5 Sum with download
-
- buf.Reset()
- err = operations.HashLister(ctx, hash.MD5, false, true, r.Fremote, &buf)
- require.NoError(t, err)
- res = buf.String()
- if !strings.Contains(res, "336d5ebc5436534e61d16e63ddfca327 empty space\n") &&
- !strings.Contains(res, " UNSUPPORTED empty space\n") &&
- !strings.Contains(res, " empty space\n") {
- t.Errorf("empty space missing: %q", res)
- }
- if !strings.Contains(res, "d6548b156ea68a4e003e786df99eee76 potato2\n") &&
- !strings.Contains(res, " UNSUPPORTED potato2\n") &&
- !strings.Contains(res, " potato2\n") {
- t.Errorf("potato2 missing: %q", res)
- }
-
- // SHA1 Sum without download
-
- buf.Reset()
- err = operations.HashLister(ctx, hash.SHA1, false, false, r.Fremote, &buf)
- require.NoError(t, err)
- res = buf.String()
- if !strings.Contains(res, "3bc15c8aae3e4124dd409035f32ea2fd6835efc9 empty space\n") &&
- !strings.Contains(res, " UNSUPPORTED empty space\n") &&
- !strings.Contains(res, " empty space\n") {
- t.Errorf("empty space missing: %q", res)
- }
- if !strings.Contains(res, "9dc7f7d3279715991a22853f5981df582b7f9f6d potato2\n") &&
- !strings.Contains(res, " UNSUPPORTED potato2\n") &&
- !strings.Contains(res, " potato2\n") {
- t.Errorf("potato2 missing: %q", res)
- }
-
- // SHA1 Sum with download
-
- buf.Reset()
- err = operations.HashLister(ctx, hash.SHA1, false, true, r.Fremote, &buf)
- require.NoError(t, err)
- res = buf.String()
- if !strings.Contains(res, "3bc15c8aae3e4124dd409035f32ea2fd6835efc9 empty space\n") &&
- !strings.Contains(res, " UNSUPPORTED empty space\n") &&
- !strings.Contains(res, " empty space\n") {
- t.Errorf("empty space missing: %q", res)
- }
- if !strings.Contains(res, "9dc7f7d3279715991a22853f5981df582b7f9f6d potato2\n") &&
- !strings.Contains(res, " UNSUPPORTED potato2\n") &&
- !strings.Contains(res, " potato2\n") {
- t.Errorf("potato2 missing: %q", res)
- }
-
- // QuickXorHash Sum without download
-
- buf.Reset()
- var ht hash.Type
- err = ht.Set("QuickXorHash")
- require.NoError(t, err)
- err = operations.HashLister(ctx, ht, false, false, r.Fremote, &buf)
- require.NoError(t, err)
- res = buf.String()
- if !strings.Contains(res, "2d00000000000000000000000100000000000000 empty space\n") &&
- !strings.Contains(res, " UNSUPPORTED empty space\n") &&
- !strings.Contains(res, " empty space\n") {
- t.Errorf("empty space missing: %q", res)
- }
- if !strings.Contains(res, "4001dad296b6b4a52d6d694b67dad296b6b4a52d potato2\n") &&
- !strings.Contains(res, " UNSUPPORTED potato2\n") &&
- !strings.Contains(res, " potato2\n") {
- t.Errorf("potato2 missing: %q", res)
- }
-
- // QuickXorHash Sum with download
-
- buf.Reset()
- require.NoError(t, err)
- err = operations.HashLister(ctx, ht, false, true, r.Fremote, &buf)
- require.NoError(t, err)
- res = buf.String()
- if !strings.Contains(res, "2d00000000000000000000000100000000000000 empty space\n") &&
- !strings.Contains(res, " UNSUPPORTED empty space\n") &&
- !strings.Contains(res, " empty space\n") {
- t.Errorf("empty space missing: %q", res)
- }
- if !strings.Contains(res, "4001dad296b6b4a52d6d694b67dad296b6b4a52d potato2\n") &&
- !strings.Contains(res, " UNSUPPORTED potato2\n") &&
- !strings.Contains(res, " potato2\n") {
- t.Errorf("potato2 missing: %q", res)
- }
-
- // QuickXorHash Sum with Base64 Encoded, without download
-
- buf.Reset()
- err = operations.HashLister(ctx, ht, true, false, r.Fremote, &buf)
+ var quickXorHash hash.Type
+ err := quickXorHash.Set("QuickXorHash")
require.NoError(t, err)
- res = buf.String()
- if !strings.Contains(res, "LQAAAAAAAAAAAAAAAQAAAAAAAAA= empty space\n") &&
- !strings.Contains(res, " UNSUPPORTED empty space\n") &&
- !strings.Contains(res, " empty space\n") {
- t.Errorf("empty space missing: %q", res)
- }
- if !strings.Contains(res, "QAHa0pa2tKUtbWlLZ9rSlra0pS0= potato2\n") &&
- !strings.Contains(res, " UNSUPPORTED potato2\n") &&
- !strings.Contains(res, " potato2\n") {
- t.Errorf("potato2 missing: %q", res)
- }
-
- // QuickXorHash Sum with Base64 Encoded and download
- buf.Reset()
- err = operations.HashLister(ctx, ht, true, true, r.Fremote, &buf)
- require.NoError(t, err)
- res = buf.String()
- if !strings.Contains(res, "LQAAAAAAAAAAAAAAAQAAAAAAAAA= empty space\n") &&
- !strings.Contains(res, " UNSUPPORTED empty space\n") &&
- !strings.Contains(res, " empty space\n") {
- t.Errorf("empty space missing: %q", res)
- }
- if !strings.Contains(res, "QAHa0pa2tKUtbWlLZ9rSlra0pS0= potato2\n") &&
- !strings.Contains(res, " UNSUPPORTED potato2\n") &&
- !strings.Contains(res, " potato2\n") {
- t.Errorf("potato2 missing: %q", res)
+ for _, test := range []struct {
+ name string
+ download bool
+ base64 bool
+ ht hash.Type
+ want []string
+ }{
+ {
+ ht: hash.MD5,
+ want: []string{
+ "336d5ebc5436534e61d16e63ddfca327 empty space\n",
+ "d6548b156ea68a4e003e786df99eee76 potato2\n",
+ },
+ },
+ {
+ ht: hash.MD5,
+ download: true,
+ want: []string{
+ "336d5ebc5436534e61d16e63ddfca327 empty space\n",
+ "d6548b156ea68a4e003e786df99eee76 potato2\n",
+ },
+ },
+ {
+ ht: hash.SHA1,
+ want: []string{
+ "3bc15c8aae3e4124dd409035f32ea2fd6835efc9 empty space\n",
+ "9dc7f7d3279715991a22853f5981df582b7f9f6d potato2\n",
+ },
+ },
+ {
+ ht: hash.SHA1,
+ download: true,
+ want: []string{
+ "3bc15c8aae3e4124dd409035f32ea2fd6835efc9 empty space\n",
+ "9dc7f7d3279715991a22853f5981df582b7f9f6d potato2\n",
+ },
+ },
+ {
+ ht: quickXorHash,
+ want: []string{
+ "2d00000000000000000000000100000000000000 empty space\n",
+ "4001dad296b6b4a52d6d694b67dad296b6b4a52d potato2\n",
+ },
+ },
+ {
+ ht: quickXorHash,
+ download: true,
+ want: []string{
+ "2d00000000000000000000000100000000000000 empty space\n",
+ "4001dad296b6b4a52d6d694b67dad296b6b4a52d potato2\n",
+ },
+ },
+ {
+ ht: quickXorHash,
+ base64: true,
+ want: []string{
+ "LQAAAAAAAAAAAAAAAQAAAAAAAAA= empty space\n",
+ "QAHa0pa2tKUtbWlLZ9rSlra0pS0= potato2\n",
+ },
+ },
+ {
+ ht: quickXorHash,
+ base64: true,
+ download: true,
+ want: []string{
+ "LQAAAAAAAAAAAAAAAQAAAAAAAAA= empty space\n",
+ "QAHa0pa2tKUtbWlLZ9rSlra0pS0= potato2\n",
+ },
+ },
+ } {
+ if !hashes.Contains(test.ht) {
+ continue
+ }
+ name := strings.Title(test.ht.String())
+ if test.download {
+ name += "Download"
+ }
+ if test.base64 {
+ name += "Base64"
+ }
+ t.Run(name, func(t *testing.T) {
+ var buf bytes.Buffer
+ err := operations.HashLister(ctx, test.ht, test.base64, test.download, r.Fremote, &buf)
+ require.NoError(t, err)
+ res := buf.String()
+ for _, line := range test.want {
+ assert.Contains(t, res, line)
+ }
+ })
}
}