This repository has been archived by the owner on Mar 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
alertnotification_test.go
172 lines (152 loc) · 3.61 KB
/
alertnotification_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
164
165
166
167
168
169
170
171
172
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
const (
getAlertNotificationsJSON = `
[
{
"id": 1,
"uid": "team-a-email-notifier",
"name": "Team A",
"type": "email",
"isDefault": false,
"sendReminder": false,
"disableResolveMessage": false,
"settings": {
"addresses": "[email protected]"
},
"created": "2018-04-23T14:44:09+02:00",
"updated": "2018-08-20T15:47:49+02:00"
}
]
`
getAlertNotificationJSON = `
{
"id": 1,
"uid": "team-a-email-notifier",
"name": "Team A",
"type": "email",
"isDefault": false,
"sendReminder": false,
"disableResolveMessage": false,
"settings": {
"addresses": "[email protected]"
},
"created": "2018-04-23T14:44:09+02:00",
"updated": "2018-08-20T15:47:49+02:00"
}
`
createdAlertNotificationJSON = `
{
"id": 1,
"uid": "new-alert-notification",
"name": "Team A",
"type": "email",
"isDefault": false,
"sendReminder": true,
"frequency": "15m",
"settings": {
"addresses": "[email protected]"
}
}
`
updatedAlertNotificationJSON = `
{
"uid": "new-alert-notification",
"name": "Team A",
"type": "email",
"isDefault": false,
"sendReminder": true,
"frequency": "15m",
"settings": {
"addresses": "[email protected]"
}
}
`
deletedAlertNotificationJSON = `
{
"message":"Notification deleted"
}
`
)
func TestAlertNotifications(t *testing.T) {
server, client := gapiTestTools(200, getAlertNotificationsJSON)
defer server.Close()
alertnotifications, err := client.AlertNotifications()
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(alertnotifications))
if len(alertnotifications) != 1 {
t.Error("Length of returned alert notifications should be 1")
}
if alertnotifications[0].Id != 1 || alertnotifications[0].Name != "Team A" {
t.Error("Not correctly parsing returned alert notifications.")
}
}
func TestAlertNotification(t *testing.T) {
server, client := gapiTestTools(200, getAlertNotificationJSON)
defer server.Close()
alertnotification := int64(1)
resp, err := client.AlertNotification(alertnotification)
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(resp))
if resp.Id != alertnotification || resp.Name != "Team A" {
t.Error("Not correctly parsing returned alert notification.")
}
}
func TestNewAlertNotification(t *testing.T) {
server, client := gapiTestTools(200, createdAlertNotificationJSON)
defer server.Close()
an := &AlertNotification{
Name: "Team A",
Type: "email",
IsDefault: false,
DisableResolveMessage: true,
SendReminder: true,
Frequency: "15m",
Settings: map[string]string{
"addresses": "[email protected]",
},
}
resp, err := client.NewAlertNotification(an)
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(resp))
if resp != 1 {
t.Error("Not correctly parsing returned creation message.")
}
}
func TestUpdateAlertNotification(t *testing.T) {
server, client := gapiTestTools(200, updatedAlertNotificationJSON)
defer server.Close()
an := &AlertNotification{
Id: 1,
Name: "Team A",
Type: "email",
IsDefault: false,
DisableResolveMessage: true,
SendReminder: true,
Frequency: "15m",
Settings: map[string]string{
"addresses": "[email protected]",
},
}
err := client.UpdateAlertNotification(an)
if err != nil {
t.Error(err)
}
}
func TestDeleteAlertNotification(t *testing.T) {
server, client := gapiTestTools(200, deletedAlertNotificationJSON)
defer server.Close()
err := client.DeleteAlertNotification(1)
if err != nil {
t.Error(err)
}
}