forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_test.go
63 lines (58 loc) · 1.32 KB
/
config_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
package notifier
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLoad(t *testing.T) {
tc := []struct {
name string
rawConfig string
expectedTemplates map[string]string
expectedError error
}{
{
name: "with a valid config and template",
rawConfig: `
{
"alertmanager_config": {
"global": {
"smtp_from": "[email protected]"
},
"route": {
"receiver": "email"
},
"receivers": [
{
"name": "email"
}
]
},
"template_files": {
"email.template": "something with a pretty good content"
}
}
`,
expectedTemplates: map[string]string{"email.template": "something with a pretty good content"},
},
{
name: "with an empty configuration, it is not valid.",
rawConfig: "{}",
expectedError: errors.New("unable to parse Alertmanager configuration: no route provided in config"),
},
}
for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
c, err := Load([]byte(tt.rawConfig))
if tt.expectedError != nil {
assert.Nil(t, c)
assert.Equal(t, tt.expectedError.Error(), err.Error())
} else {
require.NoError(t, err)
assert.NotNil(t, c.TemplateFiles)
assert.Equal(t, tt.expectedTemplates, c.TemplateFiles)
}
})
}
}