matryer / matryer/moq

feat: Allow generation of mocked interface that depends on other mocked interfaces from different packages

Open
#210 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
2.2k
Forks
135
Avg merge
11d 6h
Merged PRs (30d)
1

Description

Please let me know if this is already supported, but I have tried to dig through the issues and PR and find nothing relating to this.

Basically, for the following example use case:

package client

//go:generate moq -out myclient_mock.go . Myclient
type MyClient interface {
    OtherClient() otherservice.Client
    AnotherClient() anotherservice.Client
    ... 
}

where MyClient is an interface that implements other interfaces from different packages, I would like the generated mocked MyClientMock to be able to call the mocked otherService.ClientMock and anotherService.ClientMock.

I can set it up like this to call the other mocked client:

func TestMyClient(t *testing.T) {
    myclient := &client.MyClientMock {
        OtherClient(): func() otherService.Client {
            return otherservice.ClientMock { ... }
        }
        ....
    }
}

But the call stack information for the other mocked clients are not available.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the //go:generate moq -out myclient_mock.go . Myclient entry point and the generated myclient_mock.go output. Trace how mocked otherService.Client and anotherService.Client values are represented across packages, then verify the example test can retain call-stack information from those nested mocks.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
testing, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.