Skip to content

Support for embedding types into mocks in the matryer template #1031

@frozenbonito

Description

@frozenbonito

This issue is a feature proposal based on matryer/moq#226 (implemented in matryer/moq#227).

Some interfaces may have a mechanism to guarantee that a specific type is embedded.

For example, the <ServiceName>Server interface generated by protoc-gen-go-grpc contains an unexported mustEmbedUnimplemented<ServiceName>Server method, which can be implemented by embedding the Unimplemented<ServiceName>Server from the same package.

You can find more information here:
https://github.com/grpc/grpc-go/tree/master/cmd/protoc-gen-go-grpc#future-proofing-services

Real examples can be seen in the helloworld example of grpc-go:

To support this pattern, I propose a feature that allows specified types to be embedded in mocks.

The .mockery.yml would likely look like this:

packages:
  google.golang.org/grpc/examples/helloworld/helloworld:
    interfaces:
      GreeterServer:
        config:
          embed-types:
            - UnimplementedGreeterServer

Since the purpose is to embed types that implement unexported methods, the types used must belong to the same package as the interface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    approvedFeature request approved for development

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions