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
- func Address(n, i int) string
- func Args(project string, args ...string) []string
- func InstanceName(i int) string
- func Label(config map[string]string, key, value string)
- func NetworkName(n int) string
- func NewInstance(project string, i, on int) incusapi.Instance
- func NewInstanceState(i, on int) *incusapi.InstanceState
- func NewNetwork(project string, n int) incusapi.Network
- func ProjectName(name string) string
- func SkipE2E(t *testing.T)
- func SkipExamples(t *testing.T)
- func SkipLocal(t *testing.T)
- func Strip(out string) string
- func StripHealth(out string) string
- func StripIPv6Lines(out string) string
- func WriteTempFiles(t *testing.T, files map[string]string) string
- type Project
Constants ¶
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.
const LabelPrefix = "user.label.coredns."
LabelPrefix is the namespace an instance or a project configures us from.
Variables ¶
This section is empty.
Functions ¶
func Args ¶
Args builds the incus-compose arguments for a project, ahead of whatever the caller runs them with.
func InstanceName ¶
InstanceName is what the ith instance is called.
func NewInstance ¶
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 ¶
NewNetwork builds the nth managed bridge of a project.
func ProjectName ¶
ProjectName makes an Incus project name out of anything, so a test can pass t.Name() and get one back.
func SkipE2E ¶
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 ¶
SkipExamples skips a test that brings up a project from examples/. Same polarity as SkipE2E.
func Strip ¶
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 ¶
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 ¶
StripIPv6Lines drops every line carrying an IPv6 address.
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 ¶
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>.