matryer / moq

Interface mocking tool for go generate
http://bit.ly/meetmoq
MIT License
1.96k stars 126 forks source link

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

Open juanli16 opened 9 months ago

juanli16 commented 9 months ago

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.

scorpionknifes commented 8 months ago

Found this https://github.com/matryer/moq/issues/172#issuecomment-1081794286