This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
/
alerting_notification_policy_test.go
109 lines (96 loc) · 1.97 KB
/
alerting_notification_policy_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
func TestNotificationPolicies(t *testing.T) {
t.Run("get policy tree succeeds", func(t *testing.T) {
client := gapiTestTools(t, 200, notificationPolicyJSON)
np, err := client.NotificationPolicyTree()
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(np))
if np.Receiver != "grafana-default-email" {
t.Errorf("wrong receiver, got %#v", np.Receiver)
}
if len(np.Routes) != 1 {
t.Errorf("wrong number of routes returned, got %#v", np)
}
})
t.Run("set policy tree succeeds", func(t *testing.T) {
client := gapiTestTools(t, 202, `{"message":"created"}`)
np := createNotificationPolicy()
err := client.SetNotificationPolicyTree(&np)
if err != nil {
t.Error(err)
}
})
t.Run("reset policy tree succeeds", func(t *testing.T) {
client := gapiTestTools(t, 200, notificationPolicyJSON)
err := client.ResetNotificationPolicyTree()
if err != nil {
t.Error(err)
}
})
}
func createNotificationPolicy() NotificationPolicyTree {
return NotificationPolicyTree{
Receiver: "grafana-default-email",
GroupBy: []string{"asdfasdf", "alertname"},
Routes: []SpecificPolicy{
{
Receiver: "grafana-default-email",
ObjectMatchers: Matchers{
{
Type: MatchNotEqual,
Name: "abc",
Value: "def",
},
},
Continue: true,
},
{
Receiver: "grafana-default-email",
ObjectMatchers: Matchers{
{
Type: MatchRegexp,
Name: "jkl",
Value: "something.*",
},
},
Continue: false,
},
},
GroupWait: "10s",
GroupInterval: "5m",
RepeatInterval: "4h",
}
}
const notificationPolicyJSON = `
{
"receiver": "grafana-default-email",
"group_by": [
"..."
],
"routes": [
{
"receiver": "grafana-default-email",
"object_matchers": [
[
"a",
"=",
"b"
],
[
"asdf",
"!=",
"jk"
]
]
}
],
"group_wait": "5s",
"group_interval": "1m",
"repeat_interval": "1h"
}`