feat: add callback function to mock
This commit is contained in:
parent
a946f769ac
commit
1371889d6d
|
@ -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",
|
||||||
|
|
|
@ -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
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue