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

Function TestAPIClient_IssueEndpoints

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

Source from the content-addressed store, hash-verified

829}
830
831func TestAPIClient_IssueEndpoints(t *testing.T) {
832 mock := testutil.NewMockAPI()
833 defer mock.Close()
834 client := newTestClient(mock.Server.URL)
835
836 tests := []struct {
837 name string
838 do func() (*lib.APIResponse, error)
839 method string
840 path string
841 wantBody string
842 }{
843 {"list", func() (*lib.APIResponse, error) { return client.GET("/issues", nil) }, "GET", "/issues", ""},
844 {"get", func() (*lib.APIResponse, error) { return client.GET("/issues/issue-001", nil) }, "GET", "/issues/issue-001", ""},
845 {"create", func() (*lib.APIResponse, error) {
846 return client.POST("/issues", []byte(`{"name":"DB issue","severity":"outage"}`), nil)
847 }, "POST", "/issues", `{"name":"DB issue","severity":"outage"}`},
848 {"update", func() (*lib.APIResponse, error) {
849 return client.PUT("/issues/issue-001", []byte(`{"state":"investigating"}`), nil)
850 }, "PUT", "/issues/issue-001", `{"state":"investigating"}`},
851 {"resolve", func() (*lib.APIResponse, error) {
852 return client.PUT("/issues/issue-001", []byte(`{"state":"resolved"}`), nil)
853 }, "PUT", "/issues/issue-001", `{"state":"resolved"}`},
854 {"delete", func() (*lib.APIResponse, error) { return client.DELETE("/issues/issue-001", nil, nil) }, "DELETE", "/issues/issue-001", ""},
855 }
856
857 for _, tt := range tests {
858 t.Run(tt.name, func(t *testing.T) {
859 mock.Reset()
860 _, err := tt.do()
861 if err != nil {
862 t.Fatalf("unexpected error: %v", err)
863 }
864 req := mock.LastRequest()
865 if req.Method != tt.method {
866 t.Errorf("expected %s, got %s", tt.method, req.Method)
867 }
868 if req.Path != tt.path {
869 t.Errorf("expected %s, got %s", tt.path, req.Path)
870 }
871 if tt.wantBody != "" && req.Body != tt.wantBody {
872 t.Errorf("expected body %q, got %q", tt.wantBody, req.Body)
873 }
874 })
875 }
876}
877
878func TestAPIClient_MaintenanceEndpoints(t *testing.T) {
879 mock := testutil.NewMockAPI()

Callers

nothing calls this directly

Calls 9

CloseMethod · 0.95
ResetMethod · 0.95
LastRequestMethod · 0.95
NewMockAPIFunction · 0.92
newTestClientFunction · 0.85
GETMethod · 0.80
POSTMethod · 0.80
PUTMethod · 0.80
DELETEMethod · 0.80

Tested by

no test coverage detected