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

Source mode fails with embedded interfaces in a specific case #85

Closed
pasztorpisti opened this issue Jun 27, 2017 · 5 comments
Closed

Source mode fails with embedded interfaces in a specific case #85

pasztorpisti opened this issue Jun 27, 2017 · 5 comments

Comments

@pasztorpisti
Copy link
Contributor

pasztorpisti commented Jun 27, 2017

Here are my test files (2 packages):

github.com/anyuser/pkg1/pkg1.go:

package pkg1

type I interface {
	E
}

type E interface {
	M()
}

github.com/anyuser/pkg2/pkg2.go:

//go:generate mockgen -source pkg2.go -destination pkg2_mock.go -package pkg2 -aux_files pkg1=../pkg1/pkg1.go
package pkg2

import "github.com/pasztorpisti/pkg1"

type I interface {
	pkg1.I
}

If you run go generate on pkg2 then you get the following error message:

2017/06/27 18:03:01 Loading input failed: ../pkg1/pkg1.go:4:2: unknown embedded interface E
pkg2.go:1: running "mockgen": exit status 1

Note that mock generation succeeds if you go to pkg1 and embed the E interface into I by prefixing it with the package name pkg1.E but that turns pkg1.go into invalid go code that doesn't compile.

@JeremyLoy
Copy link

JeremyLoy commented Nov 22, 2017

This also works in the following scenario:

github.com/anyuser/pkg1/file1.go


type A interface {
	Method1()
}

github.com/anyuser/pkg1/file2.go


type B interface {
	A
}

Just to make explicit the difference here: Two separate files, but same package produces the same issue.

mockgen -source=pkg1/file2.go -package pkg1 -aux_files pkg1=pkg1/file1.go -destination pkg1/file2_mock.go

The above produces the 'unknown embedded interface' error.

It can also be resolved as you described, by the following:

type B interface {
	pkg1.A
}

But again, thats invalid Golang code.

@JeremyLoy
Copy link

Looking into it more, I found this TODO in the source code.

// TODO: This does not support recursive embedded interfaces.

@balshetzer
Copy link
Collaborator

balshetzer commented Apr 5, 2018

Both given examples above work now.

@amatoenot
Copy link

@balshetzer Just checked. Not working. The only way to solve this case is to use reflect mode.

@balshetzer
Copy link
Collaborator

As I said in #178, The aux_files flag needs to specify the full package path.

aravindakidambi added a commit to aravindakidambi/antrea that referenced this issue Nov 19, 2021
Test adding a new cluster and leader election

Test leader election when elected leader becomes disconnected

TODO: test removing a cluster

NOTE: Used pegomock to generate a mock for RemoteCluster so that
we can verify StartMonitoring is invoked. TODO: Use mockgen instead
but for now couldnt get it working due to RemoteCluster embedding
CommonArea interface (Ref:golang/mock#85)
Also had to edit the mock file generated by pegomock due to go test
complaining of a race in mock code. Added a mutex lock in the mock
code although ideally we should not edit generated mock files
aravindakidambi added a commit to aravindakidambi/antrea that referenced this issue Nov 19, 2021
RemoteCluster Tests
-------------------

Test that member announce is written and connectivity is set
to true.

TODO: Find out if fakeClient can error writes so we can test
disconnection case

NOTE: used mockgen to generate mocks for Manager from controller-runtime
library and for RemoteClusterManager. TODO: Add mockgen to Makefile
so it always gets generated automatically.

RemoteClusterManager and LeaderElector tests
--------------------------------------------

Test adding a new cluster and leader election

Test leader election when elected leader becomes disconnected

TODO: test removing a cluster

NOTE: Used pegomock to generate a mock for RemoteCluster so that
we can verify StartMonitoring is invoked. TODO: Use mockgen instead
but for now couldnt get it working due to RemoteCluster embedding
CommonArea interface (Ref:golang/mock#85)
Also had to edit the mock file generated by pegomock due to go test
complaining of a race in mock code. Added a mutex lock in the mock
code although ideally we should not edit generated mock files
aravindakidambi added a commit to aravindakidambi/antrea that referenced this issue Nov 19, 2021
RemoteCluster Tests
-------------------

Test that member announce is written and connectivity is set
to true.

TODO: Find out if fakeClient can error writes so we can test
disconnection case

NOTE: used mockgen to generate mocks for Manager from controller-runtime
library and for RemoteClusterManager. TODO: Add mockgen to Makefile
so it always gets generated automatically.

RemoteClusterManager and LeaderElector tests
--------------------------------------------

Test adding a new cluster and leader election

Test leader election when elected leader becomes disconnected

TODO: test removing a cluster

NOTE: Used pegomock to generate a mock for RemoteCluster so that
we can verify StartMonitoring is invoked. TODO: Use mockgen instead
but for now couldnt get it working due to RemoteCluster embedding
CommonArea interface (Ref:golang/mock#85)
Also had to edit the mock file generated by pegomock due to go test
complaining of a race in mock code. Added a mutex lock in the mock
code although ideally we should not edit generated mock files

Signed-off-by: Aravinda Kidambi <akidambi@vmware.com>
aravindakidambi added a commit to aravindakidambi/antrea that referenced this issue Nov 20, 2021
RemoteCluster Tests
-------------------

Test that member announce is written and connectivity is set
to true.

TODO: Find out if fakeClient can error writes so we can test
disconnection case

NOTE: used mockgen to generate mocks for Manager from controller-runtime
library and for RemoteClusterManager. TODO: Add mockgen to Makefile
so it always gets generated automatically.

RemoteClusterManager and LeaderElector tests
--------------------------------------------

Test adding a new cluster and leader election

Test leader election when elected leader becomes disconnected

TODO: test removing a cluster

NOTE: Used pegomock to generate a mock for RemoteCluster so that
we can verify StartMonitoring is invoked. TODO: Use mockgen instead
but for now couldnt get it working due to RemoteCluster embedding
CommonArea interface (Ref:golang/mock#85)
Also had to edit the mock file generated by pegomock due to go test
complaining of a race in mock code. Added a mutex lock in the mock
code although ideally we should not edit generated mock files

Signed-off-by: Aravinda Kidambi <akidambi@vmware.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants