grafana/pkg/services/notifications/send_email_integration_test.go
Arve Knudsen 78596a6756
Migrate to Wire for dependency injection (#32289)
Fixes #30144

Co-authored-by: dsotirakis <sotirakis.dim@gmail.com>
Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
Co-authored-by: Ida Furjesova <ida.furjesova@grafana.com>
Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com>
Co-authored-by: spinillos <selenepinillos@gmail.com>
Co-authored-by: Karl Persson <kalle.persson@grafana.com>
Co-authored-by: Leonard Gram <leo@xlson.com>
2021-08-25 15:11:22 +02:00

69 lines
2.2 KiB
Go

package notifications
import (
"io/ioutil"
"testing"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
. "github.com/smartystreets/goconvey/convey"
)
func TestEmailIntegrationTest(t *testing.T) {
SkipConvey("Given the notifications service", t, func() {
setting.StaticRootPath = "../../../public/"
setting.BuildVersion = "4.0.0"
ns := &NotificationService{}
ns.Bus = bus.New()
ns.Cfg = setting.NewCfg()
ns.Cfg.Smtp.Enabled = true
ns.Cfg.Smtp.TemplatesPatterns = []string{"emails/*.html", "emails/*.txt"}
ns.Cfg.Smtp.FromAddress = "from@address.com"
ns.Cfg.Smtp.FromName = "Grafana Admin"
ns.Cfg.Smtp.ContentTypes = []string{"text/html", "text/plain"}
Convey("When sending reset email password", func() {
cmd := &models.SendEmailCommand{
Data: map[string]interface{}{
"Title": "[CRITICAL] Imaginary timeseries alert",
"State": "Firing",
"Name": "Imaginary timeseries alert",
"Severity": "ok",
"SeverityColor": "#D63232",
"Message": "Alert message that will support markdown in some distant future.",
"RuleUrl": "http://localhost:3000/dashboard/db/graphite-dashboard",
"ImageLink": "http://localhost:3000/render/dashboard-solo/db/graphite-dashboard?panelId=1&from=1471008499616&to=1471012099617&width=1000&height=500",
"AlertPageUrl": "http://localhost:3000/alerting",
"EmbeddedImage": "test.png",
"EvalMatches": []map[string]string{
{
"Metric": "desktop",
"Value": "40",
},
{
"Metric": "mobile",
"Value": "20",
},
},
},
To: []string{"asdf@asdf.com"},
Template: "alert_notification",
}
err := ns.sendEmailCommandHandler(cmd)
So(err, ShouldBeNil)
sentMsg := <-ns.mailQueue
So(sentMsg.From, ShouldEqual, "Grafana Admin <from@address.com>")
So(sentMsg.To[0], ShouldEqual, "asdf@asdf.com")
err = ioutil.WriteFile("../../../tmp/test_email.html", []byte(sentMsg.Body["text/html"]), 0777)
So(err, ShouldBeNil)
err = ioutil.WriteFile("../../../tmp/test_email.txt", []byte(sentMsg.Body["text/plain"]), 0777)
So(err, ShouldBeNil)
})
})
}