hipchat_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 TestHipChatNotifier(t *testing.T) {
  9. Convey("HipChat 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: "hipchat",
  17. Settings: settingsJSON,
  18. }
  19. _, err := NewHipChatNotifier(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: "hipchat",
  31. Settings: settingsJSON,
  32. }
  33. not, err := NewHipChatNotifier(model)
  34. hipchatNotifier := not.(*HipChatNotifier)
  35. So(err, ShouldBeNil)
  36. So(hipchatNotifier.Name, ShouldEqual, "ops")
  37. So(hipchatNotifier.Type, ShouldEqual, "hipchat")
  38. So(hipchatNotifier.Url, ShouldEqual, "http://google.com")
  39. So(hipchatNotifier.ApiKey, ShouldEqual, "")
  40. So(hipchatNotifier.RoomId, ShouldEqual, "")
  41. })
  42. Convey("from settings with Recipient and Mention", func() {
  43. json := `
  44. {
  45. "url": "http://www.hipchat.com",
  46. "apikey": "1234",
  47. "roomid": "1234"
  48. }`
  49. settingsJSON, _ := simplejson.NewJson([]byte(json))
  50. model := &m.AlertNotification{
  51. Name: "ops",
  52. Type: "hipchat",
  53. Settings: settingsJSON,
  54. }
  55. not, err := NewHipChatNotifier(model)
  56. hipchatNotifier := not.(*HipChatNotifier)
  57. So(err, ShouldBeNil)
  58. So(hipchatNotifier.Name, ShouldEqual, "ops")
  59. So(hipchatNotifier.Type, ShouldEqual, "hipchat")
  60. So(hipchatNotifier.Url, ShouldEqual, "http://www.hipchat.com")
  61. So(hipchatNotifier.ApiKey, ShouldEqual, "1234")
  62. So(hipchatNotifier.RoomId, ShouldEqual, "1234")
  63. })
  64. })
  65. })
  66. }