(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func 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 | |
| 43 | func checkValue(ctx context.Context, t *testing.T, fs afero.Fs, fileFullPath string, cache *FileCache, key, wantValue string) { |
| 44 | t.Helper() |
nothing calls this directly
no test coverage detected