| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package notifiers
- import (
- "testing"
- "github.com/grafana/grafana/pkg/components/simplejson"
- m "github.com/grafana/grafana/pkg/models"
- . "github.com/smartystreets/goconvey/convey"
- )
- func TestWebhookNotifier(t *testing.T) {
- Convey("Webhook 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: "ops",
- Type: "email",
- Settings: settingsJSON,
- }
- _, err := NewWebHookNotifier(model)
- So(err, ShouldNotBeNil)
- })
- Convey("from settings", func() {
- json := `
- {
- "url": "http://google.com"
- }`
- settingsJSON, _ := simplejson.NewJson([]byte(json))
- model := &m.AlertNotification{
- Name: "ops",
- Type: "email",
- Settings: settingsJSON,
- }
- not, err := NewWebHookNotifier(model)
- webhookNotifier := not.(*WebhookNotifier)
- So(err, ShouldBeNil)
- So(webhookNotifier.Name, ShouldEqual, "ops")
- So(webhookNotifier.Type, ShouldEqual, "email")
- So(webhookNotifier.Url, ShouldEqual, "http://google.com")
- })
- })
- })
- }
|