MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestRuler_ProtoToRuleGroupYamlConvertion

Function TestRuler_ProtoToRuleGroupYamlConvertion

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

Source from the content-addressed store, hash-verified

714}
715
716func TestRuler_ProtoToRuleGroupYamlConvertion(t *testing.T) {
717 store := newMockRuleStore(make(map[string]rulespb.RuleGroupList), nil)
718 cfg := defaultRulerConfig(t)
719
720 r := newTestRuler(t, cfg, store, nil)
721 defer services.StopAndAwaitTerminated(context.Background(), r) //nolint:errcheck
722
723 a := NewAPI(r, r.store, log.NewNopLogger())
724
725 tc := []struct {
726 name string
727 input string
728 output string
729 err error
730 status int
731 }{
732 {
733 name: "when pushing group that can be safely converted from RuleGroupDesc to RuleGroup yaml",
734 status: 202,
735 input: `
736name: test_first_group_will_succeed
737interval: 15s
738rules:
739- record: up_rule
740 expr: |2+
741 up{}
742`,
743 output: "{\"status\":\"success\"}",
744 },
745 {
746 name: "when pushing group that CANNOT be safely converted from RuleGroupDesc to RuleGroup yaml",
747 status: 400,
748 input: `
749name: test_first_group_will_succeed
750interval: 15s
751rules:
752- record: up_rule
753 expr: |2+
754
755 up{}
756`,
757 output: "unable to decoded rule group\n",
758 },
759 }
760
761 router := mux.NewRouter()
762 router.Path("/api/v1/rules/{namespace}").Methods("POST").HandlerFunc(a.CreateRuleGroup)
763
764 for _, tt := range tc {
765 t.Run(tt.name, func(t *testing.T) {
766 // POST
767 req := requestFor(t, http.MethodPost, "https://localhost:8080/api/v1/rules/namespace", strings.NewReader(tt.input), "user1")
768 w := httptest.NewRecorder()
769
770 router.ServeHTTP(w, req)
771 require.Equal(t, tt.status, w.Code)
772 require.Equal(t, tt.output, w.Body.String())
773 })

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