MCPcopy
hub / github.com/kopia/kopia / TestNewStorageOrNil

Function TestNewStorageOrNil

internal/cache/cache_storage_test.go:15–46  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestNewStorageOrNil(t *testing.T) {
16 ctx := testlogging.Context(t)
17
18 // empty cache dir
19 st, err := NewStorageOrNil(ctx, "", 1000, "subdir")
20 require.NoError(t, err)
21 require.Nil(t, st)
22
23 // zero size
24 st, err = NewStorageOrNil(ctx, testutil.TempDirectory(t), 0, "subdir")
25 require.NoError(t, err)
26 require.Nil(t, st)
27
28 _, err = NewStorageOrNil(ctx, "relative/path/to/cache/dir", 1000, "subdir")
29 require.Error(t, err)
30
31 someError := errors.New("some error")
32
33 oldMkdirAll := mkdirAll
34
35 mkdirAll = func(path string, mode os.FileMode) error {
36 return someError
37 }
38
39 defer func() {
40 mkdirAll = oldMkdirAll
41 }()
42
43 _, err = NewStorageOrNil(ctx, filepath.Join(testutil.TempDirectory(t), "some-subdir"), 1000, "subdir")
44
45 require.ErrorIs(t, err, someError)
46}

Callers

nothing calls this directly

Calls 4

ContextFunction · 0.92
TempDirectoryFunction · 0.92
NewStorageOrNilFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected