MCPcopy
hub / github.com/kopia/kopia / testPutAndGet

Function testPutAndGet

repo/ecc/ecc_utils_test.go:30–64  ·  view source on GitHub ↗
(t *testing.T, opts *Options, originalSize,
	expectedEccSize int, expectedSuccess bool,
	makeChanges func(impl encryption.Encryptor, data []byte),
)

Source from the content-addressed store, hash-verified

28}
29
30func testPutAndGet(t *testing.T, opts *Options, originalSize,
31 expectedEccSize int, expectedSuccess bool,
32 makeChanges func(impl encryption.Encryptor, data []byte),
33) {
34 t.Helper()
35
36 impl, err := CreateAlgorithm(opts)
37 require.NoError(t, err)
38
39 original := make([]byte, originalSize)
40 for i := range originalSize {
41 original[i] = byte(i%255) + 1
42 }
43
44 output := gather.NewWriteBuffer()
45
46 err = impl.Encrypt(gather.FromSlice(original), nil, output)
47 require.NoError(t, err)
48
49 result := output.ToByteSlice()
50 require.Len(t, result, originalSize+expectedEccSize)
51
52 makeChanges(impl, result)
53
54 output = gather.NewWriteBuffer()
55
56 err = impl.Decrypt(gather.FromSlice(result), nil, output)
57
58 if expectedSuccess {
59 require.NoError(t, err)
60 require.Equal(t, original, output.ToByteSlice())
61 } else {
62 require.Error(t, err)
63 }
64}
65
66func flipByte(data []byte, i int) {
67 if data[i] >= 128 {

Callers 5

testRsCrc32NoChangeFunction · 0.85
testRsCrc32ChangeInDataFunction · 0.85

Calls 10

ToByteSliceMethod · 0.95
NewWriteBufferFunction · 0.92
FromSliceFunction · 0.92
CreateAlgorithmFunction · 0.85
HelperMethod · 0.80
EqualMethod · 0.80
EncryptMethod · 0.65
DecryptMethod · 0.65
ErrorMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected