From 1371889d6d5a09de9dc8b94ca4b7466522f59450 Mon Sep 17 00:00:00 2001 From: "Urko." Date: Sat, 21 Oct 2023 21:31:07 +0200 Subject: [PATCH] feat: add callback function to mock --- pkg/email/email_test.go | 2 +- pkg/email/mock.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/email/email_test.go b/pkg/email/email_test.go index 34cdf88..f70ed58 100755 --- a/pkg/email/email_test.go +++ b/pkg/email/email_test.go @@ -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", diff --git a/pkg/email/mock.go b/pkg/email/mock.go index 3920661..c7944bb 100644 --- a/pkg/email/mock.go +++ b/pkg/email/mock.go @@ -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 }, }