pushover_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 TestPushoverNotifier(t *testing.T) {
  9. Convey("Pushover 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: "Pushover",
  16. Type: "pushover",
  17. Settings: settingsJSON,
  18. }
  19. _, err := NewPushoverNotifier(model)
  20. So(err, ShouldNotBeNil)
  21. })
  22. Convey("from settings", func() {
  23. json := `
  24. {
  25. "apiToken": "4SrUFQL4A5V5TQ1z5Pg9nxHXPXSTve",
  26. "userKey": "tzNZYf36y0ohWwXo4XoUrB61rz1A4o",
  27. "priority": "1",
  28. "sound": "pushover"
  29. }`
  30. settingsJSON, _ := simplejson.NewJson([]byte(json))
  31. model := &m.AlertNotification{
  32. Name: "Pushover",
  33. Type: "pushover",
  34. Settings: settingsJSON,
  35. }
  36. not, err := NewPushoverNotifier(model)
  37. pushoverNotifier := not.(*PushoverNotifier)
  38. So(err, ShouldBeNil)
  39. So(pushoverNotifier.Name, ShouldEqual, "Pushover")
  40. So(pushoverNotifier.Type, ShouldEqual, "pushover")
  41. So(pushoverNotifier.ApiToken, ShouldEqual, "4SrUFQL4A5V5TQ1z5Pg9nxHXPXSTve")
  42. So(pushoverNotifier.UserKey, ShouldEqual, "tzNZYf36y0ohWwXo4XoUrB61rz1A4o")
  43. So(pushoverNotifier.Priority, ShouldEqual, 1)
  44. So(pushoverNotifier.Sound, ShouldEqual, "pushover")
  45. })
  46. })
  47. })
  48. }