MCPcopy
hub / github.com/kopia/kopia / VerifyStorage

Function VerifyStorage

internal/blobtesting/verify.go:22–197  ·  view source on GitHub ↗

VerifyStorage verifies the behavior of the specified storage. nolint:gocyclo,thelper

(ctx context.Context, t *testing.T, r blob.Storage, opts blob.PutOptions)

Source from the content-addressed store, hash-verified

20//
21//nolint:gocyclo,thelper
22func VerifyStorage(ctx context.Context, t *testing.T, r blob.Storage, opts blob.PutOptions) {
23 blocks := []struct {
24 blk blob.ID
25 contents []byte
26 }{
27 {blk: "abcdbbf4f0507d054ed5a80a5b65086f602b", contents: []byte{}},
28 {blk: "zxce0e35630770c54668a8cfb4e414c6bf8f", contents: []byte{1}},
29 {blk: "abff4585856ebf0748fd989e1dd623a8963d", contents: bytes.Repeat([]byte{1}, 1000)},
30 {blk: "abgc3dca496d510f492c858a2df1eb824e62", contents: bytes.Repeat([]byte{1}, 10000)},
31 {blk: "kopia.repository", contents: bytes.Repeat([]byte{2}, 100)},
32 }
33
34 // First verify that blocks don't exist.
35 t.Run("VerifyBlobsNotFound", func(t *testing.T) {
36 for _, b := range blocks {
37 t.Run(string(b.blk), func(t *testing.T) {
38 t.Parallel()
39
40 AssertGetBlobNotFound(ctx, t, r, b.blk)
41 AssertGetMetadataNotFound(ctx, t, r, b.blk)
42 })
43 }
44 })
45
46 if err := r.DeleteBlob(ctx, "no-such-blob"); err != nil && !errors.Is(err, blob.ErrBlobNotFound) {
47 t.Errorf("invalid error when deleting non-existent blob: %v", err)
48 }
49
50 initialAddConcurrency := 2
51 if os.Getenv("CI") != "" {
52 initialAddConcurrency = 4
53 }
54
55 // Now add blocks.
56 t.Run("AddBlobs", func(t *testing.T) {
57 for _, b := range blocks {
58 for i := range initialAddConcurrency {
59 t.Run(fmt.Sprintf("%v-%v", b.blk, i), func(t *testing.T) {
60 t.Parallel()
61
62 require.NoError(t, r.PutBlob(ctx, b.blk, gather.FromSlice(b.contents), opts))
63 })
64 }
65 }
66 })
67
68 t.Run("GetBlobs", func(t *testing.T) {
69 for _, b := range blocks {
70 t.Run(string(b.blk), func(t *testing.T) {
71 t.Parallel()
72
73 AssertGetBlob(ctx, t, r, b.blk, b.contents)
74 })
75 }
76 })
77
78 t.Run("ListBlobs", func(t *testing.T) {
79 errExpected := errors.New("expected error")

Callers 15

TestRCloneStorageFunction · 0.92
TestRCloneProvidersFunction · 0.92
TestShardedFileStorageFunction · 0.92
TestAzureStorageFunction · 0.92
TestAzureStorageSASTokenFunction · 0.92
TestLoggingStorageFunction · 0.92
TestGCSStorageFunction · 0.92
TestB2StorageFunction · 0.92
verifyWebDAVStorageFunction · 0.92

Calls 15

FromSliceFunction · 0.92
ListAllBlobsFunction · 0.92
AssertGetBlobNotFoundFunction · 0.85
AssertGetBlobFunction · 0.85
AssertListResultsFunction · 0.85
RepeatMethod · 0.80
ErrorfMethod · 0.80
FatalfMethod · 0.80
RunMethod · 0.65
DeleteBlobMethod · 0.65

Tested by 15

TestRCloneStorageFunction · 0.74
TestRCloneProvidersFunction · 0.74
TestShardedFileStorageFunction · 0.74
TestAzureStorageFunction · 0.74
TestAzureStorageSASTokenFunction · 0.74
TestLoggingStorageFunction · 0.74
TestGCSStorageFunction · 0.74
TestB2StorageFunction · 0.74
verifyWebDAVStorageFunction · 0.74