testlib

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package testlib holds what every package's tests need: the tier guards, the naming and argument conventions, and snapshot normalization.

Under internal/ because it has no stability promise: every signature here changes whenever a test needs it to, with no changelog entry. The compiler is what keeps that off a library user, not this paragraph.

It may import the standard library, external modules, and shared. client, iclient and project test in-package, so a helper here that reached for one of them would be an import cycle for exactly the tests that need it most. A helper that does need our own types belongs in the package it serves.

Index

Constants

View Source
const (
	EnvLocal    = "INCUS_COMPOSE_TEST_LOCAL"
	EnvE2E      = "INCUS_COMPOSE_TEST_E2E"
	EnvExamples = "INCUS_COMPOSE_TEST_EXAMPLES"
)

The environment a stage runs in. `just test-local` and `just test-e2e` set one each; `just test` sets neither, which is what makes it the middle stage.

View Source
const EnvCoverDir = "INCUS_COMPOSE_TEST_COVERDIR"

EnvCoverDir is where the CLI writes its counters; setting it builds with -cover.

Variables

This section is empty.

Functions

func Args

func Args(project string, args ...string) []string

Args builds the incus-compose arguments for a project, ahead of whatever the caller runs them with.

func CleanupCompose

func CleanupCompose(t *testing.T, project string, args ...string)

CleanupCompose runs incus-compose on teardown and fails the test when it errors.

func ComposeBin

func ComposeBin(t *testing.T) string

ComposeBin builds the CLI once per test process, with the run's own -race and -cover settings. Main removes what it built.

func DebugCommands

func DebugCommands() bool

func Exec

func Exec(ctx context.Context, t *testing.T, cwd string, env []string, name string, args ...string) (string, error)

Exec executes a command with extra environment and returns what it wrote to stdout. What it wrote to stderr comes back on the error.

func Fixture

func Fixture(t *testing.T, parts ...string) string

Fixture is the absolute path of parts under FixtureRoot.

func FixtureRoot

func FixtureRoot(t *testing.T) string

FixtureRoot is the compose stacks this suite boots, at the top of the checkout: they are the fleet, not this package's testdata.

func InitSlog

func InitSlog()

func KeepTestData

func KeepTestData() bool

func Main

func Main(m *testing.M) int

Main is a test package's TestMain: logger, run, teardown.

func ProjectName

func ProjectName(name string) string

ProjectName makes an Incus project name out of anything, so a test can pass t.Name() and get one back.

func RepoRoot

func RepoRoot(t *testing.T) string

RepoRoot is the absolute path of this checkout, so nothing depends on the working directory.

func RunCompose

func RunCompose(ctx context.Context, t *testing.T, project, dir string, env []string, args ...string) (string, error)

RunCompose runs incus-compose as a subprocess. An empty dir leaves --project-directory off, and a non-empty env implies --os-env.

func SkipE2E

func SkipE2E(t *testing.T)

SkipE2E skips a slow test that stands up a fixture stack. Opposite polarity to SkipLocal: an end-to-end test runs only when asked for.

func SkipExamples

func SkipExamples(t *testing.T)

SkipExamples skips a test that brings up a project from examples/. Same polarity as SkipE2E.

func SkipLocal

func SkipLocal(t *testing.T)

SkipLocal skips a test that needs a real Incus server.

func SkipNoExtension

func SkipNoExtension(t *testing.T, extension, message string)

func Strip

func Strip(out string) string

Strip replaces what changes between runs - addresses and the healthd image tag - so output can be snapshotted. The trailing newline goes too, since cupaloy adds one back.

func StripHealth

func StripHealth(out string) string

StripHealth is Strip, and also the reported health status. Use it where the status is still settling and the test is not about it.

func StripIPv6Lines

func StripIPv6Lines(out string) string

StripIPv6Lines drops every line carrying an IPv6 address.

func TraceCommands

func TraceCommands() bool

func WriteTempFiles

func WriteTempFiles(t *testing.T, files map[string]string) string

WriteTempFiles writes files, keyed by a path relative to a fresh temp directory, and returns that directory. Parents are created as needed, so a key may nest.

Types

This section is empty.

Jump to

Keyboard shortcuts

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