golang / mock

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

Generation mock from net, unknown embedded interface error #510

Closed maranqz closed 3 years ago

maranqz commented 3 years ago

command mockgen -source=~/go/go1.15.6/src/net/net.go -destination=test/mock/net/Conn.go --package=mocknet

Actual behavior A clear and concise description of what the bug is.

2021/01/19 13:16:37 Loading input failed: ~/go/go1.15.6/src/net/net.go:397:2: unknown embedded interface error

Additional Information

codyoss commented 3 years ago

I believe this is fixed on HEAD, just not released yet. Could you try installing head and see if it works, it did for me.

Also you can use reflect mode to generate just the interface you want, which would also solve this for you:

mockgen -destination=mock2/conn.go --package=mocknet net Conn

Let me know if this does not work and we can re-open.

maranqz commented 3 years ago

@codyoss You are right. However, in generated file there is code (net "std/net"), which creates problem. "std/net: package std/net is not in GOROOT (/home/qz/go/go1.15.6/src/std/net)" The problem disappeared by replacing (net "std/net") with ("net").