notifier_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package alerting
  2. // func TestAlertNotificationExtraction(t *testing.T) {
  3. // Convey("Notifier tests", t, func() {
  4. // Convey("rules for sending notifications", func() {
  5. // dummieNotifier := NotifierImpl{}
  6. //
  7. // result := &AlertResult{
  8. // State: alertstates.Critical,
  9. // }
  10. //
  11. // notifier := &Notification{
  12. // Name: "Test Notifier",
  13. // Type: "TestType",
  14. // SendCritical: true,
  15. // SendWarning: true,
  16. // }
  17. //
  18. // Convey("Should send notification", func() {
  19. // So(dummieNotifier.ShouldDispath(result, notifier), ShouldBeTrue)
  20. // })
  21. //
  22. // Convey("warn:false and state:warn should not send", func() {
  23. // result.State = alertstates.Warn
  24. // notifier.SendWarning = false
  25. // So(dummieNotifier.ShouldDispath(result, notifier), ShouldBeFalse)
  26. // })
  27. // })
  28. //
  29. // Convey("Parsing alert notification from settings", func() {
  30. // Convey("Parsing email", func() {
  31. // Convey("empty settings should return error", func() {
  32. // json := `{ }`
  33. //
  34. // settingsJSON, _ := simplejson.NewJson([]byte(json))
  35. // model := &m.AlertNotification{
  36. // Name: "ops",
  37. // Type: "email",
  38. // Settings: settingsJSON,
  39. // }
  40. //
  41. // _, err := NewNotificationFromDBModel(model)
  42. // So(err, ShouldNotBeNil)
  43. // })
  44. //
  45. // Convey("from settings", func() {
  46. // json := `
  47. // {
  48. // "to": "ops@grafana.org"
  49. // }`
  50. //
  51. // settingsJSON, _ := simplejson.NewJson([]byte(json))
  52. // model := &m.AlertNotification{
  53. // Name: "ops",
  54. // Type: "email",
  55. // Settings: settingsJSON,
  56. // }
  57. //
  58. // not, err := NewNotificationFromDBModel(model)
  59. //
  60. // So(err, ShouldBeNil)
  61. // So(not.Name, ShouldEqual, "ops")
  62. // So(not.Type, ShouldEqual, "email")
  63. // So(reflect.TypeOf(not.Notifierr).Elem().String(), ShouldEqual, "alerting.EmailNotifier")
  64. //
  65. // email := not.Notifierr.(*EmailNotifier)
  66. // So(email.To, ShouldEqual, "ops@grafana.org")
  67. // })
  68. // })
  69. //
  70. // Convey("Parsing webhook", func() {
  71. // Convey("empty settings should return error", func() {
  72. // json := `{ }`
  73. //
  74. // settingsJSON, _ := simplejson.NewJson([]byte(json))
  75. // model := &m.AlertNotification{
  76. // Name: "ops",
  77. // Type: "webhook",
  78. // Settings: settingsJSON,
  79. // }
  80. //
  81. // _, err := NewNotificationFromDBModel(model)
  82. // So(err, ShouldNotBeNil)
  83. // })
  84. //
  85. // Convey("from settings", func() {
  86. // json := `
  87. // {
  88. // "url": "http://localhost:3000",
  89. // "username": "username",
  90. // "password": "password"
  91. // }`
  92. //
  93. // settingsJSON, _ := simplejson.NewJson([]byte(json))
  94. // model := &m.AlertNotification{
  95. // Name: "slack",
  96. // Type: "webhook",
  97. // Settings: settingsJSON,
  98. // }
  99. //
  100. // not, err := NewNotificationFromDBModel(model)
  101. //
  102. // So(err, ShouldBeNil)
  103. // So(not.Name, ShouldEqual, "slack")
  104. // So(not.Type, ShouldEqual, "webhook")
  105. // So(reflect.TypeOf(not.Notifierr).Elem().String(), ShouldEqual, "alerting.WebhookNotifier")
  106. //
  107. // webhook := not.Notifierr.(*WebhookNotifier)
  108. // So(webhook.Url, ShouldEqual, "http://localhost:3000")
  109. // })
  110. // })
  111. // })
  112. // })
  113. // }