MCPcopy
hub / github.com/rclone/rclone / testObjectInfo

Function testObjectInfo

backend/crypt/crypt_internal_test.go:45–90  ·  view source on GitHub ↗

Test the ObjectInfo

(t *testing.T, f *Fs, wrap bool)

Source from the content-addressed store, hash-verified

43
44// Test the ObjectInfo
45func testObjectInfo(t *testing.T, f *Fs, wrap bool) {
46 var (
47 contents = random.String(100)
48 path = "hash_test_object"
49 ctx = context.Background()
50 )
51 if wrap {
52 path = "_wrap"
53 }
54
55 localFs := makeTempLocalFs(t)
56
57 obj := uploadFile(t, localFs, path, contents)
58
59 // encrypt the data
60 inBuf := bytes.NewBufferString(contents)
61 var outBuf bytes.Buffer
62 enc, err := f.cipher.newEncrypter(inBuf, nil)
63 require.NoError(t, err)
64 nonce := enc.nonce // read the nonce at the start
65 _, err = io.Copy(&outBuf, enc)
66 require.NoError(t, err)
67
68 var oi fs.ObjectInfo = obj
69 if wrap {
70 // wrap the object in an fs.ObjectUnwrapper if required
71 oi = fs.NewOverrideRemote(oi, "new_remote")
72 }
73
74 // wrap the object in a crypt for upload using the nonce we
75 // saved from the encrypter
76 src := f.newObjectInfo(oi, nonce)
77
78 // Test ObjectInfo methods
79 if !f.opt.NoDataEncryption {
80 assert.Equal(t, int64(outBuf.Len()), src.Size())
81 }
82 assert.Equal(t, f, src.Fs())
83 assert.NotEqual(t, path, src.Remote())
84
85 // Test ObjectInfo.Hash
86 wantHash := md5.Sum(outBuf.Bytes())
87 gotHash, err := src.Hash(ctx, hash.MD5)
88 require.NoError(t, err)
89 assert.Equal(t, fmt.Sprintf("%x", wantHash), gotHash)
90}
91
92func testComputeHash(t *testing.T, f *Fs) {
93 var (

Callers 1

InternalTestMethod · 0.85

Calls 15

StringFunction · 0.92
NewOverrideRemoteFunction · 0.92
makeTempLocalFsFunction · 0.85
newEncrypterMethod · 0.80
newObjectInfoMethod · 0.80
uploadFileFunction · 0.70
CopyMethod · 0.65
SizeMethod · 0.65
FsMethod · 0.65
RemoteMethod · 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…