docs: say where a mock for an unexported interface goes - #454
Merged
Conversation
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>
Codecov Report✅ All modified and coverable lines are covered by tests. @@ 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.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements
rescope-go-code-standardstask 5.4a. The rule landed in osapi-io/specs#98.The
Test doublessection said generated mocks live in a siblingmockspackage. For an unexported interface that is impossible, and the compiler proves it: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:
Scoping is load-bearing rather than tidiness — an unscoped mock puts
go.uber.org/mockinto the dependency graph of everything that imports the package.Either way the directives live in a
generate.goholding no code, and the generated file carries.genso a reader knows not to edit it.The section hashes identically in all five Go repositories.
Docs only.
just md-fmt-checkpasses.🤖 Generated with Claude Code