MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestRuler_rules_limit

Function TestRuler_rules_limit

pkg/ruler/api_test.go:367–423  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

365}
366
367func TestRuler_rules_limit(t *testing.T) {
368 store := newMockRuleStore(mockRulesLimit, nil)
369 cfg := defaultRulerConfig(t)
370
371 r := newTestRuler(t, cfg, store, nil)
372 defer services.StopAndAwaitTerminated(context.Background(), r) //nolint:errcheck
373
374 a := NewAPI(r, r.store, log.NewNopLogger())
375
376 req := requestFor(t, http.MethodGet, "https://localhost:8080/api/prom/api/v1/rules", nil, "user1")
377 w := httptest.NewRecorder()
378 a.PrometheusRules(w, req)
379
380 resp := w.Result()
381 body, _ := io.ReadAll(resp.Body)
382 // Check status code and status response
383 responseJSON := util_api.Response{}
384 err := json.Unmarshal(body, &responseJSON)
385 require.NoError(t, err)
386 require.Equal(t, http.StatusOK, resp.StatusCode)
387 require.Equal(t, responseJSON.Status, "success")
388 stripEvaluationFields(t, responseJSON)
389 actual, err := json.Marshal(responseJSON)
390 require.NoError(t, err)
391
392 // Testing the running rules for user1 in the mock store
393 expectedResponse, _ := json.Marshal(util_api.Response{
394 Status: "success",
395 Data: &RuleDiscovery{
396 RuleGroups: []*RuleGroup{
397 {
398 Name: "group1",
399 File: "namespace1",
400 Limit: 5,
401 Rules: []rule{
402 &recordingRule{
403 Name: "UP_RULE",
404 Query: "up",
405 Health: "unknown",
406 Type: "recording",
407 },
408 &alertingRule{
409 Name: "UP_ALERT",
410 Query: "up < 1",
411 State: "unknown",
412 Health: "unknown",
413 Type: "alerting",
414 Alerts: []*Alert{},
415 },
416 },
417 Interval: 10,
418 },
419 },
420 },
421 })
422 require.JSONEq(t, string(expectedResponse), string(actual))
423}
424

Callers

nothing calls this directly

Calls 11

PrometheusRulesMethod · 0.95
StopAndAwaitTerminatedFunction · 0.92
newMockRuleStoreFunction · 0.85
defaultRulerConfigFunction · 0.85
newTestRulerFunction · 0.85
requestForFunction · 0.85
stripEvaluationFieldsFunction · 0.85
NewAPIFunction · 0.70
EqualMethod · 0.65
UnmarshalMethod · 0.45
MarshalMethod · 0.45

Tested by

no test coverage detected