testutils

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageBodySize             = 100 * 1024
	ExtraMessageHeaderFields    = 10
	ExtraMessageHeaderFieldSize = 50
)

Empirically observed "around average" values.

View Source
const DeliveryData = "A: 1\r\n" +
	"B: 2\r\n" +
	"\r\n" +
	"foobar\r\n"

Variables

View Source
var AuthDisabled = func(s *smtp.Server) {
	s.AuthDisabled = true
}

Functions

func BenchDelivery

func BenchDelivery(b *testing.B, target module.DeliveryTarget, sender string, recipientTemplates []string)

func BodyFromStr added in v0.3.0

func BodyFromStr(t *testing.T, literal string) (textproto.Header, buffer.MemoryBuffer)

func CheckMsg

func CheckMsg(t *testing.T, msg *Msg, sender string, rcpt []string)

func CheckMsgID

func CheckMsgID(t *testing.T, msg *Msg, sender string, rcpt []string, id string) string

func CheckSMTPConnLeak

func CheckSMTPConnLeak(t *testing.T, srv *smtp.Server)

func CheckSMTPErr

func CheckSMTPErr(t *testing.T, err error, code int, enchCode exterrors.EnhancedCode, msg string)

func CheckTestMessage

func CheckTestMessage(t *testing.T, tgt *Target, indx int, sender string, rcpt []string)

func Dir

func Dir(t *testing.T) string

Dir is a wrapper for os.MkdirTemp that fails the test on errors.

func DoTestDelivery

func DoTestDelivery(t *testing.T, tgt module.DeliveryTarget, from string, to []string) string

func DoTestDeliveryErr

func DoTestDeliveryErr(t *testing.T, tgt module.DeliveryTarget, from string, to []string) (string, error)

func DoTestDeliveryErrMeta

func DoTestDeliveryErrMeta(t *testing.T, tgt module.DeliveryTarget, from string, to []string, msgMeta *module.MsgMetadata) (string, error)

func DoTestDeliveryMeta

func DoTestDeliveryMeta(t *testing.T, tgt module.DeliveryTarget, from string, to []string, msgMeta *module.MsgMetadata) string

func DoTestDeliveryNonAtomic

func DoTestDeliveryNonAtomic(t *testing.T, c module.StatusCollector, tgt module.DeliveryTarget, from string, to []string) string

func FailOnConn

func FailOnConn(t *testing.T, addr string) net.Listener

FailOnConn fails the test if attempt is made to connect the specified endpoint.

func Logger

func Logger(t *testing.T, name string) log.Logger

func WaitForConnsClose

func WaitForConnsClose(t *testing.T, srv *smtp.Server)

Types

type Check

type Check struct {
	InitErr   error
	EarlyErr  error
	ConnRes   module.CheckResult
	SenderRes module.CheckResult
	RcptRes   module.CheckResult
	BodyRes   module.CheckResult

	ConnCalls   int
	SenderCalls int
	RcptCalls   int
	BodyCalls   int

	UnclosedStates int

	InstName string
}

func (*Check) CheckConnection

func (c *Check) CheckConnection(ctx context.Context, state *module.ConnState) error

func (*Check) CheckStateForMsg

func (c *Check) CheckStateForMsg(ctx context.Context, msgMeta *module.MsgMetadata) (module.CheckState, error)

func (*Check) Init

func (c *Check) Init(*config.Map) error

func (*Check) InstanceName

func (c *Check) InstanceName() string

func (*Check) Name

func (c *Check) Name() string

type FailingBuffer added in v0.3.0

type FailingBuffer struct {
	Blob []byte

	OpenError error
	IOError   error
}

func (FailingBuffer) Len added in v0.3.0

func (fb FailingBuffer) Len() int

func (FailingBuffer) Open added in v0.3.0

func (fb FailingBuffer) Open() (io.ReadCloser, error)

func (FailingBuffer) Remove added in v0.3.0

