golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.3k stars 611 forks source link

Mockgen: generate interface mock in another package when method depends from another types of the same package #152

Closed nawa closed 6 years ago

nawa commented 6 years ago

sample project structure is

gomocktst
├── mock_data
│   └── interface_mock.go
├── interface.go
├── interface_test.go

interface.go contains code:

package gomocktst

type ReturnType string
type ParamType string

type Interface interface {
    Method(param ParamType) ReturnType
}

I want to generate mock of Interface in the mock_data package with next command

mockgen -source interface.go -package mock_data -destination mock_data/interface_mock.go

As a result I get inconsistent MockInterface where ParamType and ReturnType aren't imported. More detailed example here https://github.com/nawa/gomocktst/blob/master/mock_data/interface_mock.go#L36

Is it a bug, or I do something wrong?

vail130 commented 6 years ago

I'm having this same issue. Would love some guidance on a workaround or status of a fix.

nawa commented 6 years ago

@vail130 The workaround is to fix it manually

vail130 commented 6 years ago

I opened a PR with a fix, and then found another PR already opened with a fix. And then I switched to pegomock, which works :)

balshetzer commented 6 years ago

This has been fixed by #164.