2016-06-20 00:49:08 -05:00
|
|
|
package notifications
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
|
|
m "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() {
|
|
|
|
bus.ClearBusHandlers()
|
|
|
|
|
|
|
|
setting.StaticRootPath = "../../../public/"
|
|
|
|
setting.Smtp.Enabled = true
|
|
|
|
setting.Smtp.TemplatesPattern = "emails/*.html"
|
|
|
|
setting.Smtp.FromAddress = "from@address.com"
|
2017-02-14 15:04:21 -06:00
|
|
|
setting.Smtp.FromName = "Grafana Admin"
|
2016-08-12 09:44:53 -05:00
|
|
|
setting.BuildVersion = "4.0.0"
|
2016-06-20 00:49:08 -05:00
|
|
|
|
|
|
|
err := Init()
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
addToMailQueue = func(msg *Message) {
|
2017-02-15 03:45:04 -06:00
|
|
|
So(msg.From, ShouldEqual, "Grafana Admin <from@address.com>")
|
|
|
|
So(msg.To[0], ShouldEqual, "asdf@asdf.com")
|
2016-06-20 00:49:08 -05:00
|
|
|
ioutil.WriteFile("../../../tmp/test_email.html", []byte(msg.Body), 0777)
|
|
|
|
}
|
|
|
|
|
|
|
|
Convey("When sending reset email password", func() {
|
|
|
|
cmd := &m.SendEmailCommand{
|
|
|
|
|
|
|
|
Data: map[string]interface{}{
|
2016-08-12 09:44:53 -05:00
|
|
|
"Title": "[CRITICAL] Imaginary timeserie alert",
|
|
|
|
"State": "Firing",
|
|
|
|
"Name": "Imaginary timeserie alert",
|
2016-08-13 05:13:32 -05:00
|
|
|
"Severity": "ok",
|
|
|
|
"SeverityColor": "#D63232",
|
2016-08-12 09:44:53 -05:00
|
|
|
"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",
|
2016-08-13 05:13:32 -05:00
|
|
|
"AlertPageUrl": "http://localhost:3000/alerting",
|
2017-02-15 03:45:04 -06:00
|
|
|
"EmbededImage": "test.png",
|
2016-09-07 06:47:57 -05:00
|
|
|
"EvalMatches": []map[string]string{
|
2016-08-13 05:13:32 -05:00
|
|
|
{
|
|
|
|
"Metric": "desktop",
|
|
|
|
"Value": "40",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Metric": "mobile",
|
|
|
|
"Value": "20",
|
|
|
|
},
|
|
|
|
},
|
2016-06-20 00:49:08 -05:00
|
|
|
},
|
2017-02-15 03:45:04 -06:00
|
|
|
To: []string{"asdf@asdf.com"},
|
2016-06-20 00:49:08 -05:00
|
|
|
Template: "alert_notification.html",
|
|
|
|
}
|
|
|
|
|
|
|
|
err := sendEmailCommandHandler(cmd)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|