hipchat_test.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package notifiers
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/components/simplejson"
  5. "github.com/grafana/grafana/pkg/models"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. //nolint:goconst
  9. func TestHipChatNotifier(t *testing.T) {
  10. Convey("HipChat notifier tests", t, func() {
  11. Convey("Parsing alert notification from settings", func() {
  12. Convey("empty settings should return error", func() {
  13. json := `{ }`
  14. settingsJSON, _ := simplejson.NewJson([]byte(json))
  15. model := &models.AlertNotification{
  16. Name: "ops",
  17. Type: "hipchat",
  18. Settings: settingsJSON,
  19. }
  20. _, err := NewHipChatNotifier(model)
  21. So(err, ShouldNotBeNil)
  22. })
  23. Convey("from settings", func() {
  24. json := `
  25. {
  26. "url": "http://google.com"
  27. }`
  28. settingsJSON, _ := simplejson.NewJson([]byte(json))
  29. model := &models.AlertNotification{
  30. Name: "ops",
  31. Type: "hipchat",
  32. Settings: settingsJSON,
  33. }
  34. not, err := NewHipChatNotifier(model)
  35. hipchatNotifier := not.(*HipChatNotifier)
  36. So(err, ShouldBeNil)
  37. So(hipchatNotifier.Name, ShouldEqual, "ops")
  38. So(hipchatNotifier.Type, ShouldEqual, "hipchat")
  39. So(hipchatNotifier.URL, ShouldEqual, "http://google.com")
  40. So(hipchatNotifier.APIKey, ShouldEqual, "")
  41. So(hipchatNotifier.RoomID, ShouldEqual, "")
  42. })
  43. Convey("from settings with Recipient and Mention", func() {
  44. json := `
  45. {
  46. "url": "http://www.hipchat.com",
  47. "apikey": "1234",
  48. "roomid": "1234"
  49. }`
  50. settingsJSON, _ := simplejson.NewJson([]byte(json))
  51. model := &models.AlertNotification{
  52. Name: "ops",
  53. Type: "hipchat",
  54. Settings: settingsJSON,
  55. }
  56. not, err := NewHipChatNotifier(model)
  57. hipchatNotifier := not.(*HipChatNotifier)
  58. So(err, ShouldBeNil)
  59. So(hipchatNotifier.Name, ShouldEqual, "ops")
  60. So(hipchatNotifier.Type, ShouldEqual, "hipchat")
  61. So(hipchatNotifier.URL, ShouldEqual, "http://www.hipchat.com")
  62. So(hipchatNotifier.APIKey, ShouldEqual, "1234")
  63. So(hipchatNotifier.RoomID, ShouldEqual, "1234")
  64. })
  65. })
  66. })
  67. }