make Mailer an interface
This commit is contained in:
parent
dd2412463b
commit
08c09ffee7
10 changed files with 234 additions and 227 deletions
|
|
@ -1,13 +1,28 @@
|
|||
package email
|
||||
|
||||
import "log"
|
||||
|
||||
// MockMailer is a mock Mailer
|
||||
type MockMailer struct {
|
||||
LoginTokenFn func(name, email string, c ContentLoginToken) error
|
||||
LoginTokenInvoked bool
|
||||
SendFn func(m Message) error
|
||||
SendInvoked bool
|
||||
}
|
||||
|
||||
// LoginToken is a mock for LoginToken
|
||||
func (s *MockMailer) LoginToken(n, e string, c ContentLoginToken) error {
|
||||
s.LoginTokenInvoked = true
|
||||
return s.LoginTokenFn(n, e, c)
|
||||
func logMessage(m Message) {
|
||||
log.Printf("MockMailer email sent:\nSubject: %s\nTo: %s <%s>\nContext: %#v\n", m.Subject, m.To.Name, m.To.Address, m.Content)
|
||||
}
|
||||
|
||||
func NewMockMailer() *MockMailer {
|
||||
log.Println("ATTENTION: SMTP Mailer not configured => printing emails to stdout")
|
||||
return &MockMailer{
|
||||
SendFn: func(m Message) error {
|
||||
logMessage(m)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *MockMailer) Send(m Message) error {
|
||||
s.SendInvoked = true
|
||||
return s.SendFn(m)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue