Documentation

Overview

Package integration contains helpers for integration testing.

Normally users writing integration tests should not use this package directly, instead they should use the packges in subdirectories of this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	*exec.Cmd
	// contains filtered or unexported fields
}

Cmd is an external command being prepared or run.

A Cmd cannot be reused after calling its Run, Output or CombinedOutput methods.

func New

func New(ctx context.Context, name string, opts ...Option) (*Cmd, error)

New creates a new, unstarted, command.

The provided context is used to kill the process (by calling os.Process.Kill) if the context becomes done before the command completes on its own.

func (*Cmd) C2SListen

func (cmd *Cmd) C2SListen(network, addr string) (net.Listener, error)

C2SListen returns a listener with a random port. The listener is created on the first call to C2SListener. Subsequent calls ignore the arguments and return the existing listener.

func (*Cmd) Close

func (cmd *Cmd) Close() error

Close kills the command if it is still running and cleans up any temporary resources that were created.

func (*Cmd) ConfigDir

func (cmd *Cmd) ConfigDir() string

ConfigDir returns the temporary directory used to store config files.

func (*Cmd) Dial

func (cmd *Cmd) Dial(ctx context.Context, j jid.JID, t *testing.T, features ...xmpp.StreamFeature) (*xmpp.Session, error)

Dial attempts to connect to the server by dialing localhost and then negotiating a stream with the location set to the domainpart of j and the origin set to j.

type Option

type Option func(cmd *Cmd) error

Option is used to configure a Cmd.

func Args

func Args(f ...string) Option

Args sets additional command line args to be passed to the command.

func Cert

func Cert(name string) Option

Cert creates a private key and certificate with the given name.

func Defer

func Defer(f func(*Cmd) error) Option

Defer is an option that calls f the command is started.

func Log

func Log() Option

Log configures the command to log output to the current testing.T.

func LogXML

func LogXML() Option

LogXML configures the command to log sent and received XML to the current testing.T.

func Shutdown

func Shutdown(f func(*Cmd) error) Option

Shutdown is run before the configuration is removed and is meant to gracefully shutdown the application in case it does not handle the kill signal correctly.

func TempFile

func TempFile(cfgFileName string, f func(*Cmd, io.Writer) error) Option

TempFile creates a file in the commands temporary working directory. After all configuration is complete it then calls f to populate the config files.

type SubtestRunner

type SubtestRunner func(func(context.Context, *testing.T, *Cmd)) bool

SubtestRunner is the signature of a function that can be used to start subtests.

func Test

func Test(ctx context.Context, name string, t *testing.T, opts ...Option) SubtestRunner

Test starts a command and returns a function that runs tests as a subtest using t.Run. Multiple calls to the returned function will result in uniquely named subtests. When all subtests have completed, the daemon is stopped.

Directories

Path Synopsis
ejabberd Package ejabberd facilitates integration testing against Ejabberd.
prosody Package prosody facilitates integration testing against Prosody.