Test the ObjectInfo
(t *testing.T, f *Fs, wrap bool)
| 43 | |
| 44 | // Test the ObjectInfo |
| 45 | func 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 | |
| 92 | func testComputeHash(t *testing.T, f *Fs) { |
| 93 | var ( |
no test coverage detected
searching dependent graphs…