MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / TestHTTPClient_GetWithRetry_Success

Function TestHTTPClient_GetWithRetry_Success

pkg/api/http_test.go:400–428  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

398}
399
400func TestHTTPClient_GetWithRetry_Success(t *testing.T) {
401 attemptCount := 0
402
403 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
404 attemptCount++
405 if attemptCount < 3 {
406 // Fail first two attempts
407 w.WriteHeader(http.StatusInternalServerError)
408
409 return
410 }
411
412 // Succeed on third attempt
413 response := map[string]interface{}{"success": true}
414
415 w.Header().Set("Content-Type", "application/json")
416 _ = json.NewEncoder(w).Encode(response)
417 }))
418 defer server.Close()
419
420 client := NewHTTPClient(server.Client(), server.URL, testutils.NewTestLogger())
421
422 var result map[string]interface{}
423 err := client.GetWithRetry(context.Background(), "/test", &result, 3)
424
425 require.NoError(t, err)
426 assert.True(t, result["success"].(bool))
427 assert.Equal(t, 3, attemptCount)
428}
429
430func TestHTTPClient_GetWithRetry_MaxRetriesExceeded(t *testing.T) {
431 attemptCount := 0

Callers

nothing calls this directly

Calls 7

GetWithRetryMethod · 0.95
NewTestLoggerFunction · 0.92
NewHTTPClientFunction · 0.85
HeaderMethod · 0.80
ClientMethod · 0.80
SetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected