send_email_integration_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.BuildVersion = "4.0.0"
  18. err := Init()
  19. So(err, ShouldBeNil)
  20. addToMailQueue = func(msg *Message) {
  21. ioutil.WriteFile("../../../tmp/test_email.html", []byte(msg.Body), 0777)
  22. }
  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. "Events": []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 := sendEmailCommandHandler(cmd)
  50. So(err, ShouldBeNil)
  51. })
  52. })
  53. }