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

Function TestRegistry_CacheFallback

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

Source from the content-addressed store, hash-verified

177}
178
179func TestRegistry_CacheFallback(t *testing.T) {
180 t.Parallel()
181
182 cacheDir := filepath.Join(t.TempDir(), "cache")
183 cachePath := filepath.Join(cacheDir, "registry.yaml")
184 require.NoError(t, os.MkdirAll(cacheDir, 0o755))
185 require.NoError(t, os.WriteFile(cachePath, []byte(testRegistryYAML), 0o644))
186
187 // Server always returns 500.
188 mux := http.NewServeMux()
189 mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
190 w.WriteHeader(http.StatusInternalServerError)
191 })
192 server := httptest.NewServer(mux)
193 t.Cleanup(server.Close)
194
195 registry := &Registry{
196 httpClient: server.Client(),
197 baseURL: server.URL,
198 cacheDir: cacheDir,
199 }
200
201 // Should fall back to stale cache.
202 pkg, err := registry.LookupByCommand(t.Context(), "fzf")
203 require.NoError(t, err)
204 assert.Equal(t, "junegunn", pkg.RepoOwner)
205}
206
207func TestRegistry_SendsAuthHeader(t *testing.T) {
208 t.Setenv("GITHUB_TOKEN", "ghp_test_registry_token")

Callers

nothing calls this directly

Calls 3

LookupByCommandMethod · 0.95
ContextMethod · 0.80
CleanupMethod · 0.65

Tested by

no test coverage detected