send_email_integration_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package notifications
  2. import (
  3. "io/ioutil"
  4. "testing"
  5. "github.com/grafana/grafana/pkg/bus"
  6. m "github.com/grafana/grafana/pkg/models"
  7. "github.com/grafana/grafana/pkg/setting"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestEmailIntegrationTest(t *testing.T) {
  11. SkipConvey("Given the notifications service", t, func() {
  12. setting.StaticRootPath = "../../../public/"
  13. setting.BuildVersion = "4.0.0"
  14. ns := &NotificationService{}
  15. ns.Bus = bus.New()
  16. ns.Cfg = setting.NewCfg()
  17. ns.Cfg.Smtp.Enabled = true
  18. ns.Cfg.Smtp.TemplatesPattern = "emails/*.html"
  19. ns.Cfg.Smtp.FromAddress = "from@address.com"
  20. ns.Cfg.Smtp.FromName = "Grafana Admin"
  21. err := ns.Init()
  22. So(err, ShouldBeNil)
  23. Convey("When sending reset email password", func() {
  24. cmd := &m.SendEmailCommand{
  25. Data: map[string]interface{}{
  26. "Title": "[CRITICAL] Imaginary timeserie alert",
  27. "State": "Firing",
  28. "Name": "Imaginary timeserie alert",
  29. "Severity": "ok",
  30. "SeverityColor": "#D63232",
  31. "Message": "Alert message that will support markdown in some distant future.",
  32. "RuleUrl": "http://localhost:3000/dashboard/db/graphite-dashboard",
  33. "ImageLink": "http://localhost:3000/render/dashboard-solo/db/graphite-dashboard?panelId=1&from=1471008499616&to=1471012099617&width=1000&height=500",
  34. "AlertPageUrl": "http://localhost:3000/alerting",
  35. "EmbeddedImage": "test.png",
  36. "EvalMatches": []map[string]string{
  37. {
  38. "Metric": "desktop",
  39. "Value": "40",
  40. },
  41. {
  42. "Metric": "mobile",
  43. "Value": "20",
  44. },
  45. },
  46. },
  47. To: []string{"asdf@asdf.com"},
  48. Template: "alert_notification.html",
  49. }
  50. err := ns.sendEmailCommandHandler(cmd)
  51. So(err, ShouldBeNil)
  52. sentMsg := <-ns.mailQueue
  53. So(sentMsg.From, ShouldEqual, "Grafana Admin <from@address.com>")
  54. So(sentMsg.To[0], ShouldEqual, "asdf@asdf.com")
  55. ioutil.WriteFile("../../../tmp/test_email.html", []byte(sentMsg.Body), 0777)
  56. })
  57. })
  58. }