tests

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2021 License: GPL-3.0 Imports: 18 Imported by: 0

README

maddy integration testing

Tests structure

The test library creates a temporary state and runtime directory, starts the server with the specified configuration file and lets you interact with it using a couple of convenient wrappers.

Running

To run tests, use go test -tags integration in this directory. Make sure to have a maddy executable in the current working directory. Use -integration.executable if the executable is named different or is placed somewhere else. Use -integration.coverprofile to pass -test.coverprofile your_value.RANDOM to test executable. See ./build_cover.sh to build a server executable instrumented with coverage counters.

Documentation

Overview

Package tests provides the framework for integration testing of maddy.

The packages core object is tests.T object that encapsulates all test state. It runs the server using test-provided configuration file and acts as a proxy for all interactions with the server.

Index

Constants

This section is empty.

Variables

View Source
var (
	TestBinary  = "./maddy"
	CoverageOut string
	DebugLog    bool
)
View Source
var (
	DefaultSourceIP    = net.IPv4(127, 109, 97, 100)
	DefaultSourceIPRev = "100.97.109.127"
)

Functions

This section is empty.

Types

type Conn

type Conn struct {
	T *T

	WriteTimeout time.Duration
	ReadTimeout  time.Duration

	Conn    net.Conn
	Scanner *bufio.Scanner
	// contains filtered or unexported fields
}

Conn is a helper that simplifies testing of text protocol interactions.

func (*Conn) AllowIOErr

func (c *Conn) AllowIOErr(ok bool)

AllowIOErr toggles whether I/O errors should be returned to the caller of Conn method or should immedately fail the test.

By default (ok = false), the latter happens.

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Expect

func (c *Conn) Expect(line string)

func (*Conn) ExpectPattern

func (c *Conn) ExpectPattern(pat string) string

ExpectPattern reads a line from the connection socket and checks whether is matches the supplied shell pattern (as defined by path.Match). The original line is returned.

func (*Conn) Readln

func (c *Conn) Readln() (string, error)

func (*Conn) Rebind

func (c *Conn) Rebind(subtest *T) *Conn

func (*Conn) SMTPNegotation

func (c *Conn) SMTPNegotation(ourName string, requireExts, blacklistExts []string)

func (*Conn) SMTPPlainAuth added in v0.5.0

func (c *Conn) SMTPPlainAuth(username, password string, expectOk bool)

func (*Conn) TLS

func (c *Conn) TLS()

func (*Conn) Write

func (c *Conn) Write(s string)

Write writes the string to the connection socket.

func (*Conn) Writeln

func (c *Conn) Writeln(s string)

type T

type T struct {
	*testing.T
	// contains filtered or unexported fields
}

func NewT

func NewT(t *testing.T) *T

func (*T) Close

func (t *T) Close()

func (*T) Config

func (t *T) Config(cfg string)

Config sets the configuration to use for the server. It must be called before Run.

func (*T) Conn

func (t *T) Conn(portName string) Conn

func (*T) Conn4

func (t *T) Conn4(sourceIP, portName string) Conn

Conn4 connects to the server listener at the specified named port using one of 127.0.0.0/8 addresses as a source.

func (*T) Conn6

func (t *T) Conn6(portName string) Conn

Conn6 connects to the server listener at the specified named port using IPv6 loopback.

func (*T) ConnUnnamed added in v0.3.0

func (t *T) ConnUnnamed(port uint16) Conn

func (*T) DNS

func (t *T) DNS(zones map[string]mockdns.Zone)

DNS sets the DNS zones to emulate for the tested server instance.

If it is not called before Run, DNS(nil) call is assumed which makes the mockdns server respond with NXDOMAIN to all queries.

func (*T) Env added in v0.3.0

func (t *T) Env(kv string)

func (*T) Port

func (t *T) Port(name string) uint16

Port allocates the random TCP port for use by test. It will made accessible in the configuration via environment variables with name in the form TEST_PORT_name.

If there is a port with name remote_smtp, it will be passed as the value for the -debug.smtpport parameter.

func (*T) Printf

func (t *T) Printf(f string, a ...interface{})

Printf implements Logger interfaces used by some libraries.

func (*T) Run

func (t *T) Run(waitListeners int)

Run completes the configuration of test environment and starts the test server.

T.Close should be called by the end of test to release any resources and shutdown the server.

The parameter waitListeners specifies the amount of listeners the server is supposed to configure. Run() will block before all of them are up.

func (*T) RuntimeDir

func (t *T) RuntimeDir() string

func (*T) StateDir

func (t *T) StateDir() string

func (*T) Subtest

func (t *T) Subtest(name string, f func(t *T))

Jump to

Keyboard shortcuts

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