testlib

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 8 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.

It may import the standard library and external modules, and nothing from incus-compose. 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 LabelPrefix = "user.label.coredns."

LabelPrefix is the namespace an instance or a project configures us from.

Variables

This section is empty.

Functions

func Address

func Address(n, i int) string

Address is the address the ith instance holds on the nth network.

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 InstanceName

func InstanceName(i int) string

InstanceName is what the ith instance is called.

func Label

func Label(config map[string]string, key, value string)

Label writes one of our keys, prefix and all, onto a config map.

func NetworkName

func NetworkName(n int) string

NetworkName is what the nth network is called.

func NewInstance

func NewInstance(project string, i, on int) incusapi.Instance

NewInstance builds the ith running instance of a project, on network on. Its NIC is an expanded device, as a profile-supplied one is, so Devices is empty.

func NewInstanceState

func NewInstanceState(i, on int) *incusapi.InstanceState

NewInstanceState builds the state of the ith instance on network on: one global address on eth0, plus loopback.

func NewNetwork

func NewNetwork(project string, n int) incusapi.Network

NewNetwork builds the nth managed bridge of a project.

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 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 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 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

type Project

type Project struct {
	Project   incusapi.Project
	Networks  []incusapi.Network
	Instances []incusapi.Instance

	// States is what GetInstanceState answers, keyed by instance name.
	States map[string]*incusapi.InstanceState
}

Project is one project's worth of Incus values, as three reads would return them.

func NewProject

func NewProject(name string, instances, networks int) *Project

NewProject builds a project with the given number of instances and networks. Everything derives from the index: net<n> owns 10.<n>.0.0/24, and inst<i> sits on network i%networks holding 10.<n>.0.<10+i>.

Jump to

Keyboard shortcuts

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