framework

package
v0.0.0-...-f1406b7 Latest Latest
Warning

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

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

Documentation

Overview

Package framework provides helpers to run e2e test scenarios against containers.

Index

Constants

This section is empty.

Variables

View Source
var Alpine = Image{
	Ref:        "docker.io/library/alpine:3.22",
	Entrypoint: sleepEntrypoint,
	WaitCmd:    []string{"apk", "--version"},
}

Alpine is a plain Alpine container.

View Source
var ArchLinux = Image{
	Ref:        "docker.io/library/archlinux:base",
	Entrypoint: sleepEntrypoint,
	WaitCmd:    []string{"pacman", "--version"},
}

ArchLinux is a plain Arch container.

View Source
var Busybox = Image{
	Ref:        "docker.io/library/busybox:latest",
	Entrypoint: sleepEntrypoint,
	WaitCmd:    []string{"true"},
}

Busybox is a plain busybox container with busybox's adduser/groupadd applets.

View Source
var OpenWrt2410 = Image{
	Ref:        "docker.io/openwrt/rootfs:x86_64-24.10.8",
	Entrypoint: []string{"/sbin/init"},

	CapAdd:      []string{"SYS_ADMIN"},
	SecurityOpt: []string{"seccomp=unconfined", "apparmor=unconfined"},
	WaitCmd:     []string{"ubus", "call", "system", "board"},
}

OpenWrt2410 is an OpenWrt 24.10 machine with procd as PID 1 and opkg.

View Source
var OpenWrt2512 = Image{
	Ref:        "docker.io/openwrt/rootfs:x86_64-25.12.4",
	Entrypoint: []string{"/sbin/init"},

	CapAdd:      []string{"SYS_ADMIN"},
	SecurityOpt: []string{"seccomp=unconfined", "apparmor=unconfined"},
	WaitCmd:     []string{"ubus", "call", "system", "board"},
}

OpenWrt2512 is an OpenWrt 25.12 machine with procd as PID 1 and apk.

View Source
var OpenWrtImages = map[string]Image{
	"24.10": OpenWrt2410,
	"25.12": OpenWrt2512,
}

OpenWrtImages are the OpenWrt releases every openwrt* test runs on.

View Source
var SystemdDebian = Image{
	Ref: "quay.io/k0sproject/bootloose-debian12:v0.9.6",

	Entrypoint: []string{
		"/bin/sh", "-c",
		"[ -w /sys/fs/cgroup ] || mount -o remount,rw /sys/fs/cgroup && exec /sbin/init",
	},
	CapAdd: []string{"SYS_ADMIN"},

	SecurityOpt: []string{"apparmor=unconfined"},
	Tmpfs: map[string]string{
		"/run":      "",
		"/run/lock": "",
		"/tmp":      "",
	},
	WaitCmd: []string{"systemctl", "is-system-running", "--wait"},
}

SystemdDebian is a Debian 12 machine with systemd as PID 1.

Functions

This section is empty.

Types

type Env

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

Env is a running container machine with a deployed scenario binary.

func PrivateContainer

func PrivateContainer(t *testing.T, image Image, scenario Scenario) *Env

PrivateContainer deploys the scenario into a dedicated container that is terminated when the test exits.

func SharedContainer

func SharedContainer(t *testing.T, image Image, scenario Scenario) *Env

SharedContainer deploys the scenario into a container shared by all tests requesting the same image. Shared containers are reaped by ryuk after the test process exits.

Shared containers should be preferred for testing, since the startup still takes time, CPU and RAM and in general tests should be able to be written in a way to not impact each other. For cases where a test will impact other tests use PrivateContainer.

func (*Env) Exec

func (env *Env) Exec(t *testing.T, cmd ...string) (int, string)

Exec executes a command in the container machine.

func (*Env) RunScenario

func (env *Env) RunScenario(t *testing.T, args ...string) (int, string)

RunScenario executes the deployed scenario binary with args.

type Image

type Image struct {
	// Ref is the image to start the container with.
	Ref string
	// Entrypoint is the entrypoint to start the container with.
	Entrypoint []string
	// CapAdd lists added Linux capabilities.
	CapAdd []string
	// SecurityOpt lists container security options.
	SecurityOpt []string
	// Tmpfs maps mount points to mount options.
	Tmpfs map[string]string
	// Files maps container paths to file content copied in before start.
	// Wrap strings in [strings.NewReader].
	Files map[string]io.Reader
	// WaitCmd probes readiness inside the container.
	// Exit codes 0 and 1 count as ready so a degraded systemd boot, common in containers, does not fail the wait.
	WaitCmd []string
}

Image describes how to run a target OS as a container machine.

type Scenario

type Scenario struct {
	// Name is the scenario directory ./<Name>/ and the binary name.
	Name string
	// Compiler is the compiler binary.
	// Empty means "go".
	Compiler string
	// Args are the compiler arguments before the output and package arguments.
	// Empty means ["build"].
	Args []string
	// Env is extra build environment appended after the defaults.
	Env []string
	// Dir is the directory containing the main package to build as the
	// scenario binary.
	// Defaults to `./<Scenario.Name>`
	Dir string
}

Scenario builds and deploys a test binary into a container.

func (Scenario) Build

func (s Scenario) Build(t *testing.T) string

Build compiles ./<Name>/ as a static binary returns the binary path.

func (Scenario) Deploy

func (s Scenario) Deploy(t *testing.T, ctr testcontainers.Container) *Env

Deploy builds the scenario and copies it to /usr/local/bin/tensile-<Name>.

Jump to

Keyboard shortcuts

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