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