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

Function TestHTTPClient_shouldRetry

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

Source from the content-addressed store, hash-verified

449}
450
451func TestHTTPClient_shouldRetry(t *testing.T) {
452 client := NewHTTPClient(&http.Client{}, "https://test.example.com", testutils.NewTestLogger())
453
454 tests := []struct {
455 name string
456 err error
457 attempt int
458 maxRetries int
459 shouldRetry bool
460 }{
461 {
462 name: "connection error should retry",
463 err: fmt.Errorf("connection refused"),
464 attempt: 1,
465 maxRetries: 3,
466 shouldRetry: true,
467 },
468 {
469 name: "timeout error should retry",
470 err: fmt.Errorf("timeout exceeded"),
471 attempt: 1,
472 maxRetries: 3,
473 shouldRetry: true,
474 },
475 {
476 name: "5xx error should retry",
477 err: fmt.Errorf("API request failed with status 500"),
478 attempt: 1,
479 maxRetries: 3,
480 shouldRetry: true,
481 },
482 {
483 name: "4xx error should not retry",
484 err: fmt.Errorf("API request failed with status 400"),
485 attempt: 1,
486 maxRetries: 3,
487 shouldRetry: false,
488 },
489 {
490 name: "max retries reached should not retry",
491 err: fmt.Errorf("connection refused"),
492 attempt: 3,
493 maxRetries: 3,
494 shouldRetry: false,
495 },
496 }
497
498 for _, tt := range tests {
499 t.Run(tt.name, func(t *testing.T) {
500 result := client.shouldRetry(tt.err, tt.attempt, tt.maxRetries)
501 assert.Equal(t, tt.shouldRetry, result)
502 })
503 }
504}
505
506func TestHTTPClient_AuthenticationError(t *testing.T) {
507 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 4

shouldRetryMethod · 0.95
NewTestLoggerFunction · 0.92
NewHTTPClientFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected