MCPcopy Create free account
hub / github.com/cronitorio/cronitor-cli / TestAPIClient_Authentication

Function TestAPIClient_Authentication

lib/api_client_test.go:203–227  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

201}
202
203func 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
229func TestAPIClient_Headers(t *testing.T) {
230 mock := testutil.NewMockAPI()

Callers

nothing calls this directly

Calls 8

CloseMethod · 0.95
OnMethod · 0.95
LastRequestMethod · 0.95
NewMockAPIFunction · 0.92
newTestClientFunction · 0.85
GETMethod · 0.80
GetMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected