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

aux_files shouldn't be necessary in mockgen #181

Open
balshetzer opened this issue Apr 19, 2018 · 8 comments
Open

aux_files shouldn't be necessary in mockgen #181

balshetzer opened this issue Apr 19, 2018 · 8 comments

Comments

@balshetzer
Copy link
Collaborator

mockgen should try to load all the files in the package in source mode so the user shouldn't need to specify aux_file.

@codyoss
Copy link
Member

codyoss commented Feb 28, 2020

I think this is close being done. The test in the package no longer needs aux_files at least. I need to do a little more research to know if we can deprecate this for sure.

@codyoss codyoss pinned this issue Mar 4, 2020
@codyoss
Copy link
Member

codyoss commented Mar 4, 2020

I would love to hear from users here. The tests we currently have in the library that involve aux_imports no longer need the flag. If you are currently using this flag and you still need it with the current release, v1.4.1, please either comment here or open an issue. I would like to deprecate this flag in a future release and make it a no-op.

@Botono
Copy link

Botono commented Feb 9, 2021

@codyoss I am currently having trouble making mocks of the Prometheus client package. I am trying to make a mock of the gauge.go file. All the files are in vendor/github.com/prometheus/client_golang/prometheus/.

I am using Mockgen v1.4.4.

gauge.go:

package prometheus

type Gauge interface {
	Metric
	Collector
}

metric.go:

package prometheus

type Metric interface {
	Desc() *Desc
}

collector.go:

package prometheus

type Collector interface {
	Desc() *Desc
}

Failed commands:

mockgen --source=vendor/github.com/prometheus/client_golang/prometheus/gauge.go --destination=mypackage/cmd/mocks/gauge.go --package=mocks
2021/02/09 07:54:13 Loading input failed: vendor/github.com/prometheus/client_golang/prometheus/gauge.go:33:2: unknown embedded interface Metric

mockgen --source=vendor/github.com/prometheus/client_golang/prometheus/gauge.go --aux_files github.com/prometheus/client_golang/prometheus=vendor/github.com/prometheus/client_golang/prometheus/metric.go --destination=mypackage/cmd/mocks/gauge.go --package=mocks
2021/02/09 07:54:28 Loading input failed: vendor/github.com/prometheus/client_golang/prometheus/gauge.go:33:2: unknown embedded interface Metric

Frustratingly, the second command previously gave a different failure message:

mockgen --source=vendor/github.com/prometheus/client_golang/prometheus/gauge.go --aux_files github.com/prometheus/client_golang/prometheus=vendor/github.com/prometheus/client_golang/prometheus/metric.go --destination=mypackage/cmd/mocks/gauge.go --package=mocks
2021/02/09 07:27:39 Loading input failed: vendor/github.com/prometheus/client_golang/prometheus/gauge.go:34:2: unknown embedded interface Collector

And adding the collector.go file to the --aux_files option worked!

mockgen --source=vendor/github.com/prometheus/client_golang/prometheus/gauge.go --aux_files github.com/prometheus/client_golang/prometheus=vendor/github.com/prometheus/client_golang/prometheus/metric.go,github.com/prometheus/client_golang/prometheus=vendor/github.com/prometheus/client_golang/prometheus/collector.go --destination=mypackage/cmd/mocks/gauge.go --package=mocks

I cannot repeat this! After thinking I was successful, I was setting up Makefile targets to refresh these mocks. After deleting all the mocks and trying the commands again, I only ever get this message from the above command:

mockgen --source=vendor/github.com/prometheus/client_golang/prometheus/gauge.go --aux_files github.com/prometheus/client_golang/prometheus=vendor/github.com/prometheus/client_golang/prometheus/metric.go,github.com/prometheus/client_golang/prometheus=vendor/github.com/prometheus/client_golang/prometheus/collector.go --destination=mypackage/cmd/mocks/gauge.go --package=mocks
2021/02/09 08:00:24 Loading input failed: vendor/github.com/prometheus/client_golang/prometheus/gauge.go:33:2: unknown embedded interface Metric

@codyoss codyoss removed the status: v2 label Jan 7, 2022
@codyoss
Copy link
Member

codyoss commented Jan 7, 2022

@Botono I believe this case is now fixed, at least on HEAD. I believe all cases were aux_files was needed should now be gone. Unless I hear from users others I will deprecate this flag in the next release and make it a noop in the future.

@intoxicated
Copy link

intoxicated commented Jul 15, 2022

I'm struggling to resolve this issue..

Two interface in two different file but in same package. If I attempt to generate mock file from one interface which composite of the other, I got unknown embedded interface error. Tried to play with aux_files but no luck (not sure what would be input for this package=source.go ? but its in same package)

I'm using 1.6.0 btw

@mpyw
Copy link

mpyw commented Aug 4, 2022

Exactly the same situation as @intoxicated ...

@codyoss
Copy link
Member

codyoss commented Aug 12, 2022

@intoxicated @mpyw This is fixed on HEAD. Please try with v1.7.0-rc.1 and let me know if you still have issues

@aldrin-coexservices
Copy link

aldrin-coexservices commented Feb 10, 2023

@codyoss i am trying to mock uptrace bun IDB interface but I am having error

//go:generate mockgen -source $GOBASE/vendor/github.com/uptrace/bun/query_base.go -aux_files github.com/uptrace/bun/schema=$GOBASE/vendor/github.com/uptrace/bun/schema/hook.go,github.com/uptrace/bun=$GOBASE/vendor/github.com/uptrace/bun/bun.go -destination=$GOBASE/gen/mock/uptracde/bun/query_base.go IDB

output:

----> Generating go stuff GOPATH=/Users/xxxx/go:/Users/xxxx/IdeaProjects/ms-auth-api/vendor:/Users/xxxx/IdeaProjects/ms-auth-api GOBIN=/Users/xxxx/IdeaProjects/ms-auth-api/bin go generate ./... 2023/02/10 08:13:11 Loading input failed: /Users/xxxx/IdeaProjects/ms-auth-api/vendor/github.com/uptrace/bun/query_base.go:75:2: unknown embedded interface ms-auth-api/vendor/github.com/uptrace/bun.Query src/test/pubsub_test/user_auth_upsert_handler_test.go:27: running "mockgen": exit status 1

I am thinking the issue is because of type alias on another interface : https://github.com/uptrace/bun/blob/33503abd50f1dc349179a4470617a962f90b6948/bun.go#L16

how to fix? I am already using 1.7.0-rc.1

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

6 participants