func (fb FailingBuffer) Remove() error

type Modifier

type Modifier struct {
	InstName string

	InitErr     error
	MailFromErr error
	RcptToErr   error
	BodyErr     error

	MailFrom map[string]string
	RcptTo   map[string][]string
	AddHdr   textproto.Header

	UnclosedStates int
}

func (Modifier) Init

func (m Modifier) Init(*config.Map) error

func (Modifier) InstanceName

func (m Modifier) InstanceName() string

func (Modifier) ModStateForMsg

func (m Modifier) ModStateForMsg(ctx context.Context, msgMeta *module.MsgMetadata) (module.ModifierState, error)

func (Modifier) Name

func (m Modifier) Name() string

type Msg

type Msg struct {
	MsgMeta  *module.MsgMetadata
	MailFrom string
	RcptTo   []string
	Body     []byte
	Header   textproto.Header
}

type MultiTable added in v0.6.0

type MultiTable struct {
	M   map[string][]string
	Err error
}

func (MultiTable) LookupMulti added in v0.6.0

func (m MultiTable) LookupMulti(_ context.Context, a string) ([]string, error)

type SMTPBackend

type SMTPBackend struct {
	Messages        []*SMTPMessage
	MailFromCounter int
	SessionCounter  int
	SourceEndpoints map[string]struct{}

	AuthErr     error
	MailErr     error
	RcptErr     map[string]error
	DataErr     error
	LMTPDataErr []error

	ActiveSessionsCounter atomic.Int32
}

func SMTPServer

func SMTPServer(t *testing.T, addr string, fn ...SMTPServerConfigureFunc) (*SMTPBackend, *smtp.Server)

func SMTPServerSTARTTLS

func SMTPServerSTARTTLS(t *testing.T, addr string, fn ...SMTPServerConfigureFunc) (*tls.Config, *SMTPBackend, *smtp.Server)

SMTPServerSTARTTLS starts a server listening on the specified addr with the STARTTLS extension supported.

Returned *tls.Config is for the client and is set to trust the server certificate.

func SMTPServerTLS

func SMTPServerTLS(t *testing.T, addr string, fn ...SMTPServerConfigureFunc) (*tls.Config, *SMTPBackend, *smtp.Server)

SMTPServerTLS starts a SMTP server listening on the specified addr with Implicit TLS.

func (*SMTPBackend) CheckMsg

func (be *SMTPBackend) CheckMsg(t *testing.T, indx int, from string, rcptTo []string)

func (*SMTPBackend) ConnectionCount added in v0.7.1

func (be *SMTPBackend) ConnectionCount() int

func (*SMTPBackend) NewSession added in v0.5.2

func (be *SMTPBackend) NewSession(conn *smtp.Conn) (smtp.Session, error)

type SMTPMessage

type SMTPMessage struct {
	From     string
	Opts     smtp.MailOptions
	To       []string
	Data     []byte
	Conn     *smtp.Conn
	AuthUser string
	AuthPass string
}

type SMTPServerConfigureFunc

type SMTPServerConfigureFunc func(*smtp.Server)

type Table added in v0.2.0

type Table struct {
	M   map[string]string
	Err error
}

func (Table) Lookup added in v0.2.0

func (m Table) Lookup(_ context.Context, a string) (string, bool, error)

type Target

type Target struct {
	Messages        []Msg
	DiscardMessages bool

	StartErr       error
	RcptErr        map[string]error
	BodyErr        error
	PartialBodyErr map[string]error
	AbortErr       error
	CommitErr      error

	InstName string
}

func (Target) Init

func (dt Target) Init(*config.Map) error

func (Target) InstanceName

func (dt Target) InstanceName() string

func (Target) Name

func (dt Target) Name() string

func (*Target) Start

func (dt *Target) Start(ctx context.Context, msgMeta *module.MsgMetadata, mailFrom string) (module.Delivery, error)

Jump to

Keyboard shortcuts

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