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

53 lines
1.3 KiB
Go
Raw Normal View History

2018-03-28 04:56:54 -05:00
package notifiers
import (
"testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
2018-03-28 04:56:54 -05:00
. "github.com/smartystreets/goconvey/convey"
)
func TestGoogleChatNotifier(t *testing.T) {
Convey("Google Hangouts Chat 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 := &models.AlertNotification{
2018-03-28 04:56:54 -05:00
Name: "ops",
Type: "googlechat",
Settings: settingsJSON,
}
_, err := newGoogleChatNotifier(model)
2018-03-28 04:56:54 -05:00
So(err, ShouldNotBeNil)
})
Convey("from settings", func() {
json := `
{
"url": "http://google.com"
}`
settingsJSON, _ := simplejson.NewJson([]byte(json))
model := &models.AlertNotification{
2018-03-28 04:56:54 -05:00
Name: "ops",
Type: "googlechat",
Settings: settingsJSON,
}
not, err := newGoogleChatNotifier(model)
2018-03-28 04:56:54 -05:00
webhookNotifier := not.(*GoogleChatNotifier)
So(err, ShouldBeNil)
So(webhookNotifier.Name, ShouldEqual, "ops")
So(webhookNotifier.Type, ShouldEqual, "googlechat")
So(webhookNotifier.URL, ShouldEqual, "http://google.com")
2018-03-28 04:56:54 -05:00
})
})
})
}