1
0
mirror of https://github.com/volatiletech/authboss.git synced 2025-01-10 04:17:59 +02:00
authboss/defaults/log_mailer_test.go

67 lines
1.3 KiB
Go
Raw Normal View History

2018-01-29 23:14:55 +02:00
package defaults
2015-01-26 01:40:57 +02:00
import (
"bytes"
"context"
2017-02-21 01:56:26 +02:00
"math/rand"
2015-01-26 01:40:57 +02:00
"strings"
"testing"
2018-01-29 23:14:55 +02:00
"github.com/volatiletech/authboss"
2015-01-26 01:40:57 +02:00
)
func TestMailer(t *testing.T) {
t.Parallel()
2015-01-26 01:40:57 +02:00
mailServer := &bytes.Buffer{}
2018-01-29 23:14:55 +02:00
mailer := NewLogMailer(mailServer)
2015-01-26 01:40:57 +02:00
2018-01-29 23:14:55 +02:00
err := mailer.Send(context.TODO(), authboss.Email{
2015-01-26 01:40:57 +02:00
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.")
}
2018-01-29 23:14:55 +02:00
if t.Failed() {
t.Log(str)
}
2015-01-26 01:40:57 +02:00
}
2015-02-24 23:03:06 +02:00
2017-02-21 01:56:26 +02:00
func TestBoundary(t *testing.T) {
t.Parallel()
2018-01-29 23:14:55 +02:00
mailer := &SMTPMailer{"server", nil, rand.New(rand.NewSource(3))}
if got := mailer.boundary(); got != "fe3fhpsm69lx8jvnrnju0wr" {
2017-02-21 01:56:26 +02:00
t.Error("boundary was wrong", got)
}
}