matryer / moq

Interface mocking tool for go generate

Home Page:http://bit.ly/meetmoq

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

juanli16 opened this issue · comments

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.

commented

Found this #172 (comment)