Conversation
Match source-package registration to the ensure declarations actually emitted for each interface, without changing template-data inheritance or explicit import alias precedence. Fixes vektra#1082
LandonTClipp
requested changes
Sep 21, 2026
Comment on lines
+38
to
+42
| dir := t.TempDir() | ||
| require.NoError(t, os.Mkdir(filepath.Join(dir, "api"), 0o755)) | ||
| require.NoError(t, os.WriteFile(filepath.Join(dir, "go.mod"), []byte("module example.com/skipensure\n\ngo 1.25.5\n"), 0o600)) | ||
| source := "package api\ntype First interface { Ping() string }; type Second interface { Pong() string }; type Value struct { N int }; type Typed interface { Get() Value }\n" | ||
| require.NoError(t, os.WriteFile(filepath.Join(dir, "api", "api.go"), []byte(source), 0o600)) |
Member
There was a problem hiding this comment.
Instead of writing out the test file each iteration, can you make a test fixture with this source file, add the config to the root mockery config file, and then write a test file that asserts the behavior of the mock file? Adding mock generation in each test like this will quickly balloon the test run time. That's why the tests generate all of the mock files once and then assert the result of those outputs.
This branch has not been deployed
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.
Description
Fixes #1082.
Register the Matryer source-package import when at least one interface actually emits an ensure declaration. The import section previously checked file-level
TemplateData, while the declarations check each interface's effectiveTemplateData.That mismatch can produce either an unused source import (an interface opts out) or an undefined package qualifier (the file opts out and an interface opts back in).
This changes only the ensure-related registration. Configuration inheritance is unchanged; method-type imports remain intact, and explicit
add-importentries are still processed before automatic ensure imports so a later interface can supply the source alias.Type of change
Version of Go used when building/testing:
How Has This Been Tested?
go/types, not just formatted.test.ciflow passes on Go 1.26.8 and 1.27.1: lint, complete mock regeneration,git-state, 217 unit-test events, shell generation checks, and 10 end-to-end test events. The Go 1.26 run was repeated with--forceso Task did not reuse lint/tool-building cache decisions.GOFLAGS='-mod=readonly -race' GOWORK=off go test -count=1 -json ./...passes with 229 test events and no failures; the flag is inherited by the CLI/consumer subprocesses too.Reproduce the focused tests:
No generated fixtures, dependency manifests, or template-data merge rules are changed.
Checklist
No documentation change is needed: the existing interface-level option now generates compilable code consistently.