Skip to content

test(go): add unit tests for Go API - #403

Merged
kauereinbold merged 1 commit into
mainfrom
test/go-unit-tests
Aug 22, 2026
Merged

test(go): add unit tests for Go API#403
kauereinbold merged 1 commit into
mainfrom
test/go-unit-tests

Conversation

@kauereinbold

Copy link
Copy Markdown
Owner

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 through go-sqlmock (test-only dependency): GetAll, Count, GetByID, Create, Update, Delete, asserting SQL shape (deleted filter, argument order, soft delete) and error propagation (15 cases).
  • Fix: Count called log.Fatal on a database error, which terminated the API process; it now returns the error and the handler answers 500.
  • CI go-pull-request.yml: go test -coverpkg=./... -coverprofile plus a coverage gate (MIN_COVERAGE=70). Current total 78.3% (pkg/api 98.1%, cmd/app/main.go uncovered).

Closes #303

Test plan

  • go test ./... -count=1 -coverpkg=./... green locally, 78.3% total
  • go vet, gofmt -l clean; actionlint clean
  • Gate verified locally: passes at 70, fails at 99
  • CI go - build - pull request green with the new coverage step

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
@github-actions

Copy link
Copy Markdown

Reviewed the diff against CLAUDE.md/agents.md. No blockers or majors.

[minor] repository_test.go (TestRepositoryGetByID, "other errors also map to ErrorReminderNotFound"): the test pins down existing behaviour in GetByID where any DB error (not just sql.ErrNoRows) is mapped to ErrorReminderNotFound and surfaced as a 404, masking real failures as "not found". Out of scope for this PR (Count fix only), but worth a follow-up issue since the test now locks the bug in as intended behaviour.

[minor] The new coverage gate (MIN_COVERAGE=70, hard exit 1 below threshold) is a new enforced process rule; the dotnet and react PR workflows only collect/upload coverage today without failing the build. Not a blocker, but if this is meant to become the standard, worth a short ADR note or a follow-up to align the other pipelines for consistency.

[nit] Coverage gate script recomputes total via awk twice conceptually (once for parsing, once inside the awk comparison) - fine as is, just noting it's a bit dense; a comment explaining the double-negative exit !(t < m) would help future readers.

Everything else checks out: the Count() log.Fatal → returned error fix matches the PR description and handler test coverage, SQL argument order/soft-delete/route-id-over-body-id assertions in repository_test.go are correct, go-sqlmock is a test-only dependency, PR title is conventional (test(go): ...), no secrets/dashes/AI attribution found.

Ready for human review.

@kauereinbold
kauereinbold merged commit 2b1fc2a into main Aug 22, 2026
10 checks passed
@kauereinbold
kauereinbold deleted the test/go-unit-tests branch August 22, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(go): add unit tests for Go API

1 participant