MCPcopy
hub / github.com/rclone/rclone / testComputeHash

Function testComputeHash

backend/crypt/crypt_internal_test.go:92–120  ·  view source on GitHub ↗
(t *testing.T, f *Fs)

Source from the content-addressed store, hash-verified

90}
91
92func 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
123func (f *Fs) InternalTest(t *testing.T) {

Callers 1

InternalTestMethod · 0.85

Calls 8

StringFunction · 0.92
makeTempLocalFsFunction · 0.85
GetOneMethod · 0.80
ComputeHashMethod · 0.80
uploadFileFunction · 0.70
HashesMethod · 0.65
HashMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…