email_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 TestEmailNotifier(t *testing.T) {
  9. Convey("Email 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: "email",
  17. Settings: settingsJSON,
  18. }
  19. _, err := NewEmailNotifier(model)
  20. So(err, ShouldNotBeNil)
  21. })
  22. Convey("from settings", func() {
  23. json := `
  24. {
  25. "addresses": "ops@grafana.org"
  26. }`
  27. settingsJSON, _ := simplejson.NewJson([]byte(json))
  28. model := &m.AlertNotification{
  29. Name: "ops",
  30. Type: "email",
  31. Settings: settingsJSON,
  32. }
  33. not, err := NewEmailNotifier(model)
  34. emailNotifier := not.(*EmailNotifier)
  35. So(err, ShouldBeNil)
  36. So(emailNotifier.Name, ShouldEqual, "ops")
  37. So(emailNotifier.Type, ShouldEqual, "email")
  38. So(emailNotifier.Addresses[0], ShouldEqual, "ops@grafana.org")
  39. })
  40. })
  41. })
  42. }