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

Function TestVersionHeader_AppliesAcrossAllMethods

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

Source from the content-addressed store, hash-verified

1238}
1239
1240func TestVersionHeader_AppliesAcrossAllMethods(t *testing.T) {
1241 mock := testutil.NewMockAPI()
1242 defer mock.Close()
1243
1244 mock.SetDefault(200, `{}`)
1245
1246 viper.Set("CRONITOR_API_VERSION", "2025-11-28")
1247 defer viper.Set("CRONITOR_API_VERSION", "")
1248
1249 client := newTestClient(mock.Server.URL)
1250
1251 methods := []struct {
1252 name string
1253 do func() (*lib.APIResponse, error)
1254 }{
1255 {"GET", func() (*lib.APIResponse, error) { return client.GET("/test", nil) }},
1256 {"POST", func() (*lib.APIResponse, error) { return client.POST("/test", []byte(`{}`), nil) }},
1257 {"PUT", func() (*lib.APIResponse, error) { return client.PUT("/test", []byte(`{}`), nil) }},
1258 {"DELETE", func() (*lib.APIResponse, error) { return client.DELETE("/test", nil, nil) }},
1259 {"PATCH", func() (*lib.APIResponse, error) { return client.PATCH("/test", []byte(`{}`), nil) }},
1260 }
1261
1262 for _, m := range methods {
1263 t.Run(m.name, func(t *testing.T) {
1264 mock.Reset()
1265 _, err := m.do()
1266 if err != nil {
1267 t.Fatalf("unexpected error: %v", err)
1268 }
1269
1270 req := mock.LastRequest()
1271 if cv := req.Headers.Get("Cronitor-Version"); cv != "2025-11-28" {
1272 t.Errorf("%s: expected Cronitor-Version 2025-11-28, got %q", m.name, cv)
1273 }
1274 })
1275 }
1276}
1277
1278func TestVersionHeader_NotSentAcrossAllMethods(t *testing.T) {
1279 mock := testutil.NewMockAPI()

Callers

nothing calls this directly

Calls 12

CloseMethod · 0.95
SetDefaultMethod · 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
PATCHMethod · 0.80
GetMethod · 0.80

Tested by

no test coverage detected