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