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

	// Config is meant to be used by internal packages like prosody and ejabberd
	// to store their internal representation of the config before writing it out.
	Config interface{}
	// 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) C2SAddr

func (cmd *Cmd) C2SAddr() (net.Addr, string)

C2SAddr returns the client-to-server address and network.

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

func (cmd *Cmd) C2SPort() string

C2SPort returns the port on which the C2S listener is running (if any).

func (*Cmd) ClientCert

func (cmd *Cmd) ClientCert(*tls.CertificateRequestInfo) (*tls.Certificate, error)

ClientCert returns the last configured client certificate. The certificate request info is currently ignored and is only there to make promoting this method to a function and using it as tls.Config.GetClientCertificate possible.

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

func (cmd *Cmd) ComponentAddr() (net.Addr, string)

ComponentAddr returns the component address and network.

func (*Cmd) ComponentConn

func (cmd *Cmd) ComponentConn(ctx context.Context) (net.Conn, error)

ComponentConn dials a connection to the component socket and returns it without negotiating a session.

func (*Cmd) ComponentListen

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

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

func (*Cmd) ConfigDir

func (cmd *Cmd) ConfigDir() string

ConfigDir returns the temporary directory used to store config files.

func (*Cmd) Conn

func (cmd *Cmd) Conn(ctx context.Context, s2s bool) (net.Conn, error)

Conn dials a connection and returns it without negotiating a session.

func (*Cmd) DialClient

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

DialClient attempts to connect to the server with a client-to-server (c2s) connection by dialing the address reserved by C2SListen and then negotiating a stream with the location set to the domainpart of j and the origin set to j.

func (*Cmd) DialServer

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

DialServer attempts to connect to the server with a server-to-server (s2s) connection by dialing the address reserved by S2SListen and then negotiating a stream.

func (*Cmd) Done

func (cmd *Cmd) Done() <-chan error

Done returns a channel that's closed when the commands process terminates.

func (*Cmd) HTTPConn

func (cmd *Cmd) HTTPConn(ctx context.Context, secure bool) (net.Conn, error)

HTTPConn dials a connection and returns it without negotiating a session.

func (*Cmd) HTTPListen

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

HTTPListen returns a listener with a random port (for HTTP). The listener is created on the first call to HTTPListener. Subsequent calls ignore the arguments and return the existing listener.

func (*Cmd) HTTPPort

func (cmd *Cmd) HTTPPort() string

HTTPPort returns the port on which the HTTP listener is running (if any).

func (*Cmd) HTTPSListen

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

HTTPSListen returns a listener with a random port (for HTTPS). The listener is created on the first call to HTTPSListener. Subsequent calls ignore the arguments and return the existing listener.

func (*Cmd) HTTPSPort

func (cmd *Cmd) HTTPSPort() string

HTTPSPort returns the port on which the HTTPS listener is running (if any).

func (*Cmd) S2SAddr

func (cmd *Cmd) S2SAddr() (net.Addr, string)

S2SAddr returns the server-to-server address and network.

func (*Cmd) S2SListen

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

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

func (*Cmd) Start

func (cmd *Cmd) Start() error

Start runs the command.

func (*Cmd) Stdin

func (cmd *Cmd) Stdin() io.WriteCloser

Stdin returns a pipe to the commands standard input.

func (*Cmd) User

func (cmd *Cmd) User() (jid.JID, string)

User returns the address and password of a user created on the server (if any).

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 ClientCert

func ClientCert(name string) Option

ClientCert creates a private key and certificate with the given name that can be used for TLS authentication.

func Defer

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

Defer is an option that calls f after the command is started. If multiple Defer options are passed they are called in order until an error is encountered.

func Log

func Log() Option

Log configures the command to copy stdout to the current testing.T. This should not be used for CLI or TUI clients.

func LogFile

func LogFile(f string, tee io.Writer) Option

LogFile reads the provided file into the log in the same way that the Log option reads a commands standard output. It can optionally copy the command to the provided io.Writer (if non-nil) as well similar to the tee(1) command. Normally this should be used by the various server and client packages to read a FIFO which has been configured to be the log by the actual client process so that it functions similar to the tail(1) command.

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. If multiple shutdown options are used the functions will be run in the order in which they are passed until an error is encountered.

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.

func User

func User(user jid.JID, pass string) Option

User sets the values that will be returned by a call to cmd.User later. It does not actually create a user.

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
Package ejabberd facilitates integration testing against Ejabberd.
Package ejabberd facilitates integration testing against Ejabberd.
Package mcabber facilitates integration testing against Mcabber.
Package mcabber facilitates integration testing against Mcabber.
Package mellium facilitates integration testing against clients.
Package mellium facilitates integration testing against clients.
Package prosody facilitates integration testing against Prosody.
Package prosody facilitates integration testing against Prosody.
Package sendxmpp facilitates integration testing with sendxmpp.
Package sendxmpp facilitates integration testing with sendxmpp.