writing-go-tests
Installation
SKILL.md
Writing Go Tests
Project-specific test conventions for this codebase.
Critical Rules
- Always use mockery-generated
Moq*mocks when one exists for the interface. Never hand-roll a mock struct for an interface that has a*_mock.gofile. Runmockery(no args) from the module root to regenerate mocks after interface changes. - Use
logger.NoopLogger{}when tests don't need to assert on log output. It already implements the fullLoggerinterface. Never create a custom mock logger just to satisfy the interface — that duplicatesNoopLoggerfor no reason. - Use
logger.MoqLogger{}only when the test needs to verify specific log calls (e.g., asserting thatWarningwas called with a specific message).
Mock Selection Guide
| Situation | Use | Import |
|---|---|---|
Interface has a *_mock.go file |
Moq* struct from that file |
Same package (in-package tests) |
| Logger needed but output doesn't matter | logger.NoopLogger{} |
utils/logger |
| Logger needed and must assert on calls | logger.MoqLogger{} |
utils/logger |
Interface has NO mock file (e.g., MultiSelectSelector[T]) |
Inline mock struct in test file | N/A |