Closed yiminc-zz closed 4 years ago
This is not true. Mockgen reflect mode does work with type alias, and it also support type redeclaration.
You can run mockgen /import/path/to/foo A,B
to generate mocks for something like
type A Foo
type B = Foo
type Foo interface {
Get()
}
Ah, I think the problem is with source mode. It's non-obvious why that wouldn't work
(Well, it is obvious after you remember how source mode works, of course! source mode can't import other packages)
I think this sounds like a good place for some better docs.
mockgen does work with alias, but I think only correctly with source mode. This feature request is being tracked in #244. I am going to close this one for now as the other has more active discussion talking place. If there is more to be said, lets say it over there.
golang 1.9 introduce this type alias feature where you can define type as alias of another type. There are many different legit use case of that type alias. The mockgen does not seem to be able to generate mocks for type alias.
For example, If i define Foo as interface, then define Bar as alias of Foo, and I want to generate mock for Bar, it won't work.