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

Function TestAPIClient_MetricEndpoints

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

Source from the content-addressed store, hash-verified

965}
966
967func TestAPIClient_MetricEndpoints(t *testing.T) {
968 mock := testutil.NewMockAPI()
969 defer mock.Close()
970 client := newTestClient(mock.Server.URL)
971
972 t.Run("get metrics with params", func(t *testing.T) {
973 mock.Reset()
974 params := map[string]string{
975 "monitor": "abc123",
976 "field": "duration_p50,success_rate",
977 "time": "7d",
978 "env": "production",
979 "region": "us-east-1",
980 "withNulls": "true",
981 }
982 _, err := client.GET("/metrics", params)
983 if err != nil {
984 t.Fatalf("unexpected error: %v", err)
985 }
986 req := mock.LastRequest()
987 if req.Path != "/metrics" {
988 t.Errorf("expected /metrics, got %s", req.Path)
989 }
990 for k, v := range params {
991 if req.QueryParams.Get(k) != v {
992 t.Errorf("param %s: expected %q, got %q", k, v, req.QueryParams.Get(k))
993 }
994 }
995 })
996
997 t.Run("get aggregates", func(t *testing.T) {
998 mock.Reset()
999 _, err := client.GET("/aggregates", map[string]string{"monitor": "abc123"})
1000 if err != nil {
1001 t.Fatalf("unexpected error: %v", err)
1002 }
1003 req := mock.LastRequest()
1004 if req.Path != "/aggregates" {
1005 t.Errorf("expected /aggregates, got %s", req.Path)
1006 }
1007 })
1008}
1009
1010func TestAPIClient_SiteEndpoints(t *testing.T) {
1011 mock := testutil.NewMockAPI()

Callers

nothing calls this directly

Calls 7

CloseMethod · 0.95
ResetMethod · 0.95
LastRequestMethod · 0.95
NewMockAPIFunction · 0.92
newTestClientFunction · 0.85
GETMethod · 0.80
GetMethod · 0.80

Tested by

no test coverage detected