pagerduty_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 TestPagerdutyNotifier(t *testing.T) {
  9. Convey("Pagerduty 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: "pageduty_testing",
  16. Type: "pagerduty",
  17. Settings: settingsJSON,
  18. }
  19. _, err := NewPagerdutyNotifier(model)
  20. So(err, ShouldNotBeNil)
  21. })
  22. Convey("auto resolve should default to false", func() {
  23. json := `{ "integrationKey": "abcdefgh0123456789" }`
  24. settingsJSON, _ := simplejson.NewJson([]byte(json))
  25. model := &m.AlertNotification{
  26. Name: "pagerduty_testing",
  27. Type: "pagerduty",
  28. Settings: settingsJSON,
  29. }
  30. not, err := NewPagerdutyNotifier(model)
  31. pagerdutyNotifier := not.(*PagerdutyNotifier)
  32. So(err, ShouldBeNil)
  33. So(pagerdutyNotifier.Name, ShouldEqual, "pagerduty_testing")
  34. So(pagerdutyNotifier.Type, ShouldEqual, "pagerduty")
  35. So(pagerdutyNotifier.Key, ShouldEqual, "abcdefgh0123456789")
  36. So(pagerdutyNotifier.AutoResolve, ShouldBeFalse)
  37. })
  38. Convey("settings should trigger incident", func() {
  39. json := `
  40. {
  41. "integrationKey": "abcdefgh0123456789",
  42. "autoResolve": false
  43. }`
  44. settingsJSON, _ := simplejson.NewJson([]byte(json))
  45. model := &m.AlertNotification{
  46. Name: "pagerduty_testing",
  47. Type: "pagerduty",
  48. Settings: settingsJSON,
  49. }
  50. not, err := NewPagerdutyNotifier(model)
  51. pagerdutyNotifier := not.(*PagerdutyNotifier)
  52. So(err, ShouldBeNil)
  53. So(pagerdutyNotifier.Name, ShouldEqual, "pagerduty_testing")
  54. So(pagerdutyNotifier.Type, ShouldEqual, "pagerduty")
  55. So(pagerdutyNotifier.Key, ShouldEqual, "abcdefgh0123456789")
  56. So(pagerdutyNotifier.AutoResolve, ShouldBeFalse)
  57. })
  58. })
  59. })
  60. }