MCPcopy Create free account
hub / github.com/docker/docker-agent / TestRegistry_DiskCacheFallback

Function TestRegistry_DiskCacheFallback

pkg/toolinstall/registry_test.go:254–284  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

252}
253
254func TestRegistry_DiskCacheFallback(t *testing.T) {
255 t.Parallel()
256
257 callCount := 0
258 mux := http.NewServeMux()
259 mux.HandleFunc("/registry.yaml", func(w http.ResponseWriter, _ *http.Request) {
260 callCount++
261 _, _ = w.Write([]byte(testRegistryYAML))
262 })
263 server := httptest.NewServer(mux)
264 t.Cleanup(server.Close)
265
266 registry := &Registry{
267 httpClient: server.Client(),
268 baseURL: server.URL,
269 cacheDir: filepath.Join(t.TempDir(), "cache"),
270 }
271
272 // First lookup: fetches from remote and writes to disk cache.
273 _, err := registry.LookupByCommand(t.Context(), "fzf")
274 require.NoError(t, err)
275 assert.Equal(t, 1, callCount)
276
277 // Stop the server to simulate remote failure.
278 server.Close()
279
280 // Second lookup: remote fails, falls back to disk cache.
281 pkg, err := registry.LookupByCommand(t.Context(), "fzf")
282 require.NoError(t, err)
283 assert.Equal(t, "junegunn", pkg.RepoOwner)
284}
285
286// --- GitHub auth tests ---
287

Callers

nothing calls this directly

Calls 5

LookupByCommandMethod · 0.95
ContextMethod · 0.80
CleanupMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected