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

Function TestSendAlerts

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

Source from the content-addressed store, hash-verified

2683}
2684
2685func TestSendAlerts(t *testing.T) {
2686 testCases := []struct {
2687 in []*promRules.Alert
2688 exp []*notifier.Alert
2689 }{
2690 {
2691 in: []*promRules.Alert{
2692 {
2693 Labels: labels.FromStrings("l1", "v1"),
2694 Annotations: labels.FromStrings("a2", "v2"),
2695 ActiveAt: time.Unix(1, 0),
2696 FiredAt: time.Unix(2, 0),
2697 ValidUntil: time.Unix(3, 0),
2698 },
2699 },
2700 exp: []*notifier.Alert{
2701 {
2702 Labels: labels.FromStrings("l1", "v1"),
2703 Annotations: labels.FromStrings("a2", "v2"),
2704 StartsAt: time.Unix(2, 0),
2705 EndsAt: time.Unix(3, 0),
2706 GeneratorURL: "http://localhost:9090/graph?g0.expr=up&g0.tab=1",
2707 },
2708 },
2709 },
2710 {
2711 in: []*promRules.Alert{
2712 {
2713 Labels: labels.FromStrings("l1", "v1"),
2714 Annotations: labels.FromStrings("a2", "v2"),
2715 ActiveAt: time.Unix(1, 0),
2716 FiredAt: time.Unix(2, 0),
2717 ResolvedAt: time.Unix(4, 0),
2718 },
2719 },
2720 exp: []*notifier.Alert{
2721 {
2722 Labels: labels.FromStrings("l1", "v1"),
2723 Annotations: labels.FromStrings("a2", "v2"),
2724 StartsAt: time.Unix(2, 0),
2725 EndsAt: time.Unix(4, 0),
2726 GeneratorURL: "http://localhost:9090/graph?g0.expr=up&g0.tab=1",
2727 },
2728 },
2729 },
2730 {
2731 in: []*promRules.Alert{},
2732 },
2733 }
2734
2735 for i, tc := range testCases {
2736 t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
2737 senderFunc := senderFunc(func(alerts ...*notifier.Alert) {
2738 if len(tc.in) == 0 {
2739 t.Fatalf("sender called with 0 alert")
2740 }
2741 require.Equal(t, tc.exp, alerts)
2742 })

Callers

nothing calls this directly

Calls 4

senderFuncFuncType · 0.85
SendAlertsFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected