Documentation
¶
Overview ¶
Package smtptester implements a simple SMTP server for testing. All received mails are saved in a sync.Map with a key:
From+Recipient1+Recipient2
Mails to the same sender and recipients will overwrite a previous received mail, when the recipients slice has the same order as in the mail received before.
Index ¶
- func GenX509KeyPair(domain string) (tls.Certificate, error)
- func LookupKey(f string, r []string) string
- func ReaderCompareTest(t *testing.T, fs *embed.FS, path string, ...)
- func Standard() *server.Server
- func StandardWithAddress(addr string) *server.Server
- func WriterCompareTest(t *testing.T, fs *embed.FS, path string, ...)
- type Backend
- type FakeConn
- type Mail
- type Session
- func (Session) Auth(_ context.Context, _ string) (sasl.Server, error)
- func (Session) AuthMechanisms(_ context.Context) []string
- func (s *Session) Close(_ context.Context, _ error)
- func (s *Session) Data(_ context.Context, r func() io.Reader) (string, error)
- func (Session) Logger(_ context.Context) *slog.Logger
- func (s *Session) Mail(_ context.Context, from string, _ *smtp.MailOptions) error
- func (s *Session) Rcpt(_ context.Context, to string, _ *smtp.RcptOptions) error
- func (s *Session) Reset(ctx context.Context, _ bool) (context.Context, error)
- func (Session) STARTTLS(_ context.Context, config *tls.Config) (*tls.Config, error)
- func (Session) Verify(_ context.Context, _ string, _ *smtp.VrfyOptions) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenX509KeyPair ¶
func GenX509KeyPair(domain string) (tls.Certificate, error)
GenX509KeyPair generates a self signed smtp server certificate with the given domain.
func LookupKey ¶ added in v0.1.0
LookupKey returns a key of the format:
m.From+m.Recipient_1+m.Recipient_2...
func ReaderCompareTest ¶ added in v0.1.3
func ReaderCompareTest(t *testing.T, fs *embed.FS, path string, expected func(io.Reader) ([]byte, error), actual func(io.Reader) ([]byte, error))
ReaderCompareTest reads all files out of fs[path] and compares the result of the expected func against the actual func. To simulate differences of Read calls with differnt sizes it slices the files in increasing sizes up to 4048.
func StandardWithAddress ¶ added in v0.1.0
StandardWithAddress with address returns a standard SMTP server listenting on addr.
func WriterCompareTest ¶ added in v0.1.3
func WriterCompareTest(t *testing.T, fs *embed.FS, path string, expected func(io.Writer) io.WriteCloser, actual func(io.Writer) io.WriteCloser)
WriterCompareTest reads all files out of fs[path] and compares the expected func against the actual func. To simulate differences of Write calls of differnt sizes it slices the files in increasing sizes up to 4048.
Types ¶
type Backend ¶ added in v0.1.0
Backend is the backend for out test server. It contains a sync.Map with all mails received.
func GetBackend ¶ added in v0.1.0
GetBackend returns the concrete type *Backend from SMTP server.
func NewBackend ¶ added in v0.1.0
func NewBackend() *Backend
NewBackend returns a new Backend with an empty (not nil) Mails map.
type FakeConn ¶ added in v0.1.0
type FakeConn struct { io.ReadWriter RemoteAddrReturn net.Addr }
FakeConn fakes a conn for testing.
func NewFakeConn ¶ added in v0.1.0
NewFakeConn creates a new FakeConn with a string as a input.
func NewFakeConnStream ¶ added in v0.1.0
NewFakeConnStream creates a new FakeConn with a stream as a input.
func (FakeConn) RemoteAddr ¶ added in v0.1.0
RemoteAddr always returns RemoteAddrReturn.
func (FakeConn) SetDeadline ¶ added in v0.1.0
SetDeadline always returns nil and does nothing.
func (FakeConn) SetReadDeadline ¶ added in v0.1.0
SetReadDeadline always returns nil and does nothing.
type Session ¶ added in v0.1.0
type Session struct {
// contains filtered or unexported fields
}
A Session is returned after successful login.
func (Session) AuthMechanisms ¶ added in v0.1.0
AuthMechanisms implements the AuthMechanisms interface.