feat: expose mock email service function
This commit is contained in:
parent
9eb969a4c3
commit
a946f769ac
|
@ -1,7 +1,6 @@
|
|||
package email
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/smtp"
|
||||
"os"
|
||||
|
@ -44,19 +43,7 @@ func TestNewConfig_MissingEnvFile(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMockSendEmail(t *testing.T) {
|
||||
service := &EmailService{
|
||||
auth: smtp.PlainAuth("", "", "", ""),
|
||||
host: "",
|
||||
port: "",
|
||||
from: "",
|
||||
tlsconfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
ServerName: "",
|
||||
},
|
||||
dial: func(hostPort string) (SMTPClientIface, error) {
|
||||
return &MockSMTP{}, nil
|
||||
},
|
||||
}
|
||||
service := NewMockMailService()
|
||||
|
||||
emailData := EmailMessage{
|
||||
To: "test@example.com",
|
||||
|
|
|
@ -6,36 +6,53 @@ import (
|
|||
"net/smtp"
|
||||
)
|
||||
|
||||
type MockWriter struct{}
|
||||
func NewMockMailService() *EmailService {
|
||||
return &EmailService{
|
||||
auth: smtp.PlainAuth("", "", "", ""),
|
||||
host: "",
|
||||
port: "",
|
||||
from: "",
|
||||
tlsconfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
ServerName: "",
|
||||
},
|
||||
dial: func(hostPort string) (SMTPClientIface, error) {
|
||||
return &mockSMTP{}, nil
|
||||
},
|
||||
}
|
||||
|
||||
func (w *MockWriter) Close() error {
|
||||
}
|
||||
|
||||
type mockWriter struct{}
|
||||
|
||||
func (w *mockWriter) Close() error {
|
||||
return nil
|
||||
}
|
||||
func (w *MockWriter) Write(p []byte) (n int, err error) {
|
||||
func (w *mockWriter) Write(p []byte) (n int, err error) {
|
||||
return 10, nil
|
||||
}
|
||||
|
||||
// Mock SMTP Client
|
||||
type MockSMTP struct{}
|
||||
type mockSMTP struct{}
|
||||
|
||||
func (m *MockSMTP) StartTLS(*tls.Config) error {
|
||||
func (m *mockSMTP) StartTLS(*tls.Config) error {
|
||||
return nil
|
||||
}
|
||||
func (m *MockSMTP) Auth(a smtp.Auth) error {
|
||||
func (m *mockSMTP) Auth(a smtp.Auth) error {
|
||||
return nil
|
||||
}
|
||||
func (m *MockSMTP) Close() error {
|
||||
func (m *mockSMTP) Close() error {
|
||||
return nil
|
||||
}
|
||||
func (m *MockSMTP) Data() (io.WriteCloser, error) {
|
||||
return &MockWriter{}, nil
|
||||
func (m *mockSMTP) Data() (io.WriteCloser, error) {
|
||||
return &mockWriter{}, nil
|
||||
}
|
||||
func (m *MockSMTP) Mail(from string) error {
|
||||
func (m *mockSMTP) Mail(from string) error {
|
||||
return nil
|
||||
}
|
||||
func (m *MockSMTP) Quit() error {
|
||||
func (m *mockSMTP) Quit() error {
|
||||
return nil
|
||||
}
|
||||
func (m *MockSMTP) Rcpt(to string) error {
|
||||
func (m *mockSMTP) Rcpt(to string) error {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue