MCPcopy
hub / github.com/kopia/kopia / TestCacheFailureToWrite

Function TestCacheFailureToWrite

internal/cache/content_cache_test.go:271–304  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

269}
270
271func TestCacheFailureToWrite(t *testing.T) {
272 someError := errors.New("some error")
273
274 cacheData := blobtesting.DataMap{}
275 cacheStorage := blobtesting.NewMapStorage(cacheData, nil, nil)
276 underlyingStorage := newUnderlyingStorageForContentCacheTesting(t)
277 faultyCache := blobtesting.NewFaultyStorage(cacheStorage)
278
279 cc, err := cache.NewContentCache(testlogging.Context(t), underlyingStorage, cache.Options{
280 Storage: withoutTouchBlob{faultyCache},
281 Sweep: cache.SweepSettings{MaxSizeBytes: 10000},
282 }, nil)
283 require.NoError(t, err)
284
285 ctx := testlogging.Context(t)
286
287 defer cc.Close(ctx)
288
289 faultyCache.AddFault(blobtesting.MethodPutBlob).ErrorInstead(someError)
290
291 var v gather.WriteBuffer
292 defer v.Close()
293
294 err = cc.GetContent(ctx, "aa", "content-1", 0, 3, &v)
295 require.NoError(t, err, "write failure wasn't ignored")
296
297 got, want := v.ToByteSlice(), []byte{1, 2, 3}
298 require.Equal(t, want, got, "unexpected value retrieved from cache")
299
300 all, err := blob.ListAllBlobs(ctx, cacheStorage, "")
301 require.NoError(t, err, "error listing cache")
302
303 require.Empty(t, all, "invalid test - cache was written")
304}
305
306func TestCacheFailureToRead(t *testing.T) {
307 someError := errors.New("some error")

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
CloseMethod · 0.95
GetContentMethod · 0.95
ToByteSliceMethod · 0.95
NewMapStorageFunction · 0.92
NewFaultyStorageFunction · 0.92
NewContentCacheFunction · 0.92
ContextFunction · 0.92
ListAllBlobsFunction · 0.92
ErrorInsteadMethod · 0.80
AddFaultMethod · 0.80

Tested by

no test coverage detected