(t *testing.T)
| 252 | } |
| 253 | |
| 254 | func 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 |
nothing calls this directly
no test coverage detected