Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

mockgen does not work with type alias #144

Closed
yiminc-zz opened this issue Jan 22, 2018 · 5 comments
Closed

mockgen does not work with type alias #144

yiminc-zz opened this issue Jan 22, 2018 · 5 comments

Comments

@yiminc-zz
Copy link

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.

@ChuntaoLu
Copy link
Contributor

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()
}

@jmhodges
Copy link
Contributor

jmhodges commented Feb 8, 2019

Ah, I think the problem is with source mode. It's non-obvious why that wouldn't work

@jmhodges
Copy link
Contributor

jmhodges commented Feb 8, 2019

(Well, it is obvious after you remember how source mode works, of course! source mode can't import other packages)

@codyoss
Copy link
Member

codyoss commented Oct 12, 2019

I think this sounds like a good place for some better docs.

@codyoss
Copy link
Member

codyoss commented Jan 15, 2020

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.

@codyoss codyoss closed this as completed Jan 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants