1
0
mirror of https://github.com/volatiletech/authboss.git synced 2024-11-24 08:42:17 +02:00
authboss/mailer_test.go
Aaron f12f10fa43 Stop reliance on global scope.
- This change was necessary because multi-tenancy sites could not use
  authboss properly.
2015-03-31 12:34:03 -07:00

72 lines
1.3 KiB
Go

package authboss
import (
"bytes"
"io/ioutil"
"strings"
"testing"
)
func TestMailer(t *testing.T) {
t.Parallel()
ab := New()
mailServer := &bytes.Buffer{}
ab.Mailer = LogMailer(mailServer)
ab.Storer = mockStorer{}
ab.LogWriter = ioutil.Discard
err := ab.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.")
}
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.")
}
}
func TestSMTPMailer(t *testing.T) {
t.Parallel()
var _ Mailer = SMTPMailer("server", nil)
recovered := false
defer func() {
recovered = recover() != nil
}()
SMTPMailer("", nil)
if !recovered {
t.Error("Should have panicd.")
}
}