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

Function TestRuler_RulerGroupLimits

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

Source from the content-addressed store, hash-verified

653}
654
655func TestRuler_RulerGroupLimits(t *testing.T) {
656 store := newMockRuleStore(make(map[string]rulespb.RuleGroupList), nil)
657 cfg := defaultRulerConfig(t)
658
659 r := newTestRuler(t, cfg, store, nil)
660 defer services.StopAndAwaitTerminated(context.Background(), r) //nolint:errcheck
661
662 r.limits = &ruleLimits{maxRuleGroups: 1, maxRulesPerRuleGroup: 1}
663
664 a := NewAPI(r, r.store, log.NewNopLogger())
665
666 tc := []struct {
667 name string
668 input string
669 output string
670 err error
671 status int
672 }{
673 {
674 name: "when pushing the first group within bounds of the limit",
675 status: 202,
676 input: `
677name: test_first_group_will_succeed
678interval: 15s
679rules:
680- record: up_rule
681 expr: up{}
682`,
683 output: "{\"status\":\"success\"}",
684 },
685 {
686 name: "when exceeding the rule group limit after sending the first group",
687 status: 400,
688 input: `
689name: test_second_group_will_fail
690interval: 15s
691rules:
692- record: up_rule
693 expr: up{}
694`,
695 output: "per-user rule groups limit (limit: 1 actual: 2) exceeded\n",
696 },
697 }
698
699 // define once so the requests build on each other so the number of rules can be tested
700 router := mux.NewRouter()
701 router.Path("/api/v1/rules/{namespace}").Methods("POST").HandlerFunc(a.CreateRuleGroup)
702
703 for _, tt := range tc {
704 t.Run(tt.name, func(t *testing.T) {
705 // POST
706 req := requestFor(t, http.MethodPost, "https://localhost:8080/api/v1/rules/namespace", strings.NewReader(tt.input), "user1")
707 w := httptest.NewRecorder()
708
709 router.ServeHTTP(w, req)
710 require.Equal(t, tt.status, w.Code)
711 require.Equal(t, tt.output, w.Body.String())
712 })

Callers

nothing calls this directly

Calls 10

StopAndAwaitTerminatedFunction · 0.92
newMockRuleStoreFunction · 0.85
defaultRulerConfigFunction · 0.85
newTestRulerFunction · 0.85
requestForFunction · 0.85
NewAPIFunction · 0.70
RunMethod · 0.65
EqualMethod · 0.65
StringMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected