email-sender/pkg/email/mock.go

62 lines
1.1 KiB
Go
Raw Normal View History

2023-10-21 20:51:20 +02:00
package email
import (
"crypto/tls"
"io"
"net/smtp"
)
2023-10-21 21:31:07 +02:00
type MockCallbackFn func(params ...interface{})
func NewMockMailService(callbackFn MockCallbackFn, params ...interface{}) *EmailService {
return &EmailService{
auth: smtp.PlainAuth("", "", "", ""),
host: "",
port: "",
from: "",
tlsconfig: &tls.Config{
InsecureSkipVerify: true,
ServerName: "",
},
dial: func(hostPort string) (SMTPClientIface, error) {
2023-10-21 21:31:07 +02:00
callbackFn(params)
return &mockSMTP{}, nil
},
}
2023-10-21 20:51:20 +02:00
}
type mockWriter struct{}
func (w *mockWriter) Close() error {
2023-10-21 20:51:20 +02:00
return nil
}
func (w *mockWriter) Write(p []byte) (n int, err error) {
2023-10-21 20:51:20 +02:00
return 10, nil
}
// Mock SMTP Client
type mockSMTP struct{}
2023-10-21 20:51:20 +02:00
func (m *mockSMTP) StartTLS(*tls.Config) error {
2023-10-21 20:51:20 +02:00
return nil
}
func (m *mockSMTP) Auth(a smtp.Auth) error {
2023-10-21 20:51:20 +02:00
return nil
}
func (m *mockSMTP) Close() error {
2023-10-21 20:51:20 +02:00
return nil
}
func (m *mockSMTP) Data() (io.WriteCloser, error) {
return &mockWriter{}, nil
2023-10-21 20:51:20 +02:00
}
func (m *mockSMTP) Mail(from string) error {
2023-10-21 20:51:20 +02:00
return nil
}
func (m *mockSMTP) Quit() error {
2023-10-21 20:51:20 +02:00
return nil
}
func (m *mockSMTP) Rcpt(to string) error {
2023-10-21 20:51:20 +02:00
return nil
}