Skip to content

docs: say where a mock for an unexported interface goes - #454

Merged
retr0h merged 1 commit into
mainfrom
docs/mocks-for-unexported-interfaces
Aug 16, 2026
Merged

docs: say where a mock for an unexported interface goes#454
retr0h merged 1 commit into
mainfrom
docs/mocks-for-unexported-interfaces

Conversation

@retr0h

@retr0h retr0h commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

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

The Test doubles section said generated mocks live in a sibling mocks package. For an unexported interface that is impossible, and the compiler proves it:

imports .../pkg/orchestrator/mocks from orchestrator_test.go
imports .../pkg/orchestrator from renderer.gen.go: import cycle not allowed in test

The mock has to import the package to name the types in the interface; the package's own tests have to import the mock.

What is added

The second case, with its destination scoped to tests:

// generate.go, in the package that declares the interface
package thispackage

//go:generate go tool go.uber.org/mock/mockgen -source=thing.go -destination=thing.gen_test.go -package=thispackage

Scoping is load-bearing rather than tidiness — an unscoped mock puts go.uber.org/mock into the dependency graph of everything that imports the package.

Either way the directives live in a generate.go holding no code, and the generated file carries .gen so a reader knows not to edit it.

The section hashes identically in all five Go repositories.

Docs only. just md-fmt-check passes.

🤖 Generated with Claude Code

The Test doubles section said generated mocks live in a sibling mocks
package. For an unexported interface that is impossible: the mock has to
import the package to name the types in the interface, and the package
own tests have to import the mock, which the compiler rejects as a
cycle.

Records the second case, and why its destination is scoped to tests --
an unscoped mock puts the mocking library into the dependency graph of
everything that imports the package.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@retr0h
retr0h merged commit eb57692 into main Aug 16, 2026
10 checks passed
@retr0h
retr0h deleted the docs/mocks-for-unexported-interfaces branch August 16, 2026 18:12
@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     #454   +/-   ##
=======================================
  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 16df030...d971d76. 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.

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