Skip to content

feat: support embedded types in matryer mocks - #1184

Open
eliotee wants to merge 1 commit into
vektra:v3from
eliotee:feat/matryer-embedded-types
Open

feat: support embedded types in matryer mocks#1184
eliotee wants to merge 1 commit into
vektra:v3from
eliotee:feat/matryer-embedded-types

Conversation

@eliotee

@eliotee eliotee commented Sep 6, 2026

Copy link
Copy Markdown

Description

Add struct-preamble and add-import template 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

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Version of Go used when building/testing

Go 1.26.0 on macOS arm64.

How Has This Been Tested?

  • The original template generated an external mock that failed to compile because it did not implement the unexported interface method; the new embedding fixtures compile and pass.
  • Schema, import-name conflict, deduplication, and generated mock behavior tests pass.
  • 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.
  • Repeated mocks.generate left all 243 Go files byte-for-byte identical; hand-written Go files were formatted with gofumpt, and git diff --check passed.

Checklist

  • I have performed a self-review of my code
  • I have made corresponding changes to the documentation
  • I have added tests that prove this feature works
  • New and existing unit tests pass locally with my changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for embedding types into mocks in the matryer template

1 participant