MCPcopy
hub / github.com/filebrowser/filebrowser / TestFileCache

Function TestFileCache

diskcache/file_cache_test.go:12–41  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestFileCache(t *testing.T) {
13 ctx := context.Background()
14 const (
15 key = "key"
16 value = "some text"
17 newValue = "new text"
18 cacheRoot = "/cache"
19 cachedFilePath = "a/62/a62f2225bf70bfaccbc7f1ef2a397836717377de"
20 )
21
22 fs := afero.NewMemMapFs()
23 cache := New(fs, "/cache")
24
25 // store new key
26 err := cache.Store(ctx, key, []byte(value))
27 require.NoError(t, err)
28 checkValue(ctx, t, fs, filepath.Join(cacheRoot, cachedFilePath), cache, key, value)
29
30 // update existing key
31 err = cache.Store(ctx, key, []byte(newValue))
32 require.NoError(t, err)
33 checkValue(ctx, t, fs, filepath.Join(cacheRoot, cachedFilePath), cache, key, newValue)
34
35 // delete key
36 err = cache.Delete(ctx, key)
37 require.NoError(t, err)
38 exists, err := afero.Exists(fs, filepath.Join(cacheRoot, cachedFilePath))
39 require.NoError(t, err)
40 require.False(t, exists)
41}
42
43func checkValue(ctx context.Context, t *testing.T, fs afero.Fs, fileFullPath string, cache *FileCache, key, wantValue string) {
44 t.Helper()

Callers

nothing calls this directly

Calls 4

checkValueFunction · 0.85
NewFunction · 0.70
StoreMethod · 0.65
DeleteMethod · 0.65

Tested by

no test coverage detected