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

Mockgen fails when an import includes the major version #326

Closed
laconc opened this issue Aug 29, 2019 · 3 comments · Fixed by #385
Closed

Mockgen fails when an import includes the major version #326

laconc opened this issue Aug 29, 2019 · 3 comments · Fixed by #385

Comments

@laconc
Copy link

laconc commented Aug 29, 2019

I'm importing google.golang.org/api/storagetransfer/v1 in one of my source files and attempting to run mockgen on it results in:

Loading input failed: path/to/source.go:16:24: failed parsing returns: path/to/source.go.go:16:45: unknown package "source"

Adding an alias to the import such as storagetransfer "google.golang.org/api/storagetransfer/v1", appears to resolve it, although Goland complains of a redundant alias.

I am using modules.

@codyoss
Copy link
Member

codyoss commented Oct 12, 2019

Hey @laconc would you mind providing the command you are using to generate your mock?

@codyoss codyoss added the status: needs more info This issue need more information from the author. label Oct 12, 2019
@laconc
Copy link
Author

laconc commented Oct 14, 2019

Here you go:

mockgen -source=project-name/gcs/storagetransfer/storagetransfer.go -destination=project-name/gcs/storagetransfer/mocks/storagetransfer.go

@codyoss
Copy link
Member

codyoss commented Oct 15, 2019

Thank you. I have not gotten a chance to test this out myself yet but it does sound like it could be a modules related issue. I will try to investigate further!

@codyoss codyoss added type: bug status: investigating modules and removed status: needs more info This issue need more information from the author. labels Oct 15, 2019
@codyoss codyoss self-assigned this Dec 31, 2019
@codyoss codyoss added this to the v1.5.0 milestone Jan 13, 2020
codyoss added a commit that referenced this issue Jan 20, 2020
This change now makes use of go list to check for package names. This
tool is module aware and allows for better named imports.

To test this change I needed to also add a small package to our mod
file. To keep this import from disappearing from go.mod I made use
of the tools file strategy.

Note this change will change the import names in generated code. This
should not be a breaking change in user code.

Fixes #326
@codyoss codyoss removed this from the v1.5.0 milestone Feb 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants