(t *testing.T)
| 177 | } |
| 178 | |
| 179 | func 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 | |
| 207 | func TestRegistry_SendsAuthHeader(t *testing.T) { |
| 208 | t.Setenv("GITHUB_TOKEN", "ghp_test_registry_token") |
nothing calls this directly
no test coverage detected