(t *testing.T, f *Fs)
| 90 | } |
| 91 | |
| 92 | func testComputeHash(t *testing.T, f *Fs) { |
| 93 | var ( |
| 94 | contents = random.String(100) |
| 95 | path = "compute_hash_test" |
| 96 | ctx = context.Background() |
| 97 | hashType = f.Fs.Hashes().GetOne() |
| 98 | ) |
| 99 | |
| 100 | if hashType == hash.None { |
| 101 | t.Skipf("%v: does not support hashes", f.Fs) |
| 102 | } |
| 103 | |
| 104 | localFs := makeTempLocalFs(t) |
| 105 | |
| 106 | // Upload a file to localFs as a test object |
| 107 | localObj := uploadFile(t, localFs, path, contents) |
| 108 | |
| 109 | // Upload the same data to the remote Fs also |
| 110 | remoteObj := uploadFile(t, f, path, contents) |
| 111 | |
| 112 | // Calculate the expected Hash of the remote object |
| 113 | computedHash, err := f.ComputeHash(ctx, remoteObj.(*Object), localObj, hashType) |
| 114 | require.NoError(t, err) |
| 115 | |
| 116 | // Test computed hash matches remote object hash |
| 117 | remoteObjHash, err := remoteObj.(*Object).Object.Hash(ctx, hashType) |
| 118 | require.NoError(t, err) |
| 119 | assert.Equal(t, remoteObjHash, computedHash) |
| 120 | } |
| 121 | |
| 122 | // InternalTest is called by fstests.Run to extra tests |
| 123 | func (f *Fs) InternalTest(t *testing.T) { |
no test coverage detected
searching dependent graphs…