test(go): add unit tests for Go API - #403
Conversation
Handler tests through httptest with a fake repository and repository tests through go-sqlmock cover every endpoint and error path. Count no longer calls log.Fatal on a database error; it returns the error like the other methods so the handler answers 500 instead of killing the process. CI now runs tests with coverage and fails under 70 percent. Closes #303
|
Reviewed the diff against CLAUDE.md/agents.md. No blockers or majors. [minor] [minor] The new coverage gate ( [nit] Coverage gate script recomputes Everything else checks out: the Ready for human review. |
Summary
pkg/api/handler_test.go: all six handlers through httptest with a scripted fake repository: success, 404, 400 and 500 paths (19 cases).pkg/api/repository_test.go: Postgres repository throughgo-sqlmock(test-only dependency): GetAll, Count, GetByID, Create, Update, Delete, asserting SQL shape (deleted filter, argument order, soft delete) and error propagation (15 cases).Countcalledlog.Fatalon a database error, which terminated the API process; it now returns the error and the handler answers 500.go-pull-request.yml:go test -coverpkg=./... -coverprofileplus a coverage gate (MIN_COVERAGE=70). Current total 78.3% (pkg/api98.1%,cmd/app/main.gouncovered).Closes #303
Test plan
go test ./... -count=1 -coverpkg=./...green locally, 78.3% totalgo vet,gofmt -lclean; actionlint cleango - build - pull requestgreen with the new coverage step