pagerduty_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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("settings should trigger incident", func() {
  23. json := `
  24. {
  25. "integrationKey": "abcdefgh0123456789"
  26. }`
  27. settingsJSON, _ := simplejson.NewJson([]byte(json))
  28. model := &m.AlertNotification{
  29. Name: "pagerduty_testing",
  30. Type: "pagerduty",
  31. Settings: settingsJSON,
  32. }
  33. not, err := NewPagerdutyNotifier(model)
  34. pagerdutyNotifier := not.(*PagerdutyNotifier)
  35. So(err, ShouldBeNil)
  36. So(pagerdutyNotifier.Name, ShouldEqual, "pagerduty_testing")
  37. So(pagerdutyNotifier.Type, ShouldEqual, "pagerduty")
  38. So(pagerdutyNotifier.Key, ShouldEqual, "abcdefgh0123456789")
  39. })
  40. })
  41. })
  42. }