dockertest

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrClosed is a common error for use when a container has been closed.
	ErrClosed = errors.New("container has been closed")
)

Functions

func SetupNetwork

func SetupNetwork(ctx context.Context, pool dockertest.Pool, cleanIfExists bool) error

SetupNetwork sets up a network within docker.

func TCPPort

func TCPPort(port int) network.Port

TCPPort returns the moby representation of a TCP container port, e.g. "9000/tcp".

Types

type GoalStateVerifier

type GoalStateVerifier func(output string, err error) error

GoalStateVerifier asserts that a resource is in a particular state. TODO: more info here; this interface is unclear from usage

type Image

type Image struct {
	Name string
	Tag  string
}

Image represents a docker image.

type Resource

type Resource struct {
	// contains filtered or unexported fields
}

Resource is an object that provides a handle to a service being spun up via docker.

func NewDockerResource

func NewDockerResource(
	ctx context.Context,
	pool dockertest.Pool,
	resourceOpts ResourceOptions,
) (*Resource, error)

NewDockerResource creates a new DockerResource. If resourceOpts.Image is empty, it will attempt to connect to an existing container. Otherwise, it will start the container with the specified image.

func (*Resource) Close

func (c *Resource) Close() error

Close closes and cleans up the resource.

func (*Resource) Closed

func (c *Resource) Closed() bool

Closed returns true if the resource has been closed.

func (*Resource) Exec

func (c *Resource) Exec(commands ...string) (string, error)

Exec runs commands within a docker container.

func (*Resource) GetPort

func (c *Resource) GetPort(bindPort int) (int, error)

GetPort retrieves the port for accessing this resource.

func (*Resource) GetURL

func (c *Resource) GetURL(port int, path string) string

GetURL retrieves the URL for accessing this resource.

func (*Resource) GoalStateExec

func (c *Resource) GoalStateExec(
	verifier GoalStateVerifier,
	commands ...string,
) error

GoalStateExec runs commands within a container until a specified goal state is met.

func (*Resource) Resource

func (c *Resource) Resource() dockertest.Resource

Resource is the underlying dockertest resource used by this Resource. It can be used to perform more advanced operations not exposed by this class.

type ResourceOptions

type ResourceOptions struct {
	OverrideDefaults bool
	Source           string
	ContainerName    string
	Image            Image
	PortList         []int
	PortMappings     network.PortMap

	// NoNetworkOverlay if set, disables use of the default integration testing network we create (networkName).
	NoNetworkOverlay bool

	Cmd []string

	// Env is the environment for the docker container; it is passed through to dockertest.WithEnv.
	// Format should be: VAR=value
	Env []string
	// Mounts creates mounts in the container that map back to a resource
	// on the host system.
	Mounts []string
	// TmpfsMounts creates mounts to the container's temporary file system
	TmpfsMounts    []string
	InstrumentOpts instrument.Options
}

ResourceOptions returns options for creating a Resource.

func (ResourceOptions) WithDefaults

func (o ResourceOptions) WithDefaults(
	defaultOpts ResourceOptions) ResourceOptions

NB: this will fill unset fields with given default values.

Jump to

Keyboard shortcuts

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