| name | writing-tests |
| description | Guide for writing tests in GOMP. Use this when asked to create or run tests. |
Writing Tests in GOMP
ALWAYS use this skill when asked to write or add tests.
Use this guide for consistent tests across API, DB, and middleware layers.
Core Patterns
- For Go, always use table-driven tests when testing multiple input/output scenarios.
- For Go, Keep tests in package-local
*_test.go files near the implementation.
- Focus on behavior and contract verification over implementation detail.
API Layer Tests (api/)
- Use
httptest.NewRequest and httptest.NewRecorder.
- Route through generated handler wiring where possible to exercise request parsing and response encoding.
- Verify:
- HTTP status code
- response body payload
- auth/permission behavior
- error mapping for invalid request/body/path mismatches
DB Layer Tests (db/)
- Use
go-sqlmock for SQL expectation tests.
- Assert SQL statements, bind argument ordering, and scan behavior.
- Include not-found and error-path checks.
Mocks and Interfaces
- Use generated mocks under:
mocks/db/mocks.gen.go
mocks/upload/mocks.gen.go
- Regenerate with
go generate ./... when interfaces change.
Coverage Expectations
- Add tests for success path and at least one meaningful failure path.
- For write endpoints, verify side effects and returned payload shape.
- For auth-sensitive endpoints, test denied and allowed roles.
Validation Loop
make codegen (if schemas/interfaces changed)
make test
make lint
Guardrails
- Do not test generated files directly.
- Avoid brittle tests that depend on exact log text or unrelated ordering.
- Keep fixtures minimal and focused.