Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add source package support #270

Merged
merged 1 commit into from
May 28, 2020
Merged

Conversation

vincent178
Copy link
Contributor

@vincent178 vincent178 commented May 26, 2020

Signed-off-by: Vincent Huang [email protected]

Background

There's a usecase we want to generate mock for external package, there's one solution in community #210 (comment), but it's not clean to specify another alias interface into my codebase. The other solution is using -dir like in this #210 (comment) but it requires some knowledge to use it right, like it's different under go module and $GOPATH.

With this change, we can generate an external package mock anywhere (with go.mod or under $GOPATH) with

$ mockery -srcpkg github.com/aws/aws-sdk-go/service/s3 -all

Changes

  • add flag srcpkg
  • import srcpkg, read directory and set BaseDir to it

Test

  • manually verified on local
  • add integration tests
  • add unit tests

@LandonTClipp
Copy link
Collaborator

Hi Vincent, this looks great! Can you add tests to verify that this works as expected?

@vincent178
Copy link
Contributor Author

Hi @LandonTClipp , PTAL

@LandonTClipp
Copy link
Collaborator

LandonTClipp commented May 26, 2020

@vincent178 according to the go/loader docs, it is deprecated: https://godoc.org/golang.org/x/tools/go/loader

Deprecated: This is an older API and does not have support for modules. Use golang.org/x/tools/go/packages instead.

Can we use go/packages instead? go/loader does not support modules.

@vincent178
Copy link
Contributor Author

@LandonTClipp good catch, it's interesting that I tested go/loader does support our usecase with go modules, but anyway, I have changed to go/packages, PTAL, thanks.

* add srcpkg flag pass in external package import path
* use golang.org/x/tools/go/packages parse package
* add unit tests and integration tests
@LandonTClipp
Copy link
Collaborator

Looks good to me. I was about to ask you to to add more unit tests but it looks like those don't really exist for main. This'll be something I'll fix in v2

@LandonTClipp LandonTClipp merged commit 5b00589 into vektra:master May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants