go/testing

Free catalog · v0.0.31

Reviews Go tests for broken harnesses, flaky shared state, incomplete cross-entrypoint contracts, and oracles that preserve trivial defects.

Checks

RuleSeverityScans for
go-test.env-no-cleanupMediumos.Setenv in tests instead of t.Setenv
go-test.fatal-in-goroutineHight.Fatal / t.Fatalf / t.FailNow / t.Skip called from a goroutine the test spawned
go-test.hardcoded-portMediumTest binds a fixed TCP port
go-test.helper-missing-helperLowTest assertion helper does not call Helper
go-test.parallel-setenvHighOne test or t.Run callback calls both t.Parallel() and t.Setenv()
go-test.privileged-host-path-mutationMediumChanged Go tests write, delete, rename, chmod, or otherwise mutate a proven path under /etc, /usr, /bin, /sbin, or /var/lib
go-test.partition-boundary-oracleMediumDirect tests prove distinct literal header and trailer values but omit wrong-partition absence assertions, allowing the partitions to be copied or merged
go-test.cross-method-contract-coverageMediumA changed behavioral test exercises only a strict subset of three or more sibling methods carrying the same newly changed returning gate
go-test.selector-boundary-oracleMediumDirect tests of a named order-independent selector let an always-first or always-last implementation pass every applicable multi-element case
go-test.sleep-syncMediumtime.Sleep used to wait for concurrent work before asserting
go-test.testmain-defer-before-exitMediumTestMain exits before deferred cleanup can run
go-test.testmain-no-runHighTestMain defined but never calls m.Run()
go-test.short-mode-skipMediumA direct testing.Short() condition skips a Go test or direct subtest instead of preserving meaningful coverage
go-test.required-env-skipMediumA test skips on a missing literal environment input that it subsequently consumes in an unconditional call
go-test.unconditional-skipLowTest begins with an unconditional t.Skip
go-test.vacuous-absent-assertHighLeak or redaction assertion searches for a sentinel the fixture never configured

go-test.partition-boundary-oracle is intentionally limited to direct Get("literal-key") assertions, or a Get result assigned to a local and asserted in the immediately following statement, on the same stably bound receiver's RequestHeader/RequestTrailer or ResponseHeader/ResponseTrailer accessors. It requires distinct positive literal keys in both partitions and reports only the missing counterpart-absence checks. Known empty/equality assertions close the gap. Dynamic keys, custom or non-adjacent assertions, generic Header/Trailer APIs, different or reassigned receivers, helpers outside direct tests/subtests, ambiguous bindings, unrelated edits, comment-only edits, and deletion-only changes without a current semantic anchor fail closed.

go-test.cross-method-contract-coverage is not a coverage-percentage or table-style rule. It requires at least three exported methods on the same production receiver to add the same receiver-helper call in a returning if gate, plus a changed, assertion-bearing test whose name identifies that helper contract and invokes at least one but not every affected method. Direct sibling test files are loaded as bounded read-only context so existing coverage can close the gap. A centralized gate called once, fewer than three changed methods, differently named tests, unasserted calls, production-only changes, unrelated test edits, generated/vendor/testdata paths, and complete coverage across sibling tests stay quiet.

go-test.short-mode-skip reports direct Skip, Skipf, or SkipNow calls in the branch selected when testing.Short() is true. It recognizes testing import aliases, parentheses, negation and equivalent literal boolean comparisons, including a short-mode skip in an else branch. It follows top-level named Go tests and direct t.Run callbacks, without executing the scanned repository.

Short mode should retain meaningful assertions, using smaller workloads where appropriate. External-service tests should use an explicitly selected integration suite with provisioned prerequisites, rather than treating -short as a blanket coverage exclusion. This is a test-harness policy finding; it does not claim that any particular CI command uses -short or that CI actually skipped tests.

Workload reduction, skips only in full mode, independent opt-in flags, compound conditions, helper-mediated or indirect subtests, dormant closures, nested conditional skips, and ambiguous/shadowed bindings stay quiet. Aliased short-mode values and if initializers are not followed. Diff findings require a changed semantic condition or skip site; existing semantic matches on the base revision, unrelated edits and comment-only changes are suppressed.

go-test.required-env-skip distinguishes missing required inputs from independent suite-selection flags. It follows direct os.Getenv / os.LookupEnv bindings, an immediately following empty/missing-value guard containing only t.Skip, Skipf, or SkipNow, and a later unconditional call consuming that same input. It covers connection strings, fixture paths and other environment-backed inputs without depending on database names, a CI provider, or repository-specific integration conventions. Missing inputs should fail visibly; optional suites should be selected independently and provision their prerequisites.

The rule does not claim that CI ran or skipped anything. It does not flag feature flags used only for selection, missing inputs that fail, logging-only uses, helper-mediated guards, indirect/dormant/conditional consumers, or ambiguous and reassigned bindings. It currently handles top-level named Go tests with adjacent direct guards, not subtests or arbitrary data flow. Diff review requires a changed lookup, guard, skip, or consumer and suppresses existing semantic matches on the base revision; unrelated and comment-only edits stay quiet.

More from the registry