MCPcopy Index your code
hub / github.com/docker/docker-agent / TestFileCache_persists

Function TestFileCache_persists

pkg/cache/cache_test.go:122–144  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

120}
121
122func TestFileCache_persists(t *testing.T) {
123 t.Parallel()
124 dir := t.TempDir()
125 path := filepath.Join(dir, "cache.json")
126
127 c1, err := New(Config{Enabled: true, Path: path, CaseSensitive: false, TrimSpaces: true})
128 require.NoError(t, err)
129 c1.Store(" Hello ", "world")
130
131 // File must exist on disk and contain the normalized key.
132 data, err := os.ReadFile(path)
133 require.NoError(t, err)
134 var entries map[string]string
135 require.NoError(t, json.Unmarshal(data, &entries))
136 assert.Equal(t, map[string]string{"hello": "world"}, entries)
137
138 // A new cache loaded from the same file recovers the entries.
139 c2, err := New(Config{Enabled: true, Path: path, CaseSensitive: false, TrimSpaces: true})
140 require.NoError(t, err)
141 got, ok := c2.Lookup("HELLO")
142 assert.True(t, ok)
143 assert.Equal(t, "world", got)
144}
145
146func TestFileCache_missingFileIsFine(t *testing.T) {
147 t.Parallel()

Callers

nothing calls this directly

Calls 4

ReadFileMethod · 0.80
NewFunction · 0.70
StoreMethod · 0.45
LookupMethod · 0.45

Tested by

no test coverage detected