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

Function TestAuthManager_authenticate_HTTPError

pkg/api/auth_test.go:265–291  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

263}
264
265func TestAuthManager_authenticate_HTTPError(t *testing.T) {
266 // Create a test server that returns an error
267 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
268 if r.URL.Path == testEndpoint {
269 w.WriteHeader(http.StatusUnauthorized)
270 _, _ = w.Write([]byte("Authentication failed"))
271
272 return
273 }
274
275 http.NotFound(w, r)
276 }))
277 defer server.Close()
278
279 httpClient := &HTTPClient{
280 baseURL: server.URL,
281 client: server.Client(),
282 }
283 logger := testutils.NewTestLogger()
284
285 authManager := NewAuthManagerWithPassword(httpClient, "testuser", "wrongpass", logger)
286
287 token, err := authManager.authenticate(context.Background())
288 assert.Error(t, err)
289 assert.Nil(t, token)
290 assert.Contains(t, err.Error(), "authentication failed with status 401")
291}
292
293func TestAuthManager_authenticate_InvalidJSON(t *testing.T) {
294 // Create a test server that returns invalid JSON

Callers

nothing calls this directly

Calls 6

NewTestLoggerFunction · 0.92
ClientMethod · 0.80
authenticateMethod · 0.80
CloseMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected