Skip to content

docs: state the mocking convention - #453

Merged
retr0h merged 2 commits into
mainfrom
docs/state-the-mocking-convention
Aug 16, 2026
Merged

docs: state the mocking convention#453
retr0h merged 2 commits into
mainfrom
docs/state-the-mocking-convention

Conversation

@retr0h

@retr0h retr0h commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

States the mocking convention in this repository, as repo-standards requires: a repository states in full the conventions it is held to, and the rule was in the corpus and in no repository.

Implements rescope-go-code-standards task 5.4. The rule itself landed in osapi-io/specs#96.

What the section says

  • A double for an interface this organization defines is generated with mockgen and committed. Do not hand-write a struct to satisfy one.
  • Generated mocks live in a mocks package beside the code they mock, produced by a generate.go holding the //go:generate directive.
  • The generator resolves through the module's tool dependencies, so every checkout runs the version go.mod records.
  • gen/ is reserved for API code generation — mocks do not go there.
  • Where call sites repeat the same expectations, write a constructor returning a configured mock rather than introducing a hand-written type.

Three doubles stay hand-written, because generating them buys nothing: stdlib interfaces, doubles carrying a real implementation, and recorders for a dependency called from a goroutine the test cannot join.

Identical in all five

The shared Code standards block hashes the same in gohai, nats-client, nats-server, osapi-orchestrator, and osapi — so a difference in wording would mean a difference in rule.

Docs only. just md-fmt-check passes.

Next: the implementations get fixed — gohai's four Collector doubles and internal/executor/gen/, and osapi-orchestrator's mockRenderer.

🤖 Generated with Claude Code

repo-standards requires a repository to state in full the conventions it
is held to. The mocking rule was in the corpus and in no repository, so
a contributor reading this guide could not learn it here.

Adds Test doubles to the shared Code standards section: a double for an
interface we define is generated with mockgen, generated mocks live in a
mocks package beside the code they mock, the generator resolves through
the module tool dependencies, and gen is reserved for API code
generation. Three doubles stay hand-written, where generating buys
nothing.

Stated identically in all five Go repositories.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The Test doubles section under Code standards and the Test file
conventions list under Testing both said mocks are generated and never
hand-written. repo-standards requires a fact to be stated in exactly one
file; stating it twice in one file is the same defect.

Test doubles owns it, since that is where the layout, the generator
directive, and the exceptions are.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #453   +/-   ##
=======================================
  Coverage   99.94%   99.94%           
=======================================
  Files         484      484           
  Lines       24935    24935           
=======================================
  Hits        24921    24921           
  Misses         14       14           

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74e61cb...b2068e6. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@retr0h
retr0h merged commit 16df030 into main Aug 16, 2026
12 checks passed
@retr0h
retr0h deleted the docs/state-the-mocking-convention branch August 16, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant