-
Notifications
You must be signed in to change notification settings - Fork 413
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
Fix(recursive): use packages.Load support for recursive search instea… #838
Conversation
7b3c5d9
to
4192ae1
Compare
Thanks for the PR. Does this work in the case where the package exists on a remote git repo (not on local disk)? |
Could you help me test that? I have tested on a package that generates mocks from the own package and from an external package ( a github one ). I don't know exactly what you mean by local disk. The package is cached at the go cache folder and referenced using the package name, not a filepath |
I tested this out myself. I forked the AWS Go SDK, modified it a bit, and attempted to generate mocks for a package with no Go files, using your changes. https://github.com/LandonTClipp/aws-sdk-go/tree/main/service I added this config to the github.com/LandonTClipp/aws-sdk-go/service:
config:
recursive: True
all: True
exclude: ["cloudwatch", "s3", "internal", "s3control", "glacier"] I deleted the
Aha! It found 772, which sounds about right. (Note you need to append |
I tried another example with a more minimal Go module: https://github.com/LandonTClipp/example-go github.com/LandonTClipp/example-go/pkg:
config:
recursive: True
all: True
It's successful! And I see the mocks outputted. So yeah I guess I was totally wrong. I thought I had tried this initially, maybe the Go compiler handles this better now? Idk, but clearly your fix works AND it gets rid of a lot of nasty code I had to write. Well done! Another thing to think about. Do we really need the Yet another thing to think about.... currently when mockery discovers the recursive packages, it injects configuration into the yaml (well really, just the in-memory map) for each subpackage as if it was specified in the yaml. You can see this in the packages:
github.com/LandonTClipp/example-go/pkg:
config:
all: true
disable-version-string: true
filename: '{{.MockName}}.go'
mockname: '{{.InterfaceName}}'
outpkg: mocks
quiet: false
recursive: true
tags: custom2
with-expecter: true
github.com/LandonTClipp/example-go/pkg/subpkg1:
config:
all: true
disable-version-string: true
filename: '{{.MockName}}.go'
mockname: '{{.InterfaceName}}'
outpkg: mocks
quiet: false
recursive: true
tags: custom2
with-expecter: true
github.com/LandonTClipp/example-go/pkg/subpkg2:
config:
all: true
disable-version-string: true
filename: '{{.MockName}}.go'
mockname: '{{.InterfaceName}}'
outpkg: mocks
quiet: false
recursive: true
tags: custom2
with-expecter: true I wonder if we were to rely on the |
226f24d
to
4192ae1
Compare
…d of manual - Fix(Parsepackages): Ignore packages with no Go files
4192ae1
to
97ba6f2
Compare
Great! Thank you, I will get this released soon. |
Description
Related Issue: #636
This Pull Request attempts to implement a better recursive behavior for mockery.
Instead of giving an error when no Go files are present, we lookup using
packages.Load
and ignore packages with no goFiles.Shifts sub-package lookup responsibility to
packages.Load
.I had to change the tests to not error when there are no go files for the package.
I would love some feedback about this proposal.
Type of change
Version of Go used when building/testing:
How Has This Been Tested?
It was ran against a package that contains no Go files, but do contain sub-packages. These sub-packages had the mocked files generated without any further issues.
Checklist