onasty/internal/mailer/testing_mailer.go(view raw)
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 |
package mailer
import "context"
var _ Mailer = (*TestMailer)(nil)
type TestMailer struct {
emails map[string]string
}
// NewTestMailer create a mailer for tests
// that implementation of Mailer stores all sent email in memory
// to get the last email sent to a specific email use GetLastSentEmailToEmail
func NewTestMailer() *TestMailer {
return &TestMailer{
emails: make(map[string]string),
}
}
func (t *TestMailer) Send(_ context.Context, to, _, content string) error {
t.emails[to] = content
return nil
}
// GetLastSentEmailToEmail returns the last email sent to a specific email
func (t *TestMailer) GetLastSentEmailToEmail(email string) string {
return t.emails[email]
}
|