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

Function TestRuler_Rules

pkg/ruler/ruler_test.go:607–635  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

605}
606
607func TestRuler_Rules(t *testing.T) {
608 store := newMockRuleStore(mockRules, nil)
609 cfg := defaultRulerConfig(t)
610
611 r := newTestRuler(t, cfg, store, nil)
612 defer services.StopAndAwaitTerminated(context.Background(), r) //nolint:errcheck
613
614 // test user1
615 ctx := user.InjectOrgID(context.Background(), "user1")
616 rls, err := r.Rules(ctx, &RulesRequest{
617 MaxRuleGroups: -1,
618 })
619 require.NoError(t, err)
620 require.Len(t, rls.Groups, 1)
621 rg := rls.Groups[0]
622 expectedRg := mockRules["user1"][0]
623 compareRuleGroupDescToStateDesc(t, expectedRg, rg)
624
625 // test user2
626 ctx = user.InjectOrgID(context.Background(), "user2")
627 rls, err = r.Rules(ctx, &RulesRequest{
628 MaxRuleGroups: -1,
629 })
630 require.NoError(t, err)
631 require.Len(t, rls.Groups, 1)
632 rg = rls.Groups[0]
633 expectedRg = mockRules["user2"][0]
634 compareRuleGroupDescToStateDesc(t, expectedRg, rg)
635}
636
637func compareRuleGroupDescToStateDesc(t *testing.T, expected *rulespb.RuleGroupDesc, got *GroupStateDesc) {
638 require.Equal(t, got.Group.Name, expected.Name)

Callers

nothing calls this directly

Calls 7

StopAndAwaitTerminatedFunction · 0.92
newMockRuleStoreFunction · 0.85
defaultRulerConfigFunction · 0.85
newTestRulerFunction · 0.85
RulesMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected