feat: support embedded types in matryer mocks - #1184
Open
eliotee wants to merge 1 commit into
Open
Conversation
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
Add
struct-preambleandadd-importtemplate data to matryer mocks so interfaces requiring an embedded type, such as gRPC server interfaces with unexported marker methods, can be implemented outside their original package. Each mock can inject literal Go struct fields and request explicitly named imports; imports are shared across mocks in the same file, and conflicting names produce a generation error instead of silently changing the meaning of the preamble.Document and validate the new options. Add compiled fixtures for external and in-package embedding, generic types, multiple interfaces, and explicit aliases. The generated fixtures account for most of the added lines. The testify template and existing import-registration behavior are unchanged.
Fixes #1031.
Type of change
Version of Go used when building/testing
Go 1.26.0 on macOS arm64.
How Has This Been Tested?
go run github.com/go-task/task/v3/cmd/task test test.e2e: 199 unit tests, all shell e2e scenarios, and 5 Go e2e tests passed.go run github.com/go-task/task/v3/cmd/task lint: 0 issues.mocks.generateleft all 243 Go files byte-for-byte identical; hand-written Go files were formatted with gofumpt, andgit diff --checkpassed.Checklist