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

Function TestHTTPClient_ContextCancellation

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

Source from the content-addressed store, hash-verified

376}
377
378func TestHTTPClient_ContextCancellation(t *testing.T) {
379 // Create server that delays response to test context cancellation
380 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
381 // Wait longer than the context timeout
382 time.Sleep(200 * time.Millisecond)
383 w.WriteHeader(http.StatusOK)
384 }))
385 defer server.Close()
386
387 client := NewHTTPClient(server.Client(), server.URL, testutils.NewTestLogger())
388
389 // Create context with short timeout
390 ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
391 defer cancel()
392
393 var result map[string]interface{}
394 err := client.Get(ctx, "/test", &result)
395
396 require.Error(t, err)
397 assert.Contains(t, err.Error(), "context deadline exceeded")
398}
399
400func TestHTTPClient_GetWithRetry_Success(t *testing.T) {
401 attemptCount := 0

Callers

nothing calls this directly

Calls 6

GetMethod · 0.95
NewTestLoggerFunction · 0.92
NewHTTPClientFunction · 0.85
ClientMethod · 0.80
CloseMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected