forked from volatiletech/authboss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailer_test.go
71 lines (56 loc) · 1.29 KB
/
mailer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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.")
}
}