testctr

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package testctr provides utilities for setting up testcontainers in tests.

Usage:

1. Add a TestMain function to your test package:

func TestMain(m *testing.M) {
	code := testctr.EnsureTestEnv()
	if code == 0 {
		code = m.Run()
	}
	os.Exit(code)
}

2. In your test functions, check for Docker availability:

func TestWithContainers(t *testing.T) {
	testctr.SkipIfDockerNotAvailable(t)
	// Your test code here
}

This approach ensures proper environment setup for testcontainers while maintaining compatibility with parallel tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureTestEnv

func EnsureTestEnv() int

EnsureTestEnv sets up the necessary environment variables for testcontainers at the process level. This should be called from TestMain before running tests. It returns an exit code that should be passed to os.Exit.

This works around a testcontainers bug where it doesn't properly detect the Docker socket when using Colima or other non-standard Docker setups.

Example usage:

func TestMain(m *testing.M) {
	code := testctr.EnsureTestEnv()
	if code == 0 {
		code = m.Run()
	}
	os.Exit(code)
}

func SkipIfDockerNotAvailable

func SkipIfDockerNotAvailable(t *testing.T)

SkipIfDockerNotAvailable checks if Docker is available and skips the test if not. This is safe to call from tests that use t.Parallel() as it doesn't use t.Setenv. You must ensure the environment variables are set before running the test (e.g., via EnsureTestEnv in TestMain).

Types

This section is empty.

Jump to

Keyboard shortcuts

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