send_email_integration_test.go 2.0 KB

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