-
Notifications
You must be signed in to change notification settings - Fork 2
/
mailer_test.go
53 lines (44 loc) · 1.2 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
package auth
import (
"html/template"
"testing"
)
const verifyEmailTmpl string = "email:{{ .Email }}"
func TestSends(t *testing.T) {
sender := &NilSender{}
m := Emailer{
Sender: sender,
}
m.TemplateCache = template.Must(template.New("testTempl").Parse(verifyEmailTmpl))
data := &emailSession{Email: "[email protected]"}
err := m.SendMessage("to", "testTempl", "testEmailSubject", data)
if err != nil || sender.LastBody != "email:[email protected]" || sender.LastTo != "to" || sender.LastSubject != "testEmailSubject" {
t.Error("expected valid values", sender, err)
}
}
/***************************************************************************************/
type NilSender struct {
LastTo string
LastSubject string
LastBody string
}
func (s *NilSender) Send(to, subject, body string) error {
s.LastTo = to
s.LastSubject = subject
s.LastBody = body
return nil
}
type TextMailer struct {
Err error
Mailer
MessageTo string
MessageData interface{}
}
func (t *TextMailer) SendMessage(to, templateName, emailSubject string, data interface{}) error {
return t.send(to, data)
}
func (t *TextMailer) send(to string, data interface{}) error {
t.MessageTo = to
t.MessageData = data
return t.Err
}