VerifyStorage verifies the behavior of the specified storage. nolint:gocyclo,thelper
(ctx context.Context, t *testing.T, r blob.Storage, opts blob.PutOptions)
| 20 | // |
| 21 | //nolint:gocyclo,thelper |
| 22 | func 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") |