(t *testing.T)
| 263 | } |
| 264 | |
| 265 | func 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 | |
| 293 | func TestAuthManager_authenticate_InvalidJSON(t *testing.T) { |
| 294 | // Create a test server that returns invalid JSON |
nothing calls this directly
no test coverage detected