コード例 #1
0
// TestEmailNewSignup tests sending an email to a new signup.
func TestEmailNewSignup(t *testing.T) {
	mailer := mailers.NewTestMailer()

	services.EmailNewSignup("*****@*****.**", mailer)

	if mailer.Delivered() != 1 {
		t.Fatal("The mailer should have delivered a single welcome email.")
	}
}
コード例 #2
0
// TestSendEmail ensures sending an email works as expected. It is trivial to
// test the methods other than SendEmail because they are so simple.
func TestSendEmail(t *testing.T) {
	testMailer := mailers.NewTestMailer()

	subject := "Testing is fun."
	body := "Email body."
	firstReceiver := "*****@*****.**"
	secondReceiver := "*****@*****.**"

	err := testMailer.SendEmail(subject, body, firstReceiver, secondReceiver)

	if err != nil {
		t.Fatal("Sending mail should not result in error.")
	}

	if testMailer.Delivered() != 1 {
		t.Fatal("One email should have been delivered.")
	}
}
コード例 #3
0
// stubMailer replaces the Mailgun mailer with a stubbed test mailer.
func stubMailer() {
	handlers.HandlersMailer = mailers.NewTestMailer()
}