mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
2e8c514cfd
Updates Grafana Alertmanager to work with new interface from grafana/alerting#161. This change stops passing user-defined templates to the Grafana Alertmanager by persisting them to disk and instead passes them by string.
64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
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": "noreply@grafana.net"
|
|
},
|
|
"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)
|
|
}
|
|
})
|
|
}
|
|
}
|