Skip to main content

Testing

Every CI sensor is a make target, so the feedback CI gives after a push is available before the commit. make help lists them all.

The pyramid as it is​

LayerWhatWhereRun with
Unitdomain aggregate and rules, use cases over in-memory doubles, adapters over httptest, the composition rootsinternal/domain/**, internal/application/usecases, internal/adapters/**, cmd/* (*_test.go without a build tag)make test (go test ./... -race)
Coverage gatestatement coverage of domain and applicationCOVERAGE_PKGS = ./internal/domain/...,./internal/application/...make coverage, gate 90 %
Godog featuresGherkin acceptance over the real chi router and use cases wired to the in-memory doublesfeatures/*.feature (11 files, 96 Scenario and Scenario Outline blocks; the runner executes 123 scenarios once the Examples rows are expanded) with the runner and steps in internal/bddmake bdd (go test ./... -run TestFeatures -v)
Contractthe repository contract suite run by both persistence adapters; the golden CloudEvents; the event catalogue against apis/asyncapi.yaml; the specs linted by Spectralinternal/adapters/outbound/repocontract, internal/adapters/outbound/kafka/testdata/*.golden.json, internal/architecture/catalogue_fitness_test.go, .spectral.yaml, .spectral.asyncapi.yamlpart of make test, make integration, make arch-test; Spectral in the api-lint CI job
Integrationreal Postgres and Kafka via testcontainers; each test boots its own containerfiles with //go:build integration: cmd/api/e2e_*_integration_test.go (4), internal/adapters/outbound/postgres/*_integration_test.go (4), internal/adapters/outbound/outbox/main_integration_test.gomake integration (go test -tags=integration ./... -race -count=1), needs only Docker
Mutationgremlins over the domain packages.gremlins.yaml: efficacy threshold 98, mutant coverage threshold 94 (plain numbers; the residuals are in MUTATION.md), 1 worker, timeout coefficient 30make mutation (every internal/domain/<pkg> in turn), make mutation-full (./internal/domain)
Architecture fitnessexecutable rules on the package graph and on source conventionsinternal/architecture (see below)make arch-test

There are about 80 _test.go files; none needs a database or a broker unless it carries the integration tag. The in-memory adapters (internal/adapters/outbound/memory) are test doubles only: the fitness test TestRuntimeBinaryHasNoInMemoryAdapters fails the build if any cmd/** binary imports them.

Godog features​

FileScenariosCovers
open_session.feature8a ready cart opens with the binding total; an unready cart is refused before anyone else is called; an offer that expires within the margin or is no longer quoted changes nothing; an unknown cart and a missing reference are validation errors; a sibling that is down is a 503 and nothing is stored; groups that do not cover the lines are a contract bug
confirm_session.feature7authorize then place completes; a decline keeps the session open; an expired quote is refused; a closed session never changes; an authorized amount that is not the quote total is voided; a missing token is a validation error; an unknown session is not found
placement.feature6a timeout leaves the session PLACING and answers 202; no new attempt while unknown; the poll until the resolver settles it; a definitive 409 voids and asks for a requote; a 422 voids, fails and alerts; a failed void stays owed and is retried
policies.feature7expiry of OPEN and DECLINED sessions with the quote; an expired session cannot be confirmed; a stuck authorization is re-called with the same key; the 20 h alert; the 22 h give-up and void; the 24 h purge of the stored request
api_idempotency.feature8a write without a key is refused; a key that is not 1 to 128 printable ASCII characters is refused; a replayed open and a replayed confirm return the stored answer; the same key with another request or on another route is refused; a malformed body is a problem document; an unknown session is not found
platform.feature2liveness and readiness answer; the drain gate flips readiness off
session_open_rules.feature12the OpenSession rules of the Checkout documentation (includes 6 Examples tables)
session_confirm_rules.feature19the ConfirmSession rules of the Checkout documentation (includes 5 Examples tables)
session_policy_rules.feature16the policy rules of the Checkout documentation (includes 2 Examples tables)
session_api_rules.feature7the REST write rules: the Idempotency-Key format, the 24 hour replay window, a FINAL refusal is stored and a RETRYABLE one releases its key (ADR 0011), a NUL character in a body, the 64 KiB body limit (includes 2 Examples tables)

The Scenarios column counts definitions; with the Examples rows expanded the runner reports 123 scenarios (123 passed) (go test ./internal/bdd -run TestFeatures -count=1 -v). The four session_*_rules.feature files pin the rules documented in the pack and in the ADRs; the other six are the original acceptance set.

The scenarios run through HTTP (httptest.Server over NewRouter) so status codes and problem slugs are asserted as a client sees them.

Fitness tests (internal/architecture)​

make arch-test runs go test ./internal/architecture/... -v:

  • TestHexagonalArchitecture (arch-go): the domain imports no outer layer, an adapter does not reach sideways into a sibling.
  • TestRuntimeBinaryHasNoInMemoryAdapters, TestNoGoFilesAtRepoRoot.
  • TestMCPAdapterDependencyRule, TestMCPOptionalToolInputsCarryOmitempty, TestA2AAdapterDependencyRule, TestA2AAdapterIsReadOnlyAndHasNoOutboundClient.
  • TestNoAuthMiddlewareReintroduced.
  • TestCloudEventsOnly, TestNoEventEnvelopeToggleOrFlatEnvelope, TestEventCatalogueMatchesContract (the published types against apis/asyncapi.yaml).
  • TestKafkaWritersSetRequiredAcks, TestKafkaWriterTopicNotSetTwice, TestDeadLetterCallsGuardCancellation, TestReplayConsumersSetCommitInterval, TestKafkaConsumerGroupNeverHardcodedInline.
  • TestOutboxRelaysPassAttemptCap.
  • TestPostgresIntegrationTestsUseTestcontainers, TestKafkaIntegrationTestsUseTestcontainers.

Each rule has a "sensor bites" companion test that feeds it a bad fixture, so a rule cannot pass vacuously.

Make targets​

make help # list the targets
make build # go build ./...
make vet # go vet ./...
make fmt # gofmt -w .
make fmt-check # fail if gofmt -l . is non-empty
make lint # golangci-lint run (v2.14.0)
make test # go test ./... -race
make coverage # tests + the 90% gate over domain and application
make bdd # godog scenarios
make arch-test # fitness tests
make integration # testcontainers Postgres and Kafka; needs Docker
make mutation # gremlins, fast blocking gate, every domain package
make mutation-full # gremlins over ./internal/domain (exhaustive, slow)
make vuln # govulncheck ./...
make check-fast # fmt-check vet arch-test + tests of changed packages
make check # fmt-check vet build lint test
make check-all # check + coverage arch-test bdd
make guide-lint # agent guides: skills load, references resolve
make harness-test # unit-test the agent hooks

integration and mutation are deliberately not part of check or check-all. Git hooks (lefthook): pre-commit runs fmt-check, vet and lint; pre-push runs make check. Activate once per clone with lefthook install.

CI jobs​

.github/workflows/ci.yml runs on every push to main and develop, every pull request into them, a weekly schedule (Monday 06:00 UTC, mutation only) and manual dispatch:

JobWhat it runs
lintgolangci-lint v2.14.0
guide-lintagent-guide lint and hook tests (advisory, continue-on-error)
complexitygocyclo, gocognit, cyclop, funlen, nestif via golangci-lint, plus an informational gocyclo report
testgo build, go vet, then make coverage (the 90 % gate)
bddgo test ./... -run TestFeatures -v
integrationgo test -tags=integration ./... -race -count=1
mutation-fastgremlins over every internal/domain/*/ package, blocking
mutationgremlins over ./internal/domain, only on schedule or dispatch; opens or refreshes a harness:red issue on a scheduled failure and closes it on recovery
api-lintSpectral over apis/openapi.yaml and apis/asyncapi.yaml, --fail-severity=warn
vulngovulncheck ./...
helm-lintct lint and helm lint with both charts/checkout/ci values files
chart-testsevery charts/checkout/tests/*.sh and test_*.py; a test that prints SKIP fails the job
arch-testgo test ./internal/architecture/... -v
docker-publishmain only, after the jobs above: build, push to GHCR, cosign sign, SBOM attest
releasemain only, after docker-publish: version tag, image re-tag, chart push, GitHub release

This documentation site has its own workflow, .github/workflows/docs.yml: it builds the site on every pull request and deploys it to GitHub Pages on a push to main.

Writing a test​

  • A new REST error: add the sentinel to the problem catalogue (internal/adapters/inbound/http/errors.go), a case in errors_test.go and the slug to apis/openapi.yaml.
  • A new domain rule: a table test in internal/domain/checkoutsession first; the mutation gate fails if the assertion is weak.
  • A new published event: the encoder, a golden file in internal/adapters/outbound/kafka/testdata, the message in apis/asyncapi.yaml; TestEventCatalogueMatchesContract fails until both agree.
  • Integration tests never read DATABASE_URL and never skip on a missing broker: they start testcontainers themselves.