MCPcopy
hub / github.com/kopia/kopia / TestMapStorageWithLimit

Function TestMapStorageWithLimit

internal/blobtesting/map_test.go:24–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22}
23
24func TestMapStorageWithLimit(t *testing.T) {
25 ctx := testlogging.Context(t)
26 data := DataMap{}
27
28 r := NewMapStorageWithLimit(data, nil, nil, 10)
29 verifyCapacityAndFreeSpace(t, r, 10, 10)
30 require.NoError(t, r.PutBlob(ctx, "foo", gather.FromSlice([]byte("foo")), blob.PutOptions{}))
31 verifyCapacityAndFreeSpace(t, r, 10, 7)
32 require.NoError(t, r.PutBlob(ctx, "bar", gather.FromSlice([]byte("bar")), blob.PutOptions{}))
33 verifyCapacityAndFreeSpace(t, r, 10, 4)
34 require.NoError(t, r.PutBlob(ctx, "baz", gather.FromSlice([]byte("baz")), blob.PutOptions{}))
35 verifyCapacityAndFreeSpace(t, r, 10, 1)
36
37 // we're at 9/10 bytes, can't add 3 more
38 require.ErrorContains(t, r.PutBlob(ctx, "qux", gather.FromSlice([]byte("qux")), blob.PutOptions{}), "exceeded limit")
39 // remove 3 bytes
40 require.NoError(t, r.DeleteBlob(ctx, "baz"))
41 verifyCapacityAndFreeSpace(t, r, 10, 4)
42 // can add 4 bytes again
43 require.NoError(t, r.PutBlob(ctx, "qux", gather.FromSlice([]byte("qux1")), blob.PutOptions{}))
44 verifyCapacityAndFreeSpace(t, r, 10, 0)
45 // can't add any more bytes since we're at 10/10 bytes
46 require.ErrorContains(t, r.PutBlob(ctx, "aaa", gather.FromSlice([]byte("1")), blob.PutOptions{}), "exceeded limit")
47 // adding zero bytes won't fail in this situation.
48 require.NoError(t, r.PutBlob(ctx, "bbb", gather.FromSlice([]byte{}), blob.PutOptions{}), "exceeded limit")
49 verifyCapacityAndFreeSpace(t, r, 10, 0)
50
51 r = NewMapStorageWithLimit(DataMap{
52 "foo": []byte("foo"),
53 }, nil, nil, 20)
54 verifyCapacityAndFreeSpace(t, r, 20, 17)
55}
56
57func verifyCapacityAndFreeSpace(t *testing.T, r blob.Storage, wantSize, wantFree int64) {
58 t.Helper()

Callers

nothing calls this directly

Calls 6

ContextFunction · 0.92
FromSliceFunction · 0.92
NewMapStorageWithLimitFunction · 0.85
PutBlobMethod · 0.65
DeleteBlobMethod · 0.65

Tested by

no test coverage detected