| name | write-go-tests |
| description | Unified conventions for writing Go unit/integration tests (TR-F022). Use when adding tests for any Go code change. |
Skill: Write Go Unit / Integration Tests
Feature ID: TR-F022
When to use
Any Go code change must ship with tests. This skill unifies the test conventions.
Pre-research
file_search "internal/**/*_test.go" # find the closest template
view internal/adminapi/nodes_test.go # API test template
view internal/radiusd/*_test.go # protocol test template
view internal/app/*_test.go # app-layer test template
Conventions
- Co-located tests: the test file is in the same package and directory as the code under test, named
<file>_test.go.
- Short-test marking: for slow / externally dependent tests use
if testing.Short() { t.Skip(...) }; CI runs go test -short.
- Database: dev / test use SQLite (pure Go,
CGO_ENABLED=0); schema changes must be compatible with both databases.
- Coverage focus: success path + failure path (reject reasons, timeouts, validation failures, authz failures).
- Metrics / errors: auth-reject changes must assert the corresponding
AuthError / metrics tag.
- Table-driven: use table-driven tests for multiple scenarios.
Run
go test ./...
go test -short ./...
go test -run TestXxx ./internal/...
go test -bench=. ./internal/radiusd/
golangci-lint run
Acceptance