grafana/pkg/services/alerting/notifiers/alertmanager_test.go

48 lines
1.2 KiB
Go
Raw Normal View History

2017-06-16 22:30:40 -05:00
package notifiers
import (
"testing"
"github.com/grafana/grafana/pkg/components/simplejson"
m "github.com/grafana/grafana/pkg/models"
. "github.com/smartystreets/goconvey/convey"
)
func TestAlertmanagerNotifier(t *testing.T) {
Convey("Alertmanager notifier tests", t, func() {
Convey("Parsing alert notification from settings", func() {
Convey("empty settings should return error", func() {
json := `{ }`
settingsJSON, _ := simplejson.NewJson([]byte(json))
model := &m.AlertNotification{
Name: "alertmanager",
Type: "alertmanager",
Settings: settingsJSON,
}
_, err := NewAlertmanagerNotifier(model)
So(err, ShouldNotBeNil)
})
Convey("from settings", func() {
2017-12-13 12:13:23 -06:00
json := `{ "url": "http://127.0.0.1:9093/" }`
2017-06-16 22:30:40 -05:00
settingsJSON, _ := simplejson.NewJson([]byte(json))
model := &m.AlertNotification{
Name: "alertmanager",
Type: "alertmanager",
Settings: settingsJSON,
}
not, err := NewAlertmanagerNotifier(model)
alertmanagerNotifier := not.(*AlertmanagerNotifier)
So(err, ShouldBeNil)
So(alertmanagerNotifier.Url, ShouldEqual, "http://127.0.0.1:9093/")
})
})
})
}