forked from grafana-tools/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest-alertnotification_integration_test.go
65 lines (54 loc) · 1.4 KB
/
rest-alertnotification_integration_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
package sdk_test
import (
"context"
"testing"
"github.com/grafana-tools/sdk"
)
func Test_Alertnotification_CRUD(t *testing.T) {
shouldSkip(t)
client := getClient(t)
ctx := context.Background()
alertnotifications, err := client.GetAllAlertNotifications(ctx)
if err != nil {
t.Fatal(err)
}
if len(alertnotifications) != 0 {
t.Fatalf("expected to get zero alertnotifications, got %#v", alertnotifications)
}
an := sdk.AlertNotification{
Name: "team-a-email-notifier",
Type: "email",
IsDefault: false,
DisableResolveMessage: false,
SendReminder: false,
Frequency: "15m",
UID: "foobar",
Settings: map[string]string{
"addresses": "[email protected]",
},
}
id, err := client.CreateAlertNotification(ctx, an)
if err != nil {
t.Fatal(err)
}
anRetrieved, err := client.GetAlertNotificationID(ctx, uint(id))
if err != nil {
t.Fatal(err)
}
if anRetrieved.Name != an.Name {
t.Fatalf("got wrong name: expected %s, was %s", anRetrieved.Name, an.Name)
}
an.Name = "alertnotification2"
err = client.UpdateAlertNotificationUID(ctx, an, "foobar")
if err != nil {
t.Fatal(err)
}
err = client.DeleteAlertNotificationUID(ctx, "foobar")
if err != nil {
t.Fatal(err)
}
an, err = client.GetAlertNotificationUID(ctx, "foobar")
if err == nil {
t.Fatalf("expected the alertnotification to be deleted")
}
}