feat: add callback function to mock

This commit is contained in:
Urko. 2023-10-21 21:31:07 +02:00
parent a946f769ac
commit 1371889d6d
2 changed files with 5 additions and 2 deletions

View File

@ -43,7 +43,7 @@ func TestNewConfig_MissingEnvFile(t *testing.T) {
} }
func TestMockSendEmail(t *testing.T) { func TestMockSendEmail(t *testing.T) {
service := NewMockMailService() service := NewMockMailService(func(params ...interface{}) {})
emailData := EmailMessage{ emailData := EmailMessage{
To: "test@example.com", To: "test@example.com",

View File

@ -6,7 +6,9 @@ import (
"net/smtp" "net/smtp"
) )
func NewMockMailService() *EmailService { type MockCallbackFn func(params ...interface{})
func NewMockMailService(callbackFn MockCallbackFn, params ...interface{}) *EmailService {
return &EmailService{ return &EmailService{
auth: smtp.PlainAuth("", "", "", ""), auth: smtp.PlainAuth("", "", "", ""),
host: "", host: "",
@ -17,6 +19,7 @@ func NewMockMailService() *EmailService {
ServerName: "", ServerName: "",
}, },
dial: func(hostPort string) (SMTPClientIface, error) { dial: func(hostPort string) (SMTPClientIface, error) {
callbackFn(params)
return &mockSMTP{}, nil return &mockSMTP{}, nil
}, },
} }