Documentation
¶
Index ¶
- Constants
- Variables
- func AddContainerToNetwork(pool *dockertest.Pool, network *dockertest.Network, testContainer string) error
- func AuthConfiguration() docker.AuthConfiguration
- func CleanImagesInCI(pool *dockertest.Pool) error
- func CleanUnreferencedNetworks(pool *dockertest.Pool) error
- func DisconnectAndReconnect(pool *dockertest.Pool, network *dockertest.Network, testContainer string) error
- func DisconnectContainerFromNetwork(pool *dockertest.Pool, network *dockertest.Network, testContainer string) error
- func DockerAddIntegrationLabels(opts *dockertest.RunOptions, testType string)
- func DockerAllowLocalIPv6(config *docker.HostConfig)
- func DockerAllowNetworkAdministration(config *docker.HostConfig)
- func DockerMemoryLimit(config *docker.HostConfig)
- func DockerRestartPolicy(config *docker.HostConfig)
- func ExecuteCommand(resource *dockertest.Resource, cmd []string, env []string, ...) (string, string, error)
- func ExtractRunIDFromContainerName(containerName string) string
- func GenerateRunID() string
- func GetFirstOrCreateNetwork(pool *dockertest.Pool, name string) (*dockertest.Network, error)
- func GetFirstOrCreateNetworkWithSubnet(pool *dockertest.Pool, name, subnet string) (*dockertest.Network, error)
- func GetIntegrationRunID() string
- func IsRunningInContainer() bool
- func PullWithAuth(pool *dockertest.Pool, imageRef string) error
- func RandomFreeHostPort() (int, error)
- func ReconnectContainerToNetwork(pool *dockertest.Pool, network *dockertest.Network, testContainer string) error
- func RegistryAuth() (string, error)
- func RunDockerBuildForDiagnostics(contextDir, dockerfile string) (string, error)
- func SaveLog(pool *dockertest.Pool, resource *dockertest.Resource, basePath string) (string, string, error)
- func WriteLog(pool *dockertest.Pool, resource *dockertest.Resource, stdout io.Writer, ...) error
- type CredentialSource
- type ExecuteCommandConfig
- type ExecuteCommandOption
Constants ¶
const ( DockerOpInitialInterval = 1 * time.Second DockerOpMaxInterval = 10 * time.Second DockerOpMaxElapsedTime = 90 * time.Second )
Docker control-plane retry policy. MaxElapsedTime sits above the worst observed libnetwork bridge reprogramming time (~60 s on contended GHA runners).
const ( // TimestampFormatRunID is used for generating unique run identifiers // Format: "20060102-150405" provides compact date-time for file/directory names. TimestampFormatRunID = "20060102-150405" )
Variables ¶
var ( ErrDockertestCommandFailed = errors.New("dockertest command failed") ErrDockertestCommandTimeout = errors.New("dockertest command timed out") )
var ( ErrContainerNotFound = errors.New("container not found") ErrConditionTimeout = errors.New("condition not met within timeout") )
Functions ¶
func AddContainerToNetwork ¶
func AddContainerToNetwork( pool *dockertest.Pool, network *dockertest.Network, testContainer string, ) error
func AuthConfiguration ¶ added in v0.29.0
func AuthConfiguration() docker.AuthConfiguration
AuthConfiguration returns Docker Hub auth for the dockertest pool.
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 DisconnectAndReconnect ¶ added in v0.29.0
func DisconnectAndReconnect( pool *dockertest.Pool, network *dockertest.Network, testContainer string, ) error
DisconnectAndReconnect calls Disconnect followed by Reconnect; both primitives drive their own libnetwork settle waits.
func DisconnectContainerFromNetwork ¶ added in v0.29.0
func DisconnectContainerFromNetwork( pool *dockertest.Pool, network *dockertest.Network, testContainer string, ) error
DisconnectContainerFromNetwork detaches the container at the docker daemon level (cable-pull semantics) and waits for libnetwork to drop the endpoint before returning — re-attaching during the reprogramming window otherwise fails with "network is unreachable".
func DockerAddIntegrationLabels ¶ added in v0.27.0
func DockerAddIntegrationLabels(opts *dockertest.RunOptions, testType string)
DockerAddIntegrationLabels adds integration test labels to Docker dockertest.RunOptions. This allows the hi tool to identify containers belonging to specific test runs. This function should be called before passing dockertest.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
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 GetFirstOrCreateNetworkWithSubnet ¶ added in v0.29.0
func GetFirstOrCreateNetworkWithSubnet(pool *dockertest.Pool, name, subnet string) (*dockertest.Network, error)
GetFirstOrCreateNetworkWithSubnet creates a Docker network with an optional custom subnet. When subnet is empty, Docker auto-assigns from its default pool. Use RFC 5737 TEST-NET ranges (e.g. "198.51.100.0/24") for networks that need to be reachable through Tailscale exit nodes, since Tailscale's shrinkDefaultRoute strips RFC1918 ranges from exit node forwarding filters.
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 PullWithAuth ¶ added in v0.29.0
func PullWithAuth(pool *dockertest.Pool, imageRef string) error
PullWithAuth ensures imageRef is local, pulling with auth and retrying transient errors when it is not.
func RandomFreeHostPort ¶ added in v0.18.0
RandomFreeHostPort asks the kernel for a free open port that is ready to use. (from https://github.com/phayes/freeport)
func ReconnectContainerToNetwork ¶ added in v0.29.0
func ReconnectContainerToNetwork( pool *dockertest.Pool, network *dockertest.Network, testContainer string, ) error
ReconnectContainerToNetwork is the inverse of DisconnectContainerFromNetwork — re-attaches the container to the network so traffic can flow again.
func RegistryAuth ¶ added in v0.29.0
RegistryAuth returns base64-encoded credentials for the modern Docker SDK's image.PullOptions{RegistryAuth: ...}, or "" when none.
func RunDockerBuildForDiagnostics ¶ added in v0.27.0
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)
Types ¶
type CredentialSource ¶ added in v0.29.0
type CredentialSource string
const ( CredentialSourceEnv CredentialSource = "env" CredentialSourceConfig CredentialSource = "config" CredentialSourceAnonymous CredentialSource = "anonymous" )
func Credentials ¶ added in v0.29.0
func Credentials() (string, string, CredentialSource)
Credentials resolves Docker Hub credentials from DOCKERHUB_USERNAME/DOCKERHUB_TOKEN, then ~/.docker/config.json, then anonymous. The Docker Go SDKs do not read config.json on their own.
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