(t *testing.T)
| 398 | } |
| 399 | |
| 400 | func 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 | |
| 430 | func TestHTTPClient_GetWithRetry_MaxRetriesExceeded(t *testing.T) { |
| 431 | attemptCount := 0 |
nothing calls this directly
no test coverage detected