2016-07-27 05:09:55 -05:00
|
|
|
package notifiers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
2019-05-14 01:15:05 -05:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2016-07-27 05:09:55 -05:00
|
|
|
. "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))
|
2019-05-14 01:15:05 -05:00
|
|
|
model := &models.AlertNotification{
|
2016-07-27 05:09:55 -05:00
|
|
|
Name: "ops",
|
2017-11-15 10:53:02 -06:00
|
|
|
Type: "webhook",
|
2016-07-27 05:09:55 -05:00
|
|
|
Settings: settingsJSON,
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := NewWebHookNotifier(model)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("from settings", func() {
|
|
|
|
json := `
|
|
|
|
{
|
|
|
|
"url": "http://google.com"
|
|
|
|
}`
|
|
|
|
|
|
|
|
settingsJSON, _ := simplejson.NewJson([]byte(json))
|
2019-05-14 01:15:05 -05:00
|
|
|
model := &models.AlertNotification{
|
2016-07-27 05:09:55 -05:00
|
|
|
Name: "ops",
|
2017-11-15 10:53:02 -06:00
|
|
|
Type: "webhook",
|
2016-07-27 05:09:55 -05:00
|
|
|
Settings: settingsJSON,
|
|
|
|
}
|
|
|
|
|
|
|
|
not, err := NewWebHookNotifier(model)
|
2016-11-04 07:33:50 -05:00
|
|
|
webhookNotifier := not.(*WebhookNotifier)
|
2016-07-27 05:09:55 -05:00
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
2016-11-04 07:33:50 -05:00
|
|
|
So(webhookNotifier.Name, ShouldEqual, "ops")
|
2017-11-15 10:53:02 -06:00
|
|
|
So(webhookNotifier.Type, ShouldEqual, "webhook")
|
2019-05-20 08:23:06 -05:00
|
|
|
So(webhookNotifier.URL, ShouldEqual, "http://google.com")
|
2016-07-27 05:09:55 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|