MCPcopy
hub / github.com/kopia/kopia / TestCacheFailureToRead

Function TestCacheFailureToRead

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

Source from the content-addressed store, hash-verified

304}
305
306func TestCacheFailureToRead(t *testing.T) {
307 someError := errors.New("some error")
308
309 cacheData := blobtesting.DataMap{}
310 cacheStorage := blobtesting.NewMapStorage(cacheData, nil, nil)
311 underlyingStorage := newUnderlyingStorageForContentCacheTesting(t)
312 faultyCache := blobtesting.NewFaultyStorage(cacheStorage)
313
314 cc, err := cache.NewContentCache(testlogging.Context(t), underlyingStorage, cache.Options{
315 Storage: withoutTouchBlob{faultyCache},
316 Sweep: cache.SweepSettings{MaxSizeBytes: 10000},
317 }, nil)
318 require.NoError(t, err)
319
320 ctx := testlogging.Context(t)
321
322 defer cc.Close(ctx)
323
324 faultyCache.AddFault(blobtesting.MethodGetBlob).ErrorInstead(someError).Repeat(100)
325
326 var v gather.WriteBuffer
327 defer v.Close()
328
329 for range 2 {
330 require.NoError(t, cc.GetContent(ctx, "aa", "content-1", 0, 3, &v))
331
332 got, want := v.ToByteSlice(), []byte{1, 2, 3}
333 assert.Equal(t, want, got, "unexpected value retrieved from cache")
334 }
335}
336
337func verifyStorageContentList(t *testing.T, st cache.Storage, expectedContents ...blob.ID) {
338 t.Helper()

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
RepeatMethod · 0.80
ErrorInsteadMethod · 0.80
AddFaultMethod · 0.80

Tested by

no test coverage detected