MCPcopy
hub / github.com/docker/docker-agent / TestURLSource_Read_HTTPError

Function TestURLSource_Read_HTTPError

pkg/config/sources_test.go:274–306  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

272}
273
274func 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
308func TestURLSource_Read_ConnectionError(t *testing.T) {
309 t.Parallel()

Callers

nothing calls this directly

Calls 9

getURLCacheDirFunction · 0.85
hashURLFunction · 0.85
newURLSourceForTestFunction · 0.85
ContextMethod · 0.80
RunMethod · 0.65
CleanupMethod · 0.65
ReadMethod · 0.65
RemoveMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected