Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContainerSpec ¶
type ContainerSpec struct {
// Image is the container image to use (e.g., "alpine:latest")
// If FromDockerfile is set, this is ignored.
Image string
// FromDockerfile allows building an image from a Dockerfile.
FromDockerfile testcontainers.FromDockerfile
// Replicas is the number of identical containers to create.
// When > 1, the WorldContainer represents a group of replicas.
// Methods are executed on all replicas. The group name resolves
// to all replica IPs via DNS round-robin.
// Defaults to 1 if unset or zero.
Replicas int
// Entrypoint overrides the container's default entrypoint
Entrypoint []string
// Cmd is the command to run in the container
Cmd []string
// Env is a map of environment variables to set in the container
Env map[string]string
// ExposedPorts is a list of ports to expose (e.g., "80", "8080/tcp")
ExposedPorts []string
// Files is a list of files to copy into the container before it starts.
Files []testcontainers.ContainerFile
// Tmpfs is a map of tmpfs mounts (path -> options)
Tmpfs map[string]string
// ConfigModifier allows customizing the container config.
ConfigModifier func(*container.Config)
// HostConfigModifier allows customizing the Docker host config.
HostConfigModifier func(*container.HostConfig)
// WaitingFor is the strategy to wait for the container to be ready.
WaitingFor wait.Strategy
// OnDestroy is a callback function that is called before the container is terminated.
OnDestroy func(WorldContainer)
}
ContainerSpec defines the specification for creating a container.
type World ¶
type World struct {
// contains filtered or unexported fields
}
world represents the environment in which a test runs. Containers added to the world share the same network and logs are collected in a common log file. The world is destroyed at the end of the test.
func New ¶
New creates a new testworld. w.Destroy() should be deferred right after calling this function. If logPath is not empty, a world log will be created in the specified directory.
func (*World) NewContainer ¶
func (w *World) NewContainer(spec ContainerSpec) WorldContainer
NewContainer creates a new container and adds it to the World. Container creation happens in the background and WorldContainer methods wait for it to be ready. Call Await() to explicitly block until ready. Set spec.Replicas to create multiple identical containers as a group.
type WorldContainer ¶
type WorldContainer struct {
Name string
// contains filtered or unexported fields
}
func (*WorldContainer) Await ¶
func (wc *WorldContainer) Await()
Await blocks until all replica containers are created and started.
func (*WorldContainer) Exec ¶
func (wc *WorldContainer) Exec(cmd []string, expectCode int)
Exec executes a command in all replica containers and writes the output to the world log.
func (*WorldContainer) LogFile ¶
func (wc *WorldContainer) LogFile(path string)
LogFile copies a file from all replica containers to the world log.
func (*WorldContainer) Wait ¶
func (wc *WorldContainer) Wait(waitStrategy wait.Strategy)
Wait waits for all replica containers with a given wait strategy.