testutil

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package testutil provides shared helpers for packaging integration tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainerHTTPGet

func ContainerHTTPGet(t *testing.T, ctx context.Context, container testcontainers.Container, port, path string) int

ContainerHTTPGet sends an HTTP GET request to the given port and path on a running container. Returns the response status code.

func ContainerLogs

func ContainerLogs(t *testing.T, ctx context.Context, container testcontainers.Container) string

ContainerLogs returns the combined stdout/stderr of a running container.

func ExecInContainer

func ExecInContainer(t *testing.T, ctx context.Context, container testcontainers.Container, cmd ...string) (int, string)

ExecInContainer runs the given command inside the container and returns its exit code and combined stdout/stderr.

func ExecSucceeds

func ExecSucceeds(t *testing.T, ctx context.Context, container testcontainers.Container, cmd ...string) string

ExecSucceeds runs the given command inside the container, fails the test if it exits non-zero, and returns its combined stdout/stderr.

func FileContentInContainer

func FileContentInContainer(t *testing.T, ctx context.Context, container testcontainers.Container, path string) string

FileContentInContainer returns the full contents of a file inside the container, failing the test if the file cannot be read.

func FileExistsInContainer

func FileExistsInContainer(t *testing.T, ctx context.Context, container testcontainers.Container, path string) bool

FileExistsInContainer returns true if the given path exists inside the container.

func ImageOf

func ImageOf(t *testing.T, container testcontainers.Container) string

ImageOf returns the name of the image a container runs, e.g. to start further containers from an image that StartContainer built.

func RepoRoot

func RepoRoot(t *testing.T) string

RepoRoot returns the absolute path to the repository root by walking up from the caller's directory until it finds a go.mod file.

func RunPackageTest

func RunPackageTest(
	t *testing.T,
	ctx context.Context,
	dockerfilePath string,
	buildArgs map[string]*string,
) string

RunPackageTest builds a Docker image from the given Dockerfile (path relative to the repo root), runs it, and returns the container's combined output. The container is expected to exit on its own; a non-zero exit code fails the test.

func StartContainer

func StartContainer(
	t *testing.T,
	ctx context.Context,
	dockerfilePath string,
	buildArgs map[string]*string,
) testcontainers.Container

StartContainer builds a Docker image from the given Dockerfile and starts the container. Unlike StartServiceContainer, it does not wait for an HTTP endpoint; use this for containers that run `sleep infinity` and are probed via Exec.

func StartContainerFromImage

func StartContainerFromImage(t *testing.T, ctx context.Context, image string) testcontainers.Container

StartContainerFromImage starts a container from an existing local image with its default command. Suites whose scenarios run many containers from the same Dockerfile should build the image once via StartContainer and start the remaining containers from its image: concurrent scenario subtests would otherwise each trigger their own build of the same Dockerfile, multiplying build work and image storage.

func StartServiceContainerOpts

func StartServiceContainerOpts(t *testing.T, ctx context.Context, opts ServiceContainerOptions) testcontainers.Container

StartServiceContainerOpts builds and starts a service container per the given options, waiting for its HTTP endpoint to become ready. Returns the running container.

func TargetArch

func TargetArch() string

TargetArch returns the CPU architecture the test containers should be built and run for. It mirrors the Makefile's ARCH variable (read from the ARCH environment variable), defaulting to amd64 — the same default the package build uses. The container platform must match the architecture the packages under test were built for, otherwise apt/dnf cannot resolve them.

Types

type ServiceContainerOptions

type ServiceContainerOptions struct {
	// DockerfilePath is the path to the Dockerfile relative to the repo root.
	DockerfilePath string
	// BuildArgs are passed to the image build.
	BuildArgs map[string]*string
	// ExposedPorts are published to the host (e.g. "8080/tcp").
	ExposedPorts []string
	// WaitPort/WaitPath define the HTTP readiness probe.
	WaitPort string
	WaitPath string
	// Env sets environment variables inside the container.
	Env map[string]string
	// HostAccessPorts are host ports the container may reach at
	// host.testcontainers.internal — used to point a workload at an
	// otelsink.Sink listening on the host.
	HostAccessPorts []int
}

ServiceContainerOptions configures a long-running service container.

Directories

Path Synopsis
Package otelsink provides an in-process OTLP sink for integration tests.
Package otelsink provides an in-process OTLP sink for integration tests.

Jump to

Keyboard shortcuts

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