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
- func Args(project string, args ...string) []string
- func CleanupCompose(t *testing.T, project string, args ...string)
- func ComposeBin(t *testing.T) string
- func DebugCommands() bool
- func Exec(ctx context.Context, t *testing.T, cwd string, env []string, name string, ...) (string, error)
- func Fixture(t *testing.T, parts ...string) string
- func FixtureRoot(t *testing.T) string
- func InitSlog()
- func KeepTestData() bool
- func Main(m *testing.M) int
- func ProjectName(name string) string
- func RepoRoot(t *testing.T) string
- func RunCompose(ctx context.Context, t *testing.T, project, dir string, env []string, ...) (string, error)
- func SkipE2E(t *testing.T)
- func SkipExamples(t *testing.T)
- func SkipLocal(t *testing.T)
- func SkipNoExtension(t *testing.T, extension, message string)
- func Strip(out string) string
- func StripHealth(out string) string
- func StripIPv6Lines(out string) string
- func TraceCommands() bool
- func WriteTempFiles(t *testing.T, files map[string]string) string
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 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 ¶
Args builds the incus-compose arguments for a project, ahead of whatever the caller runs them with.
func CleanupCompose ¶
CleanupCompose runs incus-compose on teardown and fails the test when it errors.
func ComposeBin ¶
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 FixtureRoot ¶
FixtureRoot is the compose stacks this suite boots, at the top of the checkout: they are the fleet, not this package's testdata.
func KeepTestData ¶
func KeepTestData() bool
func ProjectName ¶
ProjectName makes an Incus project name out of anything, so a test can pass t.Name() and get one back.
func RepoRoot ¶
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 ¶
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 SkipNoExtension ¶
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.
func TraceCommands ¶
func TraceCommands() bool
Types ¶
This section is empty.