samber/cc-skills-golang / skills/golang-testing
golang-testing
VerifiedProduction-ready Golang tests — table-driven tests, testify suites and mocks, parallel tests, fuzzing, fixtures, goroutine leak detection with goleak, snapshot testing, code coverage, integration tests, idiomatic test naming. Use when writing or reviewing Go tests, choosing a testing approach, setting up Go test CI, or debugging flaky/slow tests. For testify-specific APIs see `samber/cc-skills-golang@golang-stretchr-testify`; for measurement methodology see `samber/cc-skills-golang@golang-benchmark`.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 17.5 KB |
| evals/evals.json | config | 21.5 KB |
| references/benchmarks.md | markdown | 1.9 KB |
| references/coverage.md | markdown | 1.8 KB |
| references/examples.md | markdown | 1.9 KB |
| references/helpers.md | markdown | 1.0 KB |
| references/http-testing.md | markdown | 2.2 KB |
| references/integration-testing.md | markdown | 4.4 KB |
| references/mocking.md | markdown | 4.6 KB |
references/http-testing.md
View on GitHub# HTTP Handler Testing
Use `httptest` package for testing HTTP handlers without starting a server.
## Basic Handler Test
```go
func TestCreateUserHandler(t *testing.T) {
tests := []struct {
name string
body string
expectedStatus int
}{
{
name: "valid request",
body: `{"name": "Alice", "email": "alice@example.com"}`,
expectedStatus: http.StatusCreated,
},
{
name: "invalid JSON",
body: `invalid json`,
expectedStatus: http.StatusBadRequest,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
is := assert.New(t)
req := httptest.NewRequest(http.MethodPost, "/users", strings.NewReader(tt.body))
req.Header.Set("Content-Type", "application/json")
w := httptest.NewRecorder()
handler := http.HandlerFunc(CreateUserHandler)
handler.ServeHTTP(w, req)
is.Equal(tt.expectedStatus, w.Code)
})
}
}
```
## Query Parameters and Headers
```go
func TestListUsersHandler(t *testing.T) {
tests := []struct {
name string
query string
authHeader string
expectedStatus int
}{
{
name: "paginated results",
query: "?page=1&limit=10",
authHeader: "Bearer token123",
expectedStatus: http.StatusOK,
},
{
name: "missing auth",
query: "?page=1",
authHeader: "",
expectedStatus: http.StatusUnauthorized,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
is := assert.New(t)
req := httptest.NewRequest(http.MethodGet, "/users"+tt.query, nil)
if tt.authHeader != "" {
req.Header.Set("Authorization", tt.authHeader)
}
w := httptest.NewRecorder()
handler := AuthMiddleware(ListUsersHandler)
handler.ServeHTTP(w, req)
is.Equal(tt.expectedStatus, w.Code)
})
}
}
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |