agentleFS
aiproxeraiproxer/aiproxer/.agents/skills/golang-testing/SKILL.md

golang-testing

Skill22 starsChanged 15 days agoMITView on GitHub

Write, review, or prune Go tests: unit, integration, HTTP, concurrent, fuzz, benchmark. Use when adding tests (including to raise coverage), judging whether existing tests prove anything, choosing fixtures/fakes/clocks, or diagnosing flaky tests.

51 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use golang-how-to and golang-samber-lo.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • alexastrumSkill

    golang-how-to

    Golang skills orchestrator — always active on any Golang coding, review, debug, or setup task. Reads the task context and loads the most relevant skills from samber/cc-skills-golang, often multiple at once: writing a gRPC service loads golang-grpc + golang-testing + golang-error-handling; debugging a panic loads golang-troubleshooting + golang-safety; auditing security loads golang-security + golang-lint + golang-safety. Also: disambiguates competing clusters when two skills seem to overlap (performance vs benchmark vs troubleshooting, samber/lo vs mo vs ro, DI cluster, safety vs security), and configures CLAUDE.md or AGENTS.md to force-trigger skills in a project (/golang-how-to configure).

    Also in 7 projects that use this

  • guynhsichngeodiecSkill

    golang-samber-lo

    Functional programming helpers for Golang using samber/lo — 500+ type-safe generic functions for slices, maps, channels, strings, math, tuples, and concurrency (Map, Filter, Reduce, GroupBy, Chunk, Flatten, Find, Uniq, etc.). Core immutable package (lo), concurrent variants (lo/parallel aka lop), in-place mutations (lo/mutable aka lom), lazy iterators (lo/it aka loi for Go 1.23+), and experimental SIMD (lo/exp/simd). Apply when using or adopting samber/lo, when the codebase imports github.com/samber/lo, or when implementing functional-style data transformations in Go. Not for streaming pipelines (→ See golang-samber-ro skill).

    Also in 9 projects that use this

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 47 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    No source or no mutant means no test.

    line 16
  2. Distinctive:

    Find claims: Read these, in order, and collect the behaviour each one requires of the code under change:

    line 22
  3. Very specific:

    Trivial code: Test a getter, String(), or constructor only when its output is itself a contract: a wire value, a config key, a validation …

    line 52

“Common” is measured: kept by at least 6 in 10 of the 47 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Go testing

A test earns its place by defending a claim: one sentence naming behaviour that someone outside the code depends on, and that a plausible bug would break. Coverage is a by-product of tested claims, never a reason to write a test.

Each claim has three parts:

  • Claim: what callers, users, or operators observe. "A request with an unknown proxy key gets 401 and never reaches a backend."
  • Source: where that behaviour is required, named concretely (file, symbol, issue, steering line).
  • Mutant: the concrete bug the test catches. "Delete the !ok check in Gate.ServeHTTP."

No source or no mutant means no test.

Reviewing existing tests instead of writing new ones: follow review.

Writing tests

  1. Find claims. Read these, in order, and collect the behaviour each one requires of the code under change:
    • the task, issue, or bug report you were given;
    • .kiro/specs/<feature>/requirements.md acceptance criteria, when the work belongs to a spec;
    • the godoc of each exported symbol you are testing;
    • "High-Value Semantic Targets" in .kiro/steering/testing.md and "Architecture Guardrails" in AGENTS.md;
    • what the callers of the code do with its return values and errors.
  2. Write the claim table before any test code. One row per claim: claim, source, mutant. A row whose source is "this line is uncovered" or "the function exists" is struck out.
  3. Choose where to observe the claim:
    • pure logic or decisions: call the function directly, table test with one row per distinct outcome;
    • HTTP handler or middleware: httptest, asserting status, body, and what reached the next handler or backend;
    • frontend/backend/core protocol behaviour: add a case to the existing suite under internal/testkit/contract/ before building a new harness;
    • external service or slow dependency: fake only that boundary; use real pkg/aipapi types everywhere else.
  4. Write the test. Assert both what the caller receives (value, error class, status, events) and the side effect that must or must not happen (backend called or not, row persisted or not, retry attempted or not). Name it Test<Unit>_<Claim>: TestGate_UnknownKeyNeverReachesBackend, not TestServeHTTP2. Hard-code expected values worked out from the source, e.g. want := 6, never recomputed with the code's own formula.
  5. See it red. For each row:
    • Under TDD, run the test before the implementation exists and confirm it fails.
    • For code that already exists, edit the production code to the mutant, run go test -run '^TestName$' ./path/to/pkg, confirm FAIL, undo exactly that edit, re-run to PASS, and confirm git diff on the production file shows no leftover mutant.
    • A test that stays green under its mutant asserts the wrong thing. Fix the assertion, not the mutant.
  6. Check every test against these questions. Any "no" means rewrite or delete it:
    • Does its name state the claim?
    • Is the source a concrete requirement, contract, invariant, or bug?
    • Was it observed red under its mutant?
    • Would it still pass after a refactor that keeps behaviour the same?
  7. Hand off the claim table with the red result, plus a list of code you left uncovered and why:

    TestClaimSourceMutant → result
    TestGate_UnknownKeyNeverReachesBackendunknown key → 401, next handler not calledtesting.md: authorization boundariesremoved !ok check → FAIL

Coverage targets. When a task asks for a coverage percentage, write the claim-backed tests, then report the remaining shortfall and the uncovered code by name. Uncovered code either serves a claim you missed (add the claim) or serves none (report it as dead or speculative). A coverage request never justifies a dummy test.

Trivial code. Test a getter, String(), or constructor only when its output is itself a contract: a wire value, a config key, a validation rule in the constructor. Then the claim is that contract, e.g. "New rejects an empty key map".

Dummy tests

These pass against broken code or break on harmless refactors. Never write them; delete them when found.

PatternLooks likeDo instead
Existence checkif New(...) == nil { t.Fatal() }Delete. Claim tests already construct the value.
Getter echoNew("a").Name() == "a"Delete.
Discarded result_ = l.Allow(ctx, "t"), then assert something elseAssert the returned value.
Smoke onlyonly err == nil, or "does not panic", on a function that produces outputAssert the output.
Mock echofake returns X; test asserts X came backAssert what the unit does with X: transforms it, maps the error, decides.
Mirrored oraclewant := l.Limit() - l.used["t"]Hard-code want := 6, derived from the source.
Testing Go or a libraryJSON tags round-trip, const == literal, errors.Is worksDelete. If the wire shape is the contract, assert the exact bytes a client receives.
Change detectorreads private fields, asserts internal call order, exact log or metric textAssert the public outcome. Assert call order only when order is the contract.
Padding rowsten table rows that all take the same pathOne row per distinct outcome or boundary: empty, at limit, limit+1, malformed.
Unrun gatebuild tag or env var no Makefile target setsWire it into a documented target, or delete it.
Tested scaffoldingtests for a test helper or fakeSimplify the helper until it is obviously correct.

Go-specific gotchas

  • t.Fatal/FailNow only from the test goroutine; workers send errors back for assertion after synchronization.
  • t.Context() (Go 1.24+) is cancelled just before t.Cleanup functions run; use it for code that must stop with the test.
  • testing/synctest (Go 1.25+) or an injected clock for timer/deadline ordering. time.Sleep is never synchronization; a timeout bounds a test, it does not fix a race.
  • -race detects races only on exercised paths and cannot prove absence. In this repo never run -race locally: scheduled remote scans own race coverage and it is not a merge gate; see AGENTS.md Verification.
  • Packages that own goroutines need a test-owned shutdown path for each; goleak.VerifyNone/VerifyTestMain proves Stop actually releases them (filter unavoidable runtime goroutines).
  • Fuzz parsers and decoders that take untrusted input; the oracle is a contract property (round-trip, typed error instead of panic, output stays escaped), with a minimal seed corpus.
  • httptest.NewRecorder skips the transport: use httptest.NewServer when headers, streaming flush, connection close, or client behaviour is the claim.
  • sql.Open does not connect; prove readiness with PingContext under a deadline.
  • Benchmarks: b.Loop() where the module's Go version supports it, b.ReportAllocs() when allocations are the claim, compare runs with benchstat.
  • Flakes: reproduce with -count=N and fixed seeds; fix the synchronization, never weaken the assertion.

Repo test policy (layers, proportionality budget, gating, commands) lives in .kiro/steering/testing.md and overrides this skill.

References: helpers, HTTP tests, integration tests, fakes and mocks.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.