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) {
service := NewMockMailService()
service := NewMockMailService(func(params ...interface{}) {})
emailData := EmailMessage{
To: "test@example.com",

View File

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