dockertestutil

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TimestampFormatRunID is used for generating unique run identifiers
	// Format: "20060102-150405" provides compact date-time for file/directory names.
	TimestampFormatRunID = "20060102-150405"
)

Variables

View Source
var (
	ErrDockertestCommandFailed  = errors.New("dockertest command failed")
	ErrDockertestCommandTimeout = errors.New("dockertest command timed out")
)
View Source
var ErrContainerNotFound = errors.New("container not found")

Functions

func AddContainerToNetwork

func AddContainerToNetwork(
	pool *dockertest.Pool,
	network *dockertest.Network,
	testContainer string,
) error

func CleanImagesInCI added in v0.26.0

func CleanImagesInCI(pool *dockertest.Pool) error

CleanImagesInCI removes images if running in CI. It only removes dangling (untagged) images to avoid forcing rebuilds. Tagged images (golang:*, tailscale/tailscale:*, etc.) are automatically preserved.

func CleanUnreferencedNetworks added in v0.26.0

func CleanUnreferencedNetworks(pool *dockertest.Pool) error

CleanUnreferencedNetworks removes networks that are not referenced by any containers.

func DockerAddIntegrationLabels added in v0.27.0

func DockerAddIntegrationLabels(opts *dockertest.RunOptions, testType string)

DockerAddIntegrationLabels adds integration test labels to Docker RunOptions. This allows the hi tool to identify containers belonging to specific test runs. This function should be called before passing RunOptions to dockertest functions.

func DockerAllowLocalIPv6

func DockerAllowLocalIPv6(config *docker.HostConfig)

DockerAllowLocalIPv6 allows IPv6 traffic within the container.

func DockerAllowNetworkAdministration

func DockerAllowNetworkAdministration(config *docker.HostConfig)

DockerAllowNetworkAdministration gives the container network administration capabilities.

func DockerMemoryLimit added in v0.27.0

func DockerMemoryLimit(config *docker.HostConfig)

DockerMemoryLimit sets memory limit and disables OOM kill for containers.

func DockerRestartPolicy

func DockerRestartPolicy(config *docker.HostConfig)

DockerRestartPolicy sets the restart policy for containers.

func ExecuteCommand

func ExecuteCommand(
	resource *dockertest.Resource,
	cmd []string,
	env []string,
	options ...ExecuteCommandOption,
) (string, string, error)

func ExtractRunIDFromContainerName added in v0.27.0

func ExtractRunIDFromContainerName(containerName string) string

ExtractRunIDFromContainerName extracts the run ID from container name. Expects format: "prefix-YYYYMMDD-HHMMSS-HASH".

func GenerateRunID added in v0.27.0

func GenerateRunID() string

GenerateRunID creates a unique run identifier with timestamp and random hash. Format: YYYYMMDD-HHMMSS-HASH (e.g., 20250619-143052-a1b2c3).

func GetFirstOrCreateNetwork

func GetFirstOrCreateNetwork(pool *dockertest.Pool, name string) (*dockertest.Network, error)

func GetIntegrationRunID added in v0.27.0

func GetIntegrationRunID() string

GetIntegrationRunID returns the run ID for the current integration test session. This is set by the hi tool and passed through environment variables.

func IsRunningInContainer

func IsRunningInContainer() bool

IsRunningInContainer checks if the current process is running inside a Docker container. This is used by tests to determine if they should run integration tests.

func RandomFreeHostPort added in v0.18.0

func RandomFreeHostPort() (int, error)

RandomFreeHostPort asks the kernel for a free open port that is ready to use. (from https://github.com/phayes/freeport)

func RunDockerBuildForDiagnostics added in v0.27.0

func RunDockerBuildForDiagnostics(contextDir, dockerfile string) (string, error)

RunDockerBuildForDiagnostics runs docker build manually to get detailed error output. This is used when a docker build fails to provide more detailed diagnostic information than what dockertest typically provides.

Returns the build output regardless of success/failure, and an error if the build failed.

func SaveLog added in v0.20.0

func SaveLog(
	pool *dockertest.Pool,
	resource *dockertest.Resource,
	basePath string,
) (string, string, error)

func WriteLog added in v0.24.0

func WriteLog(
	pool *dockertest.Pool,
	resource *dockertest.Resource,
	stdout io.Writer,
	stderr io.Writer,
) error

Types

type ExecuteCommandConfig

type ExecuteCommandConfig struct {
	// contains filtered or unexported fields
}

type ExecuteCommandOption

type ExecuteCommandOption func(*ExecuteCommandConfig) error

func ExecuteCommandTimeout

func ExecuteCommandTimeout(timeout time.Duration) ExecuteCommandOption

Jump to

Keyboard shortcuts

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