(t *testing.T)
| 201 | } |
| 202 | |
| 203 | func TestAPIClient_Authentication(t *testing.T) { |
| 204 | mock := testutil.NewMockAPI() |
| 205 | defer mock.Close() |
| 206 | |
| 207 | mock.On("GET", "/monitors", 200, `{}`) |
| 208 | |
| 209 | client := newTestClient(mock.Server.URL) |
| 210 | client.ApiKey = "my-secret-key" |
| 211 | |
| 212 | // Need to bypass viper for this test - set the key directly |
| 213 | // The Request method reads from viper first, then falls back to client.ApiKey |
| 214 | _, err := client.GET("/monitors", nil) |
| 215 | if err != nil { |
| 216 | t.Fatalf("unexpected error: %v", err) |
| 217 | } |
| 218 | |
| 219 | req := mock.LastRequest() |
| 220 | authHeader := req.Headers.Get("Authorization") |
| 221 | if authHeader == "" { |
| 222 | t.Error("expected Authorization header to be set") |
| 223 | } |
| 224 | if !strings.HasPrefix(authHeader, "Basic ") { |
| 225 | t.Errorf("expected Basic auth, got %q", authHeader) |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | func TestAPIClient_Headers(t *testing.T) { |
| 230 | mock := testutil.NewMockAPI() |
nothing calls this directly
no test coverage detected