send_email_integration_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. ioutil.WriteFile("../../../tmp/test_email.html", []byte(msg.Body), 0777)
  23. }
  24. Convey("When sending reset email password", func() {
  25. cmd := &m.SendEmailCommand{
  26. Data: map[string]interface{}{
  27. "Title": "[CRITICAL] Imaginary timeserie alert",
  28. "State": "Firing",
  29. "Name": "Imaginary timeserie alert",
  30. "Severity": "ok",
  31. "SeverityColor": "#D63232",
  32. "Message": "Alert message that will support markdown in some distant future.",
  33. "RuleUrl": "http://localhost:3000/dashboard/db/graphite-dashboard",
  34. "ImageLink": "http://localhost:3000/render/dashboard-solo/db/graphite-dashboard?panelId=1&from=1471008499616&to=1471012099617&width=1000&height=500",
  35. "AlertPageUrl": "http://localhost:3000/alerting",
  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 := sendEmailCommandHandler(cmd)
  51. So(err, ShouldBeNil)
  52. })
  53. })
  54. }