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

Generating all mocks into one file #564

Closed
yurii-vyrovyi opened this issue Mar 7, 2023 · 4 comments
Closed

Generating all mocks into one file #564

yurii-vyrovyi opened this issue Mar 7, 2023 · 4 comments
Labels
approved feature Feature request approved for development

Comments

@yurii-vyrovyi
Copy link

Description

I want to generate all mocks into one file to avoid garbaging a folder. I have a lot of interfaces in my package and I have a unit tests in the same package. So, if I generate mocks into sub-package I get a cyclic dependency as mypackage refers to mocks while mocks imports mypackage due to data types.

├── mypackage
│   ├── worker.go
│   ├── worker_test.go
│   ├── mocks
│   │   ├── mock_repository_one.go
│   │   ├── mock_repository_two.go
│   │   └── mock_repository_three.go

worker.go

package mypackage
import .../mypackage/mocks

mock_repository_one.go

package mocks
import .../mypackage

Of course I can move all interfaces definitions to some other folder but I prefer not to change a project structure only because of mocks. Another solution is to place mocks into mypackage. Then I have

├── mypackage
│   ├── worker.go
│   ├── worker_test.go
│   ├── mock_repository_one.go
│   ├── mock_repository_two.go
│   └── mock_repository_three.go

That's better from imports prospective but the more interfaces I have the more garbaged my package will be.

Proposal

Can we have a config that will allow to generate all mocks into one file?

@LandonTClipp
Copy link
Contributor

I'm open to the idea. I think generating mocks in-package is generally the safer way to do this because of the cyclic dependency issue you mentioned. If we add this feature, I'd like it to be part of the packages feature first but then also backport it if needed.

@yurii-vyrovyi
Copy link
Author

Sounds great. As for me this will be a point when I want to switch to mockery from mockgen. I really like strong typization in mockrey but we need to keep code clean. I hope it will be soon ;)

@LandonTClipp
Copy link
Contributor

I can't give a good estimate on when this would be done, we need to stabilize the packages feature first. Adding this functionality is kind of non-trivial, but I do see the benefit in it.

@LandonTClipp LandonTClipp added the approved feature Feature request approved for development label Mar 20, 2023
@LandonTClipp
Copy link
Contributor

Closing this as a duplicate of #322

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved feature Feature request approved for development
Projects
None yet
Development

No branches or pull requests

2 participants