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

Function TestHTTPClient_AuthenticationError

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

Source from the content-addressed store, hash-verified

504}
505
506func TestHTTPClient_AuthenticationError(t *testing.T) {
507 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
508 w.WriteHeader(http.StatusOK)
509 _ = json.NewEncoder(w).Encode(map[string]interface{}{"success": true})
510 }))
511 defer server.Close()
512
513 client := NewHTTPClient(server.Client(), server.URL, testutils.NewTestLogger())
514
515 // Create auth manager that will fail authentication
516 authManager := NewAuthManagerWithPassword(
517 NewHTTPClient(&http.Client{}, "http://invalid-auth-server.local", testutils.NewTestLogger()),
518 "user", "pass", testutils.NewTestLogger(),
519 )
520 client.SetAuthManager(authManager)
521
522 var result map[string]interface{}
523 err := client.Get(context.Background(), "/test", &result)
524
525 require.Error(t, err)
526 assert.Contains(t, err.Error(), "authentication failed")
527}
528
529func TestHTTPClient_MarshalError(t *testing.T) {
530 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected