testutils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: MIT Imports: 25 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\n" +
	"B: 2\n" +
	"\n" +
	"foobar\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 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 ioutil.TempDir 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 *smtp.ConnectionState) 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 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 SMTPBackend

type SMTPBackend struct {
	Messages        []*SMTPMessage
	MailFromCounter int

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

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) AnonymousLogin

func (be *SMTPBackend) AnonymousLogin(state *smtp.ConnectionState) (smtp.Session, error)

func (*SMTPBackend) CheckMsg

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

func (*SMTPBackend) Login

func (be *SMTPBackend) Login(state *smtp.ConnectionState, username, password string) (smtp.Session, error)

type SMTPMessage

type SMTPMessage struct {
	From     string
	Opts     smtp.MailOptions
	To       []string
	Data     []byte
	State    *smtp.ConnectionState
	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(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