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_message_template_test.go
94 lines (75 loc) · 2.13 KB
/
alerting_message_template_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
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
func TestMessageTemplates(t *testing.T) {
t.Run("get message templates succeeds", func(t *testing.T) {
client := gapiTestTools(t, 200, getMessageTemplatesJSON)
ts, err := client.MessageTemplates()
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(ts))
if len(ts) != 2 {
t.Errorf("wrong number of templates returned, got %#v", ts)
}
if ts[0].Name != "template-one" {
t.Errorf("incorrect name - expected %s on element %d, got %#v", "template-one", 0, ts)
}
if ts[1].Name != "template-two" {
t.Errorf("incorrect name - expected %s on element %d, got %#v", "template-two", 0, ts)
}
})
t.Run("get message template succeeds", func(t *testing.T) {
client := gapiTestTools(t, 200, messageTemplateJSON)
tmpl, err := client.MessageTemplate("template-one")
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(tmpl))
if tmpl.Name != "template-one" {
t.Errorf("incorrect name - expected %s, got %#v", "template-one", tmpl)
}
})
t.Run("get non-existent message template fails", func(t *testing.T) {
client := gapiTestTools(t, 404, ``)
tmpl, err := client.MessageTemplate("does not exist")
if err == nil {
t.Errorf("expected error but got nil")
t.Log(pretty.PrettyFormat(tmpl))
}
})
t.Run("put message template succeeds", func(t *testing.T) {
client := gapiTestTools(t, 202, messageTemplateJSON)
err := client.SetMessageTemplate("template-three", "{{define \"template-one\" }}\n content three\n{{ end }}")
if err != nil {
t.Error(err)
}
})
t.Run("delete message template succeeds", func(t *testing.T) {
client := gapiTestTools(t, 204, ``)
err := client.DeleteMessageTemplate("template-three")
if err != nil {
t.Error(err)
}
})
}
const getMessageTemplatesJSON = `
[
{
"name": "template-one",
"template": "{{define \"template-one\" }}\n content one\n{{ end }}"
},
{
"name": "template-two",
"template": "{{define \"template-one\" }}\n content two\n{{ end }}"
}
]
`
const messageTemplateJSON = `
{
"name": "template-one",
"template": "{{define \"template-one\" }}\n content one\n{{ end }}"
}
`