containers

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package containers provides shared helpers for starting testcontainers with uniform retry behavior. It exists so every container builder in the repo can opt into the same backoff policy instead of each rolling its own.

Container startup flakes for many non-deterministic reasons — Docker daemon cold starts, port conflicts, image pull stalls, transient network blips — and a single attempt is too brittle for a large integration test suite.

Index

Constants

This section is empty.

Variables

View Source
var RunningTests = strings.TrimSpace(strings.ToLower(os.Getenv("RUN_CONTAINER_TESTS"))) == "true"

RunningTests reports whether RUN_CONTAINER_TESTS=true is set in the environment. Container-backed tests across the repo should gate on this (typically via `if !containers.RunningTests { t.SkipNow() }`) so a default `go test ./...` does not require a Docker daemon. The variable is read once at package init.

Functions

func DefaultRetryConfig

func DefaultRetryConfig() retry.Config

DefaultRetryConfig returns the retry.Config used by StartWithRetry. Callers that need bespoke retry behavior can start from this and tweak individual fields before calling retry.NewExponentialBackoffPolicy themselves.

func SkipIfNotRunning

func SkipIfNotRunning(tb testing.TB)

SkipIfNotRunning skips the current test or benchmark (via SkipNow) when RunningTests is false. It is the one-line equivalent of `if !containers.RunningTests { tb.SkipNow() }` that every container-backed test and benchmark in the repo needs. It accepts testing.TB so both *testing.T and *testing.B can use it.

func StartWithRetry

func StartWithRetry[C any](ctx context.Context, start func(context.Context) (C, error)) (C, error)

StartWithRetry invokes start with exponential backoff retry on failure. It is a thin wrapper over the retry package so that every container builder in the repo gets the same backoff policy for free.

The callback receives the same ctx that was passed in, and is expected to return the concrete container type from its module's Run function (e.g. *postgres.PostgresContainer, *redis.RedisContainer). Callers handle the error themselves — typically via must.NoError(t, err) — so that this helper stays decoupled from the testing package.

Types

This section is empty.

Directories

Path Synopsis
Package redistest provides a single source of truth for the redis testcontainer setup that the redis-backed test suites in this repo all duplicate.
Package redistest provides a single source of truth for the redis testcontainer setup that the redis-backed test suites in this repo all duplicate.

Jump to

Keyboard shortcuts

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