1
0
mirror of https://github.com/volatiletech/authboss.git synced 2024-12-04 10:24:52 +02:00
authboss/mailer_test.go

52 lines
1023 B
Go
Raw Normal View History

2015-01-26 01:40:57 +02:00
package authboss
import (
"bytes"
"strings"
"testing"
)
func TestMailer(t *testing.T) {
NewConfig()
2015-01-26 01:40:57 +02:00
mailServer := &bytes.Buffer{}
Cfg.Mailer = LogMailer(mailServer)
Cfg.Storer = mockStorer{}
Init()
2015-01-26 01:40:57 +02:00
err := SendMail(Email{
To: []string{"some@email.com", "a@a.com"},
ToNames: []string{"Jake", "Noname"},
From: "some@guy.com",
FromName: "Joseph",
ReplyTo: "an@email.com",
Subject: "Email!",
TextBody: "No html here",
HTMLBody: "<html>body</html>",
})
if err != nil {
t.Error(err)
}
if mailServer.Len() == 0 {
t.Error("It should have logged the e-mail.")
}
str := mailServer.String()
if !strings.Contains(str, "From: Joseph <some@guy.com>") {
t.Error("From line not present.")
}
if !strings.Contains(str, "To: Jake <some@email.com>, Noname <a@a.com>") {
t.Error("To line not present.")
}
2015-01-26 02:55:30 +02:00
if !strings.Contains(str, "No html here") {
t.Error("Text body not present.")
}
if !strings.Contains(str, "<html>body</html>") {
t.Error("Html body not present.")
}
2015-01-26 01:40:57 +02:00
}