webhook_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package notifiers
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/components/simplejson"
  5. m "github.com/grafana/grafana/pkg/models"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestWebhookNotifier(t *testing.T) {
  9. Convey("Webhook notifier tests", t, func() {
  10. Convey("Parsing alert notification from settings", func() {
  11. Convey("empty settings should return error", func() {
  12. json := `{ }`
  13. settingsJSON, _ := simplejson.NewJson([]byte(json))
  14. model := &m.AlertNotification{
  15. Name: "ops",
  16. Type: "email",
  17. Settings: settingsJSON,
  18. }
  19. _, err := NewWebHookNotifier(model)
  20. So(err, ShouldNotBeNil)
  21. })
  22. Convey("from settings", func() {
  23. json := `
  24. {
  25. "url": "http://google.com"
  26. }`
  27. settingsJSON, _ := simplejson.NewJson([]byte(json))
  28. model := &m.AlertNotification{
  29. Name: "ops",
  30. Type: "email",
  31. Settings: settingsJSON,
  32. }
  33. not, err := NewWebHookNotifier(model)
  34. webhookNotifier := not.(*WebhookNotifier)
  35. So(err, ShouldBeNil)
  36. So(webhookNotifier.Name, ShouldEqual, "ops")
  37. So(webhookNotifier.Type, ShouldEqual, "email")
  38. So(webhookNotifier.Url, ShouldEqual, "http://google.com")
  39. })
  40. })
  41. })
  42. }