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

Function TestAPIClient_500_ServerError

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

Source from the content-addressed store, hash-verified

371}
372
373func TestAPIClient_500_ServerError(t *testing.T) {
374 mock := testutil.NewMockAPI()
375 defer mock.Close()
376
377 errBody := testutil.LoadFixture("error_responses/500.json")
378 mock.On("GET", "/monitors", 500, errBody)
379
380 client := newTestClient(mock.Server.URL)
381 resp, err := client.GET("/monitors", nil)
382 if err != nil {
383 t.Fatalf("unexpected error: %v", err)
384 }
385
386 if resp.StatusCode != 500 {
387 t.Errorf("expected 500, got %d", resp.StatusCode)
388 }
389 if resp.IsSuccess() {
390 t.Error("expected IsSuccess() to be false")
391 }
392
393 parsed := resp.ParseError()
394 if !strings.Contains(parsed, "Internal server error") {
395 t.Errorf("expected 'Internal server error', got %q", parsed)
396 }
397}
398
399func TestAPIClient_NetworkError(t *testing.T) {
400 // Create a server and immediately close it to simulate connection refused

Callers

nothing calls this directly

Calls 9

CloseMethod · 0.95
OnMethod · 0.95
NewMockAPIFunction · 0.92
LoadFixtureFunction · 0.92
newTestClientFunction · 0.85
GETMethod · 0.80
IsSuccessMethod · 0.80
ErrorMethod · 0.80
ParseErrorMethod · 0.80

Tested by

no test coverage detected