Documentation
¶
Index ¶
- Variables
- func ContainerAddr(ctx context.Context, container testcontainers.Container, port nat.Port) (string, error)
- func NewTestcontainersLogger() log.Logger
- func PortWait(port nat.Port) wait.Strategy
- func WithoutPublishedPorts() testcontainers.CustomizeRequestOption
- type ClickhouseClientFunc
- type PostgresDBCloneFunc
Constants ¶
This section is empty.
Variables ¶
var UsePublishedPorts = sync.OnceValue(func() bool { if runtime.GOOS != "linux" { return true } ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() cli, err := testcontainers.NewDockerClientWithOpts(ctx) if err != nil { return true } defer func() { _ = cli.Close() }() if !strings.HasPrefix(cli.DaemonHost(), "unix://") { return true } res, err := cli.Info(ctx, client.InfoOptions{}) if err != nil { return true } return res.Info.OperatingSystem == "Docker Desktop" || slices.Contains(res.Info.SecurityOptions, "name=rootless") })
UsePublishedPorts reports whether test containers must publish host ports for tests to reach them. Published ports are the source of two recurring CI flake classes: Docker's dynamic host-port allocator can pick a port already held by a host process (container start fails with "address already in use"), and dials through the publishing path (NAT rules, userland proxy) can be misrouted to unrelated host listeners under heavy parallel container churn. When the test process can route to container IPs directly — a local, rootful Docker daemon on Linux — ports are not published at all and tests dial <container IP>:<container port>. Docker Desktop and rootless daemons keep containers behind a VM or user namespace where container IPs are unreachable, so they retain published ports.
Functions ¶
func ContainerAddr ¶
func ContainerAddr(ctx context.Context, container testcontainers.Container, port nat.Port) (string, error)
ContainerAddr returns the address tests should dial to reach a container port: the container IP itself when ports are unpublished, otherwise the published endpoint on the Docker host.
func NewTestcontainersLogger ¶
func PortWait ¶
PortWait waits for a container port to accept connections, checking only from inside the container when the port is not published on the host.
func WithoutPublishedPorts ¶
func WithoutPublishedPorts() testcontainers.CustomizeRequestOption
WithoutPublishedPorts strips the exposed ports declared by a container module so Docker never allocates host ports for them. No-op when UsePublishedPorts reports true.
Types ¶
type ClickhouseClientFunc ¶
type ClickhouseClientFunc func(t *testing.T) (clickhouse.Conn, error)
func NewTestClickhouse ¶
func NewTestClickhouse(ctx context.Context) (*clickhousecontainer.ClickHouseContainer, ClickhouseClientFunc, error)
NewTestClickhouse creates a new ClickHouse container with the schema initialized from migration files. Returns a container reference and a function to create test connections. The per-test connection is automatically closed via t.Cleanup.
type PostgresDBCloneFunc ¶
func NewTestPostgres ¶
func NewTestPostgres(ctx context.Context) (*postgres.PostgresContainer, PostgresDBCloneFunc, error)