(t *testing.T)
| 272 | } |
| 273 | |
| 274 | func TestURLSource_Read_HTTPError(t *testing.T) { |
| 275 | t.Parallel() |
| 276 | |
| 277 | tests := []struct { |
| 278 | name string |
| 279 | statusCode int |
| 280 | }{ |
| 281 | {"not found", http.StatusNotFound}, |
| 282 | {"server error", http.StatusInternalServerError}, |
| 283 | } |
| 284 | |
| 285 | for _, tt := range tests { |
| 286 | t.Run(tt.name, func(t *testing.T) { |
| 287 | t.Parallel() |
| 288 | |
| 289 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| 290 | w.WriteHeader(tt.statusCode) |
| 291 | })) |
| 292 | t.Cleanup(server.Close) |
| 293 | |
| 294 | // Clean up any cached data for this URL to ensure we test the error path |
| 295 | urlCacheDir := getURLCacheDir() |
| 296 | urlHash := hashURL(server.URL) |
| 297 | cachePath := filepath.Join(urlCacheDir, urlHash) |
| 298 | etagPath := cachePath + ".etag" |
| 299 | _ = os.Remove(cachePath) |
| 300 | _ = os.Remove(etagPath) |
| 301 | |
| 302 | _, err := newURLSourceForTest(server.URL, nil).Read(t.Context()) |
| 303 | require.Error(t, err) |
| 304 | }) |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | func TestURLSource_Read_ConnectionError(t *testing.T) { |
| 309 | t.Parallel() |
nothing calls this directly
no test coverage detected