tester

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2025 License: MIT Imports: 22 Imported by: 0

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

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

func LookupKey(f string, r []string) string

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 Standard added in v0.1.0

func Standard() *server.Server

Standard returns a standard SMTP server listening on a random Port.

func StandardWithAddress added in v0.1.0

func StandardWithAddress(addr string) *server.Server

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

type Backend struct {
	Mails sync.Map
}

Backend is the backend for out test server. It contains a sync.Map with all mails received.

func GetBackend added in v0.1.0

func GetBackend(s *server.Server) *Backend

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.

func (*Backend) Add added in v0.1.0

func (b *Backend) Add(m *Mail)

Add adds mail to backends map.

func (*Backend) Load added in v0.1.0

func (b *Backend) Load(from string, recipients []string) (*Mail, bool)

Load loads mail from 'from' to recipients 'recipients'. The ok result indicates whether value was found in the map.

func (*Backend) NewSession added in v0.1.0

func (b *Backend) NewSession(ctx context.Context, _ *server.Conn) (context.Context, server.Session, error)

NewSession returns a new Session.

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

func NewFakeConn(in string, out *bytes.Buffer) *FakeConn

NewFakeConn creates a new FakeConn with a string as a input.

func NewFakeConnStream added in v0.1.0

func NewFakeConnStream(in io.Reader, out *bytes.Buffer) *FakeConn

NewFakeConnStream creates a new FakeConn with a stream as a input.

func (FakeConn) Close added in v0.1.0

func (FakeConn) Close() error

Close always returns nil.

func (FakeConn) LocalAddr added in v0.1.0

func (FakeConn) LocalAddr() net.Addr

LocalAddr always returns nil.

func (FakeConn) RemoteAddr added in v0.1.0

func (f FakeConn) RemoteAddr() net.Addr

RemoteAddr always returns RemoteAddrReturn.

func (FakeConn) SetDeadline added in v0.1.0

func (FakeConn) SetDeadline(time.Time) error

SetDeadline always returns nil and does nothing.

func (FakeConn) SetReadDeadline added in v0.1.0

func (FakeConn) SetReadDeadline(time.Time) error

SetReadDeadline always returns nil and does nothing.

func (FakeConn) SetWriteDeadline added in v0.1.0

func (FakeConn) SetWriteDeadline(time.Time) error

SetWriteDeadline always returns nil and does nothing.

type Mail added in v0.1.0

type Mail struct {
	From       string
	Recipients []string
	Data       []byte
}

Mail is one mail received by SMTP server.

func (*Mail) LookupKey added in v0.1.0

func (m *Mail) LookupKey() string

LookupKey call LookupKey for current mail.

type Session added in v0.1.0

type Session struct {
	// contains filtered or unexported fields
}

A Session is returned after successful login.

func (Session) Auth added in v0.1.0

func (Session) Auth(_ context.Context, _ string) (sasl.Server, error)

Auth implements the Auth interface.

func (Session) AuthMechanisms added in v0.1.0

func (Session) AuthMechanisms(_ context.Context) []string

AuthMechanisms implements the AuthMechanisms interface.

func (*Session) Close added in v0.1.0

func (s *Session) Close(_ context.Context, _ error)

Close implements the Close interface.

func (*Session) Data added in v0.1.0

func (s *Session) Data(_ context.Context, r func() io.Reader) (string, error)

Data implements the Data interface.

func (Session) Logger added in v0.1.0

func (Session) Logger(_ context.Context) *slog.Logger

Logger implements the Logger interface.

func (*Session) Mail added in v0.1.0

func (s *Session) Mail(_ context.Context, from string, _ *smtp.MailOptions) error

Mail implements the Mail interface.

func (*Session) Rcpt added in v0.1.0

func (s *Session) Rcpt(_ context.Context, to string, _ *smtp.RcptOptions) error

Rcpt implements the Rcpt interface.

func (*Session) Reset added in v0.1.0

func (s *Session) Reset(ctx context.Context, _ bool) (context.Context, error)

Reset implements Reset interface.

func (Session) STARTTLS added in v0.1.0

func (Session) STARTTLS(_ context.Context, config *tls.Config) (*tls.Config, error)

STARTTLS implements the STARTTLS interface.

func (Session) Verify added in v0.1.0

func (Session) Verify(_ context.Context, _ string, _ *smtp.VrfyOptions) error

Verify implements the Verify interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL