1
0
mirror of https://github.com/rclone/rclone.git synced 2025-01-29 21:04:23 +02:00

operations: fix HashSum tests after removing ERROR and UNSUPPORTED

This was caused by

7a1cab57b60cedcd cmd/hashsum: dont put ERROR or UNSUPPORTED in output

And was picked up in the integration tests.

This patch no longer calls the HashLister for unsupported hash types.
This commit is contained in:
Nick Craig-Wood 2021-10-15 10:44:06 +01:00
parent f529c02446
commit edf8978d15

View File

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