Testing
The backend has two layers of automated tests: fast unit tests that run everywhere, and integration tests that exercise the repositories against a real Postgres. Tests use testify for assertions and mockery-generated mocks for service interfaces.
Unit tests
Section titled “Unit tests”make backend-testThis runs go test -race -v ./... with a 60s timeout. The -race flag enables
the data-race detector, so concurrency bugs surface in CI. Unit tests use the
committed mock_*.go mocks rather than touching a database — see
Code Generation
for how to regenerate mocks when an interface changes.
Integration tests
Section titled “Integration tests”make backend-test-integrationIntegration tests run the repository layer (internal/repositories/postgres/...)
against a live Postgres instance — locally via Docker Compose, in CI via a
service container. They are gated behind the integration build tag, so the
default make backend-test does not run them.
- Override the target database with the
POSTGRES_TEST_DSNenvironment variable. - The timeout is 180s to allow for migrations and real I/O.
Coverage
Section titled “Coverage”make backend-test-coverageThis writes coverage.out and renders coverage.html in backend/. Clean up
the artifacts with make backend-test-clean.
Service interfaces are mocked with mockery. Regenerate all mocks after changing an interface:
make backend-mock-generateThe generated mock_*.go files are committed and must not be hand-edited.
Spec conformance
Section titled “Spec conformance”The internal/specconformance package contains tests asserting that the running
server matches the OpenAPI spec. These run as part of make backend-test and
help catch drift between the implementation and
the spec.
Before you commit
Section titled “Before you commit”Run the same checks CI runs:
make backend-test # unit tests (-race)make backend-check # lint + vulncheck + securityRun make backend-test-integration as well when you touch the repository layer
or migrations. See Database & Migrations.