testinfra

package
v0.0.0-...-50dbd19 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 NewTestcontainersLogger() log.Logger

func PortWait

func PortWait(port nat.Port) wait.Strategy

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

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

type PostgresDBCloneFunc func(t *testing.T, name string) (*pgxpool.Pool, error)

Jump to

Keyboard shortcuts

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