email-sender/pkg/email/mock.go

59 lines
997 B
Go

package email
import (
"crypto/tls"
"io"
"net/smtp"
)
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
},
}
}
type mockWriter struct{}
func (w *mockWriter) Close() error {
return nil
}
func (w *mockWriter) Write(p []byte) (n int, err error) {
return 10, nil
}
// Mock SMTP Client
type mockSMTP struct{}
func (m *mockSMTP) StartTLS(*tls.Config) error {
return nil
}
func (m *mockSMTP) Auth(a smtp.Auth) error {
return nil
}
func (m *mockSMTP) Close() error {
return nil
}
func (m *mockSMTP) Data() (io.WriteCloser, error) {
return &mockWriter{}, nil
}
func (m *mockSMTP) Mail(from string) error {
return nil
}
func (m *mockSMTP) Quit() error {
return nil
}
func (m *mockSMTP) Rcpt(to string) error {
return nil
}