test-handler

Writes API tests for Connect-RPC handlers using httptest servers and generated clients.

Updated Sep 14, 2026
One-click install
npx skills add https://github.com/nakamori-naoya/go-convention-plugins --skill test-handler-nakamori-naoya
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: test-handler
Source: https://github.com/nakamori-naoya/go-convention-plugins/tree/main/plugins/go-convention/skills/test-handler
Command: npx skills add https://github.com/nakamori-naoya/go-convention-plugins --skill test-handler-nakamori-naoya

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing handler tests for Connect-RPC services often drifts into shallow unit tests that bypass interceptors, or into duplicated lower-layer checks. This Skill defines how to test a Go handler as a public API: boot the production-identical composition on httptest.NewServer, call it with the generated client, and verify connect.Code translation, public error messages, authorization, persistence effects, and response content. ## Core Features & Use Cases - API-level test structure: Boots the same NewMux(Deps) composition function used by run, swapping only the auth interceptor, with a real PostgreSQL via dockertest and a fixed Clock. - Case selection rules: Enumerates success, each reachable sentinel-to-Code translation, missing caller, wrong owner, and invalid input per RPC, while excluding domain boundary values, SQL concerns, and usecase coverage that belong to other layers. - Table-driven shape: Defines seed/caller/req to wantCode/wantMessage/wantResp/want{Table} fields with projection structs, sentinel .Error() references, and a branch-free loop body. - Use Case: Given a reservation service with a ConfirmReservation RPC, produce a table-driven test that verifies FailedPrecondition for expired holds, PermissionDenied for non-owners, NotFound for missing reservations, and the persisted status/version change on success. ## Quick Start Write the API test for this RPC following the test-handler convention, booting the real server composition and verifying each public result.

Frequently Asked Questions about test-handler

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test a Connect-RPC handler in Go?▼

Boot the same composition function that run uses on httptest.NewServer with a real database, fixed Clock, and a test auth interceptor, then call it with the generated client. Verify connect.CodeOf(err), the error message, response projections, and persisted rows per case.

How to write table-driven API tests for RPC handlers?▼

Use an anonymous struct slice with id, name, description, seed rows, caller, request, then wantCode, wantMessage, wantResp, and want{Table} projections. The loop body resets and seeds the database, calls the RPC, and asserts Code, message, response, and persistence without per-case branching.

Should handler tests use mock usecases or repositories?▼

No. This convention replaces only the auth interceptor and runs the real usecase, repository, transaction manager, and PostgreSQL. Fakes would miss wiring bugs like a missing transaction, and duplicating lower-layer checks is explicitly out of scope.

Does this approach work without Docker?▼

Tests can be written without Docker but cannot run, because the real PostgreSQL is started via dockertest in TestMain. The convention requires reporting execution as incomplete rather than claiming the tests passed.

What should handler tests not cover?▼

They exclude domain boundary values, SQL and DB constraint behavior, full-table column comparison, usecase concerns like transaction rollback, and log output. Those belong to the domain, persistence, and usecase test layers respectively.