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

Function TestAPIClient_POST

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

Source from the content-addressed store, hash-verified

108}
109
110func TestAPIClient_POST(t *testing.T) {
111 mock := testutil.NewMockAPI()
112 defer mock.Close()
113
114 mock.On("POST", "/monitors", 201, `{"key":"new-mon","name":"New Monitor"}`)
115
116 client := newTestClient(mock.Server.URL)
117 body := []byte(`{"key":"new-mon","name":"New Monitor","type":"job"}`)
118 resp, err := client.POST("/monitors", body, nil)
119 if err != nil {
120 t.Fatalf("unexpected error: %v", err)
121 }
122
123 if resp.StatusCode != 201 {
124 t.Errorf("expected status 201, got %d", resp.StatusCode)
125 }
126
127 req := mock.LastRequest()
128 if req.Method != "POST" {
129 t.Errorf("expected POST, got %s", req.Method)
130 }
131 if req.Body != string(body) {
132 t.Errorf("expected body %q, got %q", string(body), req.Body)
133 }
134}
135
136func TestAPIClient_PUT(t *testing.T) {
137 mock := testutil.NewMockAPI()

Callers

nothing calls this directly

Calls 6

CloseMethod · 0.95
OnMethod · 0.95
LastRequestMethod · 0.95
NewMockAPIFunction · 0.92
newTestClientFunction · 0.85
POSTMethod · 0.80

Tested by

no test coverage detected