go-test¶
go test -race -coverprofile over the project's packages, with the
coverage badge driven by the standard go tool cover -func total line.
Runs on go-tools.
An optional go-test-e2e job runs a separate test path under an env-var
build flag (default INT_TEST_E2E=1) when enable_e2e: true. When false,
the e2e job is not scheduled at all — no skipped-job noise.
An optional go-test-integration job (when enable_integration: true)
adds a docker:dind service so testcontainers-go
suites can reach a Docker daemon via DOCKER_HOST. It requires a
privileged runner (the phpboyscout self-hosted runner already is) and
disables testcontainers' Ryuk reaper by default (the dind daemon is
ephemeral, so reaping is redundant). Off by default — no dind service or
job unless opted in. See
the dind spec.
Change-detected by default. Embed projects with a Svelte UI MUST extend
changes with their frontend path (e.g. pkg/studio/web/**) so a
frontend-only change still runs the Go embed/served-UI tests — see
Explanation: the Svelte frontend track.
The default changes also includes CHANGELOG.md, so a releaser-pleaser
Release MR (which for a bootstrap v0.1.0 changes only the changelog) runs
test before the tag is cut — see
the CHANGELOG-changes spec.
Coverage counts hand-written code by default. exclude_generated
(default true) strips files carrying Go's // Code generated … DO NOT
EDIT. marker — mockery/protoc/stringer output — out of the coverage
profile before the badge is computed, so generated packages (which have
~0% coverage) no longer dilute the figure and paths can stay ./...
without per-repo scoping. Only the counted profile is filtered; paths
(what gets tested) and the raw cover.out artifact are unchanged. Set
exclude_generated: false for the raw figure. See
the exclude-generated spec.
Jobs¶
| Job | What it runs |
|---|---|
go-test |
go test -race -coverprofile=cover.out $[[ inputs.paths ]]; uploads cover.out as an always-on artifact. |
go-test-e2e |
(only when enable_e2e: true) go test $[[ inputs.e2e_paths ]] -v -timeout $[[ inputs.e2e_timeout ]], with $[[ inputs.e2e_env_var ]]=1. |
go-test-integration |
(only when enable_integration: true) go test $[[ inputs.integration_paths ]] -v -timeout $[[ inputs.integration_timeout ]], with $[[ inputs.integration_env_var ]]=1, a docker:dind service, and DOCKER_HOST/FF_NETWORK_PER_BUILD/TESTCONTAINERS_RYUK_DISABLED wired. |
Inputs¶
| Input | Type | Default | Description |
|---|---|---|---|
image |
string | go-tools:v0.1.0 |
Go toolchain image. |
stage |
string | test |
GitLab CI stage. |
paths |
string | "./..." |
Path expression for go test. |
coverage_regex |
string | '/total:\s+\(statements\)\s+(\d+\.\d+)%/' |
Regex GitLab uses to extract the coverage badge %. |
exclude_generated |
boolean | true |
Strip generated files (first line // Code generated … DO NOT EDIT.) from the coverage profile before the badge — so generated code stops diluting it. Filters only what's counted; paths and the raw cover.out are untouched. false = raw figure. |
if |
string | '$CI_PIPELINE_SOURCE == "merge_request_event"' |
Gating rules:if: for the unit-test job. |
changes |
array | ["**/*.go", "**/go.mod", "**/go.sum", ".golangci.*", ".gitlab-ci.yml", "CHANGELOG.md", "**/CHANGELOG.md"] |
Change-detection paths. Includes CHANGELOG.md so Release MRs run. Must be extended for Svelte-embed projects. |
enable_e2e |
boolean | false |
Adds the go-test-e2e job. |
e2e_paths |
string | "./test/e2e/..." |
Path expression for the e2e run. |
e2e_timeout |
string | "5m" |
go test -timeout= value for e2e. |
e2e_env_var |
string | "INT_TEST_E2E" |
Env var set to 1 in the e2e job. |
enable_integration |
boolean | false |
Adds the dind-backed go-test-integration job (testcontainers-go). Requires a privileged runner. |
integration_paths |
string | "./test/integration/..." |
Path expression for the integration run. |
integration_timeout |
string | "10m" |
go test -timeout= value for integration (longer — image pulls + container startup). |
integration_env_var |
string | "INT_TEST_INTEGRATION" |
Env var set to 1 in the integration job. |
dind_image |
string | "docker:27-dind" |
Docker-in-Docker service image (Renovate-tracked). |
Usage¶
include:
- component: gitlab.com/phpboyscout/cicd/[email protected]
inputs:
enable_e2e: true
Testcontainers-go integration suite (needs a privileged runner):
include:
- component: gitlab.com/phpboyscout/cicd/[email protected]
inputs:
enable_integration: true
integration_paths: "./test/integration/..."
Your integration tests connect to the daemon via DOCKER_HOST (testcontainers-go
reads it automatically) and should skip unless INT_TEST_INTEGRATION=1, e.g.
if os.Getenv("INT_TEST_INTEGRATION") != "1" { t.Skip() }.
See also¶
go-lint,go-security- Explanation: the Svelte frontend track, change-detection