teams_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 TestTeamsNotifier(t *testing.T) {
  9. Convey("Teams 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: "teams",
  17. Settings: settingsJSON,
  18. }
  19. _, err := NewTeamsNotifier(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: "teams",
  31. Settings: settingsJSON,
  32. }
  33. not, err := NewTeamsNotifier(model)
  34. teamsNotifier := not.(*TeamsNotifier)
  35. So(err, ShouldBeNil)
  36. So(teamsNotifier.Name, ShouldEqual, "ops")
  37. So(teamsNotifier.Type, ShouldEqual, "teams")
  38. So(teamsNotifier.Url, ShouldEqual, "http://google.com")
  39. })
  40. Convey("from settings with Recipient and Mention", func() {
  41. json := `
  42. {
  43. "url": "http://google.com"
  44. }`
  45. settingsJSON, _ := simplejson.NewJson([]byte(json))
  46. model := &m.AlertNotification{
  47. Name: "ops",
  48. Type: "teams",
  49. Settings: settingsJSON,
  50. }
  51. not, err := NewTeamsNotifier(model)
  52. teamsNotifier := not.(*TeamsNotifier)
  53. So(err, ShouldBeNil)
  54. So(teamsNotifier.Name, ShouldEqual, "ops")
  55. So(teamsNotifier.Type, ShouldEqual, "teams")
  56. So(teamsNotifier.Url, ShouldEqual, "http://google.com")
  57. })
  58. })
  59. })
  60. }