henriqueatila/golang-gin-best-practices / skills/golang-gin-testing
golang-gin-testing
VerifiedTest Go Gin APIs with httptest, table-driven tests, testcontainers. Use when writing tests for Gin handlers, services, middleware, or setting up integration and e2e tests.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 7.7 KB |
| metadata.json | config | 495 B |
| references/e2e-cicd-config-and-cleanup.md | markdown | 5.1 KB |
| references/e2e-structure-and-critical-flow.md | markdown | 6.9 KB |
| references/integration-tests-api-migrations-and-fixtures.md | markdown | 3.6 KB |
| references/integration-tests-cleanup-and-repository.md | markdown | 5.8 KB |
| references/integration-tests-setup-and-testmain.md | markdown | 4.3 KB |
| references/load-testing-benchmarks-and-vegeta.md | markdown | 2.1 KB |
| references/load-testing-k6-and-ci-regression.md | markdown | 3.1 KB |
| references/test-patterns-helpers-and-handler-tests.md | markdown | 4.8 KB |
| references/test-patterns-service-tests-and-running.md | markdown | 2.8 KB |
| references/unit-tests-benchmarks-fuzz-and-golden.md | markdown | 5.1 KB |
| references/unit-tests-fixtures-helpers-and-middleware.md | markdown | 4.7 KB |
| references/unit-tests-handler-and-json.md | markdown | 5.8 KB |
| references/unit-tests-service-mocks-and-table-driven.md | markdown | 5.6 KB |
references/load-testing-k6-and-ci-regression.md
View on GitHub# Load Testing — k6, Performance Targets, and CI Benchmark Regression
## k6 Load Testing
Script-based load tester with thresholds and stages. Good for realistic traffic patterns.
```bash
brew install k6 # macOS
sudo snap install k6 # Linux
```
```js
// load-test.js
import http from "k6/http";
import { check, sleep } from "k6";
export const options = {
stages: [
{ duration: "30s", target: 50 }, // ramp up to 50 VUs
{ duration: "1m", target: 50 }, // sustain
{ duration: "15s", target: 0 }, // ramp down
],
thresholds: {
http_req_duration: ["p(95)<200", "p(99)<500"], // latency gates
http_req_failed: ["rate<0.01"], // <1% error rate
},
};
export default function () {
const res = http.get("http://localhost:8080/api/v1/users/1", {
headers: { Authorization: `Bearer ${__ENV.TOKEN}` },
});
check(res, { "status 200": (r) => r.status === 200 });
const payload = JSON.stringify({ name: "Alice", email: "alice@example.com" });
const postRes = http.post("http://localhost:8080/api/v1/users", payload, {
headers: { "Content-Type": "application/json" },
});
check(postRes, { "status 201": (r) => r.status === 201 });
sleep(1);
}
```
```bash
TOKEN=your-jwt k6 run load-test.js
```
k6 exits non-zero if any threshold is breached — suitable for CI gates.
---
## Performance Targets
Typical targets for a single Go Gin instance on commodity hardware (2 vCPU / 4 GB RAM):
| Metric | Target |
|--------|--------|
| p50 latency | < 50 ms |
| p95 latency | < 200 ms |
| p99 latency | < 500 ms |
| Error rate | < 0.1% |
| RPS per instance | > 1 000 |
Adjust based on: external I/O (DB, Redis), payload size, auth middleware overhead.
---
## CI Integration — Benchmark Regression Detection
Use `benchstat` to catch performance regressions between commits.
```bash
go install golang.org/x/perf/cmd/benchstat@latest
```
```yaml
# .github/workflows/benchmarks.yml
jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- uses: actions/setup-go@v5
with: { go-version: "1.22" }
- name: Run benchmarks (HEAD)
run: go test -bench=. -benchmem -count=6 ./... | tee bench-head.txt
- name: Checkout base branch
run: git checkout ${{ github.base_ref }}
- name: Run benchmarks (base)
run: go test -bench=. -benchmem -count=6 ./... | tee bench-base.txt
- name: Compare with benchstat
run: |
benchstat bench-base.txt bench-head.txt
benchstat -html bench-base.txt bench-head.txt > bench-report.html
- uses: actions/upload-artifact@v4
with: { name: bench-report, path: bench-report.html }
```
**Interpreting benchstat:**
```
name old time/op new time/op delta
GetUserHandler-8 9.82µs ± 2% 8.91µs ± 1% -9.26% (p=0.008 n=6+6)
```
- Negative `delta` = improvement; `p<0.05` = statistically significant change
- Use `-count=6` for reliable statistics
> For Go benchmarks and Vegeta: see [load-testing-benchmarks-and-vegeta.md](load-testing-benchmarks-and-vegeta.md).
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 |