mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 07:35:45 -06:00
Added slack tests , fixed webhook tests
This commit is contained in:
parent
2f60929d1e
commit
dc3a62da83
81
pkg/services/alerting/notifiers/slack_test.go
Normal file
81
pkg/services/alerting/notifiers/slack_test.go
Normal file
@ -0,0 +1,81 @@
|
||||
package notifiers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestSlackNotifier(t *testing.T) {
|
||||
Convey("Slack 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: "slack",
|
||||
Settings: settingsJSON,
|
||||
}
|
||||
|
||||
_, err := NewSlackNotifier(model)
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("from settings", func() {
|
||||
json := `
|
||||
{
|
||||
"url": "http://google.com"
|
||||
}`
|
||||
|
||||
settingsJSON, _ := simplejson.NewJson([]byte(json))
|
||||
model := &m.AlertNotification{
|
||||
Name: "ops",
|
||||
Type: "slack",
|
||||
Settings: settingsJSON,
|
||||
}
|
||||
|
||||
not, err := NewSlackNotifier(model)
|
||||
slackNotifier := not.(*SlackNotifier)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(slackNotifier.Name, ShouldEqual, "ops")
|
||||
So(slackNotifier.Type, ShouldEqual, "slack")
|
||||
So(slackNotifier.Url, ShouldEqual, "http://google.com")
|
||||
So(slackNotifier.Recipient, ShouldEqual, "")
|
||||
So(slackNotifier.Mention, ShouldEqual, "")
|
||||
})
|
||||
|
||||
Convey("from settings with Recipient and Mention", func() {
|
||||
json := `
|
||||
{
|
||||
"url": "http://google.com",
|
||||
"recipient": "#ds-opentsdb",
|
||||
"mention": "@carl"
|
||||
}`
|
||||
|
||||
settingsJSON, _ := simplejson.NewJson([]byte(json))
|
||||
model := &m.AlertNotification{
|
||||
Name: "ops",
|
||||
Type: "slack",
|
||||
Settings: settingsJSON,
|
||||
}
|
||||
|
||||
not, err := NewSlackNotifier(model)
|
||||
slackNotifier := not.(*SlackNotifier)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(slackNotifier.Name, ShouldEqual, "ops")
|
||||
So(slackNotifier.Type, ShouldEqual, "slack")
|
||||
So(slackNotifier.Url, ShouldEqual, "http://google.com")
|
||||
So(slackNotifier.Recipient, ShouldEqual, "#ds-opentsdb")
|
||||
So(slackNotifier.Mention, ShouldEqual, "@carl")
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
}
|
@ -40,12 +40,12 @@ func TestWebhookNotifier(t *testing.T) {
|
||||
}
|
||||
|
||||
not, err := NewWebHookNotifier(model)
|
||||
emailNotifier := not.(*WebhookNotifier)
|
||||
webhookNotifier := not.(*WebhookNotifier)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(emailNotifier.Name, ShouldEqual, "ops")
|
||||
So(emailNotifier.Type, ShouldEqual, "email")
|
||||
So(emailNotifier.Url, ShouldEqual, "http://google.com")
|
||||
So(webhookNotifier.Name, ShouldEqual, "ops")
|
||||
So(webhookNotifier.Type, ShouldEqual, "email")
|
||||
So(webhookNotifier.Url, ShouldEqual, "http://google.com")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user