forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alerting_mute_timing_test.go
163 lines (140 loc) · 2.96 KB
/
alerting_mute_timing_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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
func TestMuteTimings(t *testing.T) {
t.Run("get mute timings succeeds", func(t *testing.T) {
client := gapiTestTools(t, 200, getMuteTimingsJSON)
mts, err := client.MuteTimings()
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(mts))
if len(mts) != 2 {
t.Errorf("wrong number of mute timings returned, got %#v", mts)
}
if mts[0].Name != "timing one" {
t.Errorf("incorrect name - expected %s on element %d, got %#v", "timing one", 0, mts)
}
if mts[1].Name != "another timing" {
t.Errorf("incorrect name - expected %s on element %d, got %#v", "another timing", 1, mts)
}
})
t.Run("get mute timing succeeds", func(t *testing.T) {
client := gapiTestTools(t, 200, muteTimingJSON)
mt, err := client.MuteTiming("timing one")
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(mt))
if mt.Name != "timing one" {
t.Errorf("incorrect name - expected %s, got %#v", "timing one", mt)
}
})
t.Run("get non-existent mute timing fails", func(t *testing.T) {
client := gapiTestTools(t, 404, muteTimingJSON)
mt, err := client.MuteTiming("does not exist")
if err == nil {
t.Errorf("expected error but got nil")
t.Log(pretty.PrettyFormat(mt))
}
})
t.Run("create mute timing succeeds", func(t *testing.T) {
client := gapiTestTools(t, 201, muteTimingJSON)
mt := createMuteTiming()
err := client.NewMuteTiming(&mt)
if err != nil {
t.Error(err)
}
})
t.Run("update mute timing succeeds", func(t *testing.T) {
client := gapiTestTools(t, 200, muteTimingJSON)
mt := createMuteTiming()
mt.TimeIntervals[0].Weekdays = []WeekdayRange{"tuesday", "thursday"}
err := client.UpdateMuteTiming(&mt)
if err != nil {
t.Error(err)
}
})
t.Run("delete mute timing succeeds", func(t *testing.T) {
client := gapiTestTools(t, 204, muteTimingJSON)
err := client.DeleteMuteTiming("timing two")
if err != nil {
t.Error(err)
}
})
}
func createMuteTiming() MuteTiming {
return MuteTiming{
Name: "timing two",
TimeIntervals: []TimeInterval{
{
Times: []TimeRange{
{
StartMinute: "13:13",
EndMinute: "15:15",
},
},
Weekdays: []WeekdayRange{"monday", "wednesday"},
Months: []MonthRange{"1:3", "4"},
Years: []YearRange{"2022", "2023"},
},
},
}
}
const getMuteTimingsJSON = `
[
{
"name": "timing one",
"time_intervals": [
{
"times": [
{
"start_time": "13:13",
"end_time": "15:15"
}
],
"weekdays": [
"monday:wednesday"
],
"months": [
"1"
]
}
]
},
{
"name": "another timing",
"time_intervals": [
{
"days_of_month": [
"1"
],
"years": [
"2030"
]
}
]
}
]`
const muteTimingJSON = `
{
"name": "timing one",
"time_intervals": [
{
"times": [
{
"start_time": "13:13",
"end_time": "15:15"
}
],
"weekdays": [
"monday:wednesday"
],
"months": [
"1"
]
}
]
}`