Documentation ¶
Index ¶
- type Backend
- type BuildOption
- type BuildParams
- type Confort
- func (cft *Confort) Build(tb testing.TB, ctx context.Context, b *BuildParams, opts ...BuildOption)
- func (cft *Confort) LazyRun(tb testing.TB, ctx context.Context, c *ContainerParams, opts ...RunOption) *Container
- func (cft *Confort) Namespace() string
- func (cft *Confort) Network() *types.NetworkResource
- func (cft *Confort) Run(tb testing.TB, ctx context.Context, c *ContainerParams, opts ...RunOption) *Container
- type Connection
- type Container
- func (c *Container) Alias() string
- func (c *Container) ID() string
- func (c *Container) Name() string
- func (c *Container) Use(tb testing.TB, ctx context.Context, exclusive bool, opts ...UseOption) Ports
- func (c *Container) UseExclusive(tb testing.TB, ctx context.Context, opts ...UseOption) Ports
- func (c *Container) UseShared(tb testing.TB, ctx context.Context, opts ...UseOption) Ports
- type ContainerParams
- type InitFunc
- type Namespace
- type NewOption
- func WithBeacon(conn *Connection) NewOption
- func WithClientOptions(opts ...client.Opt) NewOption
- func WithDefaultTimeout(d time.Duration) NewOption
- func WithNamespace(namespace string, force bool) NewOption
- func WithResourcePolicy(s ResourcePolicy) NewOption
- func WithTerminateFunc(f *func()) NewOption
- type Ports
- type ResourcePolicy
- type RunOption
- func WithConfigConsistency(check bool) RunOption
- func WithContainerConfig(f func(config *container.Config)) RunOption
- func WithHostConfig(f func(config *container.HostConfig)) RunOption
- func WithNetworkingConfig(f func(config *network.NetworkingConfig)) RunOption
- func WithPullOptions(opts *types.ImagePullOptions, out io.Writer) RunOption
- type UseOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BuildOption ¶
func WithBuildOutput ¶
func WithBuildOutput(dst io.Writer) BuildOption
WithBuildOutput sets dst that the output during build will be written.
func WithForceBuild ¶
func WithForceBuild() BuildOption
WithForceBuild forces to build an image even if it already exists.
func WithImageBuildOptions ¶
func WithImageBuildOptions(f func(option *types.ImageBuildOptions)) BuildOption
WithImageBuildOptions modifies the configuration of build. The argument `option` already contains required values, according to Build.
type BuildParams ¶ added in v0.3.0
type Confort ¶
type Confort struct {
// contains filtered or unexported fields
}
func New ¶
New creates Confort instance which is an interface of controlling containers. Confort creates docker resources like a network and containers. Also, it provides an exclusion control of container usage.
If you want to control the same containers across parallelized tests, enable integration with the beacon server by using `confort` command and WithBeacon option.
func (*Confort) Build ¶
func (cft *Confort) Build(tb testing.TB, ctx context.Context, b *BuildParams, opts ...BuildOption)
Build creates new image from given Dockerfile and context directory.
When same name image already exists, it doesn't perform building. WithForceBuild enables us to build image on every call of Build.
func (*Confort) LazyRun ¶
func (cft *Confort) LazyRun(tb testing.TB, ctx context.Context, c *ContainerParams, opts ...RunOption) *Container
LazyRun creates container but doesn't start. When container is required by UseShared or UseExclusive, the container starts.
If container is already created/started by other test or process, LazyRun just store container info. It makes no error.
func (*Confort) Network ¶ added in v0.2.0
func (cft *Confort) Network() *types.NetworkResource
Network returns docker network representation associated with Confort.
func (*Confort) Run ¶
func (cft *Confort) Run(tb testing.TB, ctx context.Context, c *ContainerParams, opts ...RunOption) *Container
Run starts container with given parameters. If container already exists and not started, it starts. It reuses already started container and its endpoint information.
When container is already existing and connected to another network, Run and other methods let the container connect to this network and create alias. For now, without specifying host port, container loses the port binding occasionally. If you want to use port binding and use a container with several network, and encounter such trouble, give it a try.
type Connection ¶
type Connection struct { Conn *grpc.ClientConn // contains filtered or unexported fields }
func ConnectBeacon ¶
func ConnectBeacon(tb testing.TB, ctx context.Context) *Connection
ConnectBeacon tries to connect beacon server and returns its result. The address of server will be read from CFT_BEACON_ADDR or lock file specified as CFT_LOCKFILE.
With `confort test` command ¶
This command starts beacon server and sets the address as CFT_BEACON_ADDR automatically.
With `confort start` command ¶
This command starts beacon server and creates a lock file that contains the address. The default filename is ".confort.lock" and you don't need to set the file name as CFT_LOCKFILE. If you set a custom filename with "-lock-file" option, also you have to set the file name as CFT_LOCKFILE, or you can set address that read from lock file as CFT_BEACON_ADDR.
func (*Connection) Enabled ¶
func (c *Connection) Enabled() bool
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container represents a created container and its controller.
func (*Container) Alias ¶ added in v0.3.0
Alias returns a host name of the container. The alias is valid only in a docker network created in New or attached by Confort.Run.
func (*Container) Use ¶ added in v0.3.0
func (c *Container) Use(tb testing.TB, ctx context.Context, exclusive bool, opts ...UseOption) Ports
Use acquires a lock for using the container and returns its endpoint. If exclusive is true, it requires to use the container exclusively. When other tests have already acquired an exclusive or shared lock for the container, it blocks until all previous locks are released.
func (*Container) UseExclusive ¶ added in v0.3.0
UseExclusive acquires an exclusive lock for using the container explicitly and returns its endpoint.
type ContainerParams ¶ added in v0.3.0
type Namespace ¶
type Namespace interface { Namespace() string Network() *types.NetworkResource CreateContainer(ctx context.Context, name string, container *container.Config, host *container.HostConfig, network *network.NetworkingConfig, configConsistency bool, wait *wait.Waiter, pullOptions *types.ImagePullOptions, pullOut io.Writer) (string, error) StartContainer(ctx context.Context, name string) (Ports, error) Release(ctx context.Context) error }
type NewOption ¶
func WithBeacon ¶
func WithBeacon(conn *Connection) NewOption
WithBeacon configures Confort to integrate with a starting beacon server. The beacon server is started by the "confort" command. Use Connection object given from ConnectBeacon as the argument conn.
For detail, see ConnectBeacon and "confort help".
func WithClientOptions ¶
WithClientOptions sets options for Docker API client. Default option is client.FromEnv. For detail, see client.NewClientWithOpts.
func WithDefaultTimeout ¶
WithDefaultTimeout sets the default timeout for each request to the Docker API and beacon server. The default value of the "default timeout" is 1 min. If default timeout is 0, Confort doesn't apply any timeout for ctx.
If a timeout has already been set to ctx, the default timeout is not applied.
func WithNamespace ¶
WithNamespace specifies namespace of Confort. Default namespace is the value of the CFT_NAMESPACE environment variable. The "confort test" command has "-namespace" option that overrides the variable. If force is true, the value of the argument namespace takes precedence.
If neither CFT_NAMESPACE nor WithNamespace is set, New fails.
func WithResourcePolicy ¶
func WithResourcePolicy(s ResourcePolicy) NewOption
WithResourcePolicy overrides the policy for handling Docker resources that already exist, such as containers and networks. By default, ResourcePolicyReuse or the value of the CFT_RESOURCE_POLICY environment variable, if set, is used. The "confort test" command has "-policy" option that overrides the variable.
func WithTerminateFunc ¶ added in v0.2.0
func WithTerminateFunc(f *func()) NewOption
WithTerminateFunc extracts the function to release all resources created by Confort. With this option, the responsibility for termination is passed to the user.
type Ports ¶
func (Ports) Binding ¶
func (p Ports) Binding(port nat.Port) (b nat.PortBinding)
Binding returns the first value associated with the given container port. If there are no values associated with the port, Binding returns zero value. To access multiple values, use the nat.PortMap directly.
func (Ports) HostPort ¶ added in v0.2.0
HostPort returns "host:port" style string of the first value associated with the given container port. If there are no values associated with the port, HostPort returns empty string.
type ResourcePolicy ¶
type ResourcePolicy string
const ( ResourcePolicyError ResourcePolicy = beaconutil.ResourcePolicyError ResourcePolicyReuse ResourcePolicy = beaconutil.ResourcePolicyReuse ResourcePolicyReusable ResourcePolicy = beaconutil.ResourcePolicyReusable ResourcePolicyTakeOver ResourcePolicy = beaconutil.ResourcePolicyTakeOver )
type RunOption ¶
func WithConfigConsistency ¶
WithConfigConsistency enables/disables the test checking consistency of configurations. By default, this test is enabled. NOTICE: This is quite experimental feature.
func WithContainerConfig ¶
WithContainerConfig modifies the configuration of container. The argument `config` already contains required values to create container, apply your values with care.
func WithHostConfig ¶
func WithHostConfig(f func(config *container.HostConfig)) RunOption
WithHostConfig modifies the configuration of container from host side. The argument `config` already contains required values to create container, apply your values with care.
func WithNetworkingConfig ¶
func WithNetworkingConfig(f func(config *network.NetworkingConfig)) RunOption
WithNetworkingConfig modifies the configuration of network. The argument `config` already contains required values to connecting to bridge network, and a container cannot join multi-networks on container creation.
func WithPullOptions ¶
func WithPullOptions(opts *types.ImagePullOptions, out io.Writer) RunOption
WithPullOptions enables to pull image that not exists. For example, if you want to use an image hosted in private repository, you have to fill RegistryAuth field.
The output will be written to `out`. If nil, io.Discard will be used.
type UseOption ¶
func WithInitFunc ¶
WithInitFunc sets initializer to set up container using the given port. The init will be performed only once per container, executed with an exclusive lock. If you use a container with Confort.UseShared, the lock state is downgraded to the shared lock after init.
The returned error makes the acquired lock released and testing.TB fail. After that, you can attempt to use the container and init again.
func WithReleaseFunc ¶
func WithReleaseFunc(f *func()) UseOption
WithReleaseFunc extracts the function to release lock of the container. With this option, the responsibility for releasing the container is passed to the user.