Skip to main content

Testing

The pyramid as it stands on develop. Everything except make integration runs without Docker, Postgres or Kafka.

LayerWhereHow manyRuns with
Unit (domain, application, adapters)internal/domain/**, internal/application/**, internal/adapters/**, internal/bootretry, cmd/*/main_test.goabout 89 _test.go files, 12 of them *_integration_test.gomake test
HTTP handler tests (no database)internal/adapters/inbound/http/*_test.goreadiness, NUL rejection, idempotency capture, scorecard, telemetry, handlersmake test
BDD acceptance (godog)features/*.feature13 feature files, 168 scenario definitions, 222 executedmake bdd (also part of make test)
Integration (testcontainers)files tagged integration: cmd/api/e2e_integration_test.go, cmd/mcp, cmd/a2a, internal/adapters/outbound/{postgres,outbox,kafka}, internal/adapters/inbound/kafka12 *_integration_test.go filesmake integration
Contractevent catalogue vs apis/asyncapi.yaml, MCP tool registry golden file, CloudEvents encoder/decoder, Spectral lint of both specssee belowmake arch-test, make test, CI api-lint
Mutationinternal/domain/** with gremlinsthresholds in .gremlins.yamlmake mutation, make mutation-full
Architecture fitnessinternal/architecture/12 test files, 31 Test* functionsmake arch-test

Unit and use-case tests​

The domain packages (inboundplan, inboundshipment, seller, scorecard, network, shared, shared/gs1) have table tests for every invariant; internal/application/usecases has flow_test.go (a shipment from onboarding to receipt on in-memory test doubles), consumers_test.go, scorecard_test.go and shipment_metrics_test.go. The in-memory store under internal/adapters/outbound/memory exists for tests only: a fitness test (TestRuntimeBinaryHasNoInMemoryAdapters) fails if any cmd/** binary imports it.

make coverage runs the whole suite with the race detector and enforces a 90 % gate over ./internal/domain/... and ./internal/application/... (COVERAGE_PKGS and COVERAGE_THRESHOLD in the Makefile; CI runs the same target, so the scope cannot drift).

godog features​

Definitions are Scenario and Scenario Outline lines (git grep -c -E "^[[:space:]]*Scenario" -- features, an Outline counts once); executed adds one run per Examples row and is the N scenarios line of make bdd. No scenario is tagged @known-bug any more (see below).

FileDefinitionsExecuted
features/sellers.feature99
features/inbound_plans.feature99
features/shipments_and_labels.feature1313
features/receipts.feature66
features/scorecard.feature88
features/node_limits.feature22
features/seller_account_rules.feature1421
features/plan_rules.feature1630
features/carton_rules.feature2947
features/shipment_lifecycle_rules.feature1516
features/receipt_rules.feature2832
features/read_model_rules.feature88
features/scorecard_rules.feature1121
Total168222

The first six files are the original suite, written from the OpenAPI contract. The *_rules files pin the documented rules, invariants, caps, state edges and failure modes (seller account, plan lines and GTINs, carton and SSCC rules, shipment lifecycle, receipt discrepancies and the ADR 0014 received lines, the node-topology and packaging read models, and the scorecard thresholds at their edges).

Tags: BDD_TAGS selects scenarios (default ~@known-bug). @known-bug marks a scenario that states a documented rule the code does not meet yet; BDD_TAGS=@known-bug go test ./features -run TestFeatures runs it and it fails until the defect is fixed. @slow marks the 1000-carton scenario so mutation runs can skip it. The runner is Strict, so an undefined step fails the run. The step table also has two placeholders, {shipment:N} and {repeat:c:N}.

The steps (features/steps_test.go, features/features_test.go) drive the real use cases and the real REST router over in-memory adapters, and feed the consumers with CloudEvents built from the producers' contracts (node-topology, offer-availability, vendor-connectivity). Run them alone with make bdd (go test ./... -run TestFeatures -v).

Integration tests​

make integration runs go test -tags=integration ./... -race -count=1. It needs only Docker: every test boots its own Postgres and Kafka with testcontainers, so there is no DATABASE_URL, no docker compose and no skip gate. Two fitness tests enforce this (TestPostgresIntegrationTestsUseTestcontainers, TestKafkaIntegrationTestsUseTestcontainers).

  • cmd/api/e2e_integration_test.go starts the real run entry point against the containers and walks the REST API, the four consumers and the relay end to end (the sourcing consumer: a merged release lands demand_heat_lines rows, a replayed event id is a no-op, a cancel removes the rows).
  • cmd/mcp and cmd/a2a have their own main_integration_test.go.
  • internal/adapters/outbound/postgres covers the repositories, the scorecard tables, and that an outbox row written under a span stores its traceparent.
  • internal/adapters/outbound/outbox covers the relay and the attempt cap; outbound/kafka the sink and writers; inbound/kafka the consumers and dead-lettering.

Contract tests​

  • TestEventCatalogueMatchesContract (internal/architecture/catalogue_fitness_test.go, a fleet-managed file) checks that every com.warehouse.(wms|wes).<service>... or com.retailnetwork.<domain>.<service>... type that apis/asyncapi.yaml declares for this module appears in the ADR catalogue. seller-inbound's types are com.retailnetwork.partner.seller-inbound...; its ten published types are checked against ADR 0004, and the types it only consumes (other services' segments) are not required there. TestEventCatalogueDetector pins both type shapes. A new event still changes the domain struct, apis/asyncapi.yaml and the ADR 0004 type: line in one commit (CLAUDE.md); the test now fails the build if the ADR line is missing.
  • TestToolRegistryGolden and TestToolSurface (internal/adapters/inbound/mcp/governance_test.go) pin the MCP tools to internal/adapters/inbound/mcp/testdata/tool_registry.golden.json; refresh it with go test ./internal/adapters/inbound/mcp -update and review the diff. The same file checks that no tool name is a write verb.
  • internal/adapters/kafka/cloudevents/cloudevents_test.go and internal/adapters/outbound/kafka/encoder_test.go pin the CloudEvents envelope.
  • CI api-lint runs Spectral on apis/openapi.yaml (.spectral.yaml) and apis/asyncapi.yaml (.spectral.asyncapi.yaml) with --fail-severity=warn.

Mutation testing​

.gremlins.yaml sets one worker, timeout coefficient 30, and thresholds efficacy 99 and mutant-coverage 99. The file records the last measurement: every domain package except inboundshipment at 100 %; inboundshipment at 99.23 % with one equivalent surviving mutant (receipt.go:195, the receipt normalisation already drops zero-quantity items). make mutation runs gremlins on internal/domain/inboundshipment (the fast subset); make mutation-full on all of internal/domain. gremlins is pinned to v0.6.0.

Architecture fitness tests​

make arch-test runs go test ./internal/architecture/... -v. Each rule has a "sensor bites" companion that proves the rule fails on a bad fixture.

RuleTest
Hexagonal dependency direction (domain imports nothing outward, application only domain, adapters do not import each other)TestHexagonalArchitecture
MCP and A2A adapters are read-only and import no REST adapter or outbound clientTestMCPAdapterDependencyRule, TestA2AAdapterDependencyRule, TestA2AAgentIsReadOnlyAndHasNoOutboundClient
No authentication middleware reintroducedTestNoAuthMiddlewareReintroduced
Runtime binaries never import the in-memory adaptersTestRuntimeBinaryHasNoInMemoryAdapters
No Go file at the repository rootTestNoGoFilesAtRepoRoot
CloudEvents only, no flat envelope or toggle; replay consumers set a commit intervalTestNoEventEnvelopeToggleOrFlatEnvelope, TestCloudEventsOnly, TestReplayConsumersSetCommitInterval
Event catalogue test (every own com.warehouse.(wms|wes) or com.retailnetwork type in apis/asyncapi.yaml is in ADR 0004)TestEventCatalogueMatchesContract
Consumer group ids come from configuration, never a literalTestKafkaConsumerGroupNeverHardcodedInline
Kafka writers set RequiredAcks; a writer and its message never both set a topic; dead-letter calls guard cancellationTestKafkaWritersSetRequiredAcks, TestKafkaWriterTopicNotSetTwice, TestDeadLetterCallsGuardCancellation
Every outbox relay passes the attempt capTestOutboxRelaysPassAttemptCap
MCP optional inputs carry omitemptyTestMCPOptionalToolInputsCarryOmitempty
Integration tests use testcontainersTestPostgresIntegrationTestsUseTestcontainers, TestKafkaIntegrationTestsUseTestcontainers

Known discrepancy: internal/architecture/architecture_test.go:23 sets modulePath = "github.com/IQVO/seller-inbound" while go.mod declares module github.com/claudioed/seller-inbound. Whether the arch-go rules of TestHexagonalArchitecture resolve packages under the go.mod path was not verified for this page.

Make targets​

TargetWhat it runs
make build / vet / fmt / fmt-checkgo build ./..., go vet ./..., gofmt -w ., the gofmt check
make lintgolangci-lint run --allow-parallel-runners ./... (pinned v2.14.0)
make testgo test ./... -race
make coveragetests plus the 90 % gate
make bddgo test ./... -run TestFeatures -v
make arch-testthe fitness tests
make integrationtestcontainers suite (Docker)
make mutation / make mutation-fullgremlins
make vulngovulncheck ./...
make checkfmt-check vet build lint test; the lefthook pre-push hook runs it
make check-allcheck plus coverage arch-test bdd
make check-fast, make guide-lint, make harness-testagent-harness helpers (changed packages, guide linter, hook tests)

CI jobs (.github/workflows/ci.yml)​

Triggers: push and pull request on main and develop, a weekly Monday schedule, and manual dispatch.

JobRunsGate
lintgolangci-lint v2.14.0blocking
guide-lintagent-guide sensor and hook testsadvisory (continue-on-error)
complexitygocyclo, gocognit, cyclop, funlen, nestif plus an informational gocyclo reportblocking
file-lengthrevive file-length-limit (at most 300 code lines per production Go file, .golangci.yml)blocking on pull requests into develop for the Go files the PR adds or touches; an informational report of the whole backlog on push, schedule and release PRs
testbuild, vet, make coverageblocking
bddgo test ./... -run TestFeatures -vblocking
integrationgo test -tags=integration ./... -race -count=1blocking
mutation-fastgremlins on every package under internal/domainblocking
mutation, driftexhaustive mutation, deadcode, go mod tidy -diff, knip, coverage-qualityscheduled and manual only; open a harness:red issue on a scheduled failure
api-lintSpectral on both specsblocking
vulngovulncheckblocking
helm-lintct lint and the Service selector testpull requests only
chart-testsevery charts/seller-inbound/tests/*.sh and test_*.pyblocking
arch-testfitness testsblocking
webthe Module Federation remote: lint, tsc -b, vitest, buildblocking
docker-publish, releaseimage, cosign signature, SBOM, Helm chart, tagpush to main only, after the jobs above

docs.yml builds this site on pull requests and deploys it on a push to main. The CI has no trivy scan and no generated-docs drift job.