go-test-gen
Go Unit Test Generator
Generate unit tests for Go service and repository layers.
Critical Rules
- NO mock.Any/mock.Anything - Use explicit arguments
- NO mock.MatchedBy - Prefer concrete structs
- ALL mocks require call counts -
.Once(),.Twice(), etc. - Use
wantErr error- NotwantErr bool - Test naming:
TestPackageName_FunctionNamewith cases like"Success_with_valid_input" - NO handler/API tests - Service and repository layers only
Workflow
- Identify layer: service or repository
- Read function to test
- For service tests: See references/service-tests.md
- For repository tests: See references/repository-tests.md
- Generate test following the template
- Verify all mock expectations have call counts
Testing Strategies
- Unit tests: Test individual functions in isolation with mocks
- Table-driven tests: Use for multiple input/output scenarios
- Test coverage: Aim for 80%+ meaningful coverage
- Mock generation: Use
//go:generate mockery --name InterfaceName --output ../mock/package - Test structure: Define all mocks at the top of test functions for clarity, do not put mocked repository as function args
- Database testing: Use
sqlmockwithDATA-DOG/go-sqlmockfor database layer testing with consistent structure - Handler layer testing: DO NOT generate unit tests for handler layer (API controllers) - focus testing on service and repository layers only
Quick Reference
Service Layer
- Mock dependencies at function top
- Table-driven structure
- Explicit mock expectations
- Specific error assertions
Repository Layer
- Use sqlmock with DATA-DOG/go-sqlmock
regexp.QuoteMeta()for queries- Verify
mock.ExpectationsWereMet() - Specific errors with
apierror.Get()
More from sultanfarizbythen/skills
go-code-review
Reviews Go backend PRs for bugs, potential bugs, anomalies, and redundant code. Specialized for Bythen repos (platform-svc, go-core) using wire DI, custom query builder, layered architecture (handler/service/repository). Use when reviewing Go PRs, diffs, or code changes.
9sql-query-generator
Generate and execute SQL queries for databases using the Kalysta MCP server. Use when the user needs to query database information, analyze data patterns, explore table contents, generate reports, or investigate data. Supports any database accessible via Kalysta MCP.
9create-devops-task
Creates draft tasks on the Bythen Devops GitHub Project board (https://github.com/orgs/tanookiai/projects/2/views/1). Always assigns novahariyabythen. Use when asked to add tasks, to-dos, or action items to the devops board.
4update-scientia-ip
Update the Scientia WiFi IP whitelist in Jenkins. Captures the current public IP before VPN, connects OpenVPN, then triggers the Jenkins `change-ip-wifi-scientia` job with the captured IP. Use when your WiFi IP has changed and you need to regain Scientia access.
4go-pr-description
>
3be-jenkins-deploy
Deploy a backend (BE) branch to a non-production Jenkins job and notify when done. Use this skill whenever the user says "deploy to staging", "deploy to jenkins", "trigger jenkins build", "deploy branch", "push to jenkins", or any variation of deploying/releasing a backend service via Jenkins CI/CD. Also trigger when the user asks to redeploy or check a Jenkins deployment in progress. Do NOT use this skill if the user mentions "prod", "production", or "beta" — those environments require manual confirmation and are out of scope.
3