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

Function TestAPIClient_EnvironmentEndpoints

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

Source from the content-addressed store, hash-verified

749}
750
751func TestAPIClient_EnvironmentEndpoints(t *testing.T) {
752 mock := testutil.NewMockAPI()
753 defer mock.Close()
754 client := newTestClient(mock.Server.URL)
755
756 tests := []struct {
757 name string
758 do func() (*lib.APIResponse, error)
759 method string
760 path string
761 }{
762 {"list", func() (*lib.APIResponse, error) { return client.GET("/environments", nil) }, "GET", "/environments"},
763 {"get", func() (*lib.APIResponse, error) { return client.GET("/environments/prod", nil) }, "GET", "/environments/prod"},
764 {"create", func() (*lib.APIResponse, error) {
765 return client.POST("/environments", []byte(`{"key":"staging"}`), nil)
766 }, "POST", "/environments"},
767 {"update", func() (*lib.APIResponse, error) {
768 return client.PUT("/environments/staging", []byte(`{"name":"QA"}`), nil)
769 }, "PUT", "/environments/staging"},
770 {"delete", func() (*lib.APIResponse, error) { return client.DELETE("/environments/old", nil, nil) }, "DELETE", "/environments/old"},
771 }
772
773 for _, tt := range tests {
774 t.Run(tt.name, func(t *testing.T) {
775 mock.Reset()
776 _, err := tt.do()
777 if err != nil {
778 t.Fatalf("unexpected error: %v", err)
779 }
780 req := mock.LastRequest()
781 if req.Method != tt.method {
782 t.Errorf("expected %s, got %s", tt.method, req.Method)
783 }
784 if req.Path != tt.path {
785 t.Errorf("expected %s, got %s", tt.path, req.Path)
786 }
787 })
788 }
789}
790
791func TestAPIClient_NotificationEndpoints(t *testing.T) {
792 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