mirror of
https://github.com/grafana/grafana.git
synced 2024-11-27 19:30:36 -06:00
fd633a1d5d
This way we are able to edit notification behavior per notifier. This would be usefull to let some notifiers send notifications, even when the state doesn't change, or with custom condition. Signed-off-by: Thibault Chataigner <t.chataigner@criteo.com>
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
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: "webhook",
|
|
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: "webhook",
|
|
Settings: settingsJSON,
|
|
}
|
|
|
|
not, err := NewWebHookNotifier(model)
|
|
webhookNotifier := not.(*WebhookNotifier)
|
|
|
|
So(err, ShouldBeNil)
|
|
So(webhookNotifier.Name, ShouldEqual, "ops")
|
|
So(webhookNotifier.Type, ShouldEqual, "webhook")
|
|
So(webhookNotifier.Url, ShouldEqual, "http://google.com")
|
|
})
|
|
})
|
|
})
|
|
}
|