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

Mockery also generates mocks for interfaces inside mock*.go #471

Closed
tinoquang opened this issue Jun 1, 2022 · 7 comments
Closed

Mockery also generates mocks for interfaces inside mock*.go #471

tinoquang opened this issue Jun 1, 2022 · 7 comments

Comments

@tinoquang
Copy link

Description

  • When using --inpackage flag, mock files also contain an inteface, sth like this:

type NewMockPublisherT interface {
mock.TestingT
Cleanup(func())
}

  • Then in the next run, mockery also generates mock file for this interface, which I think is redundant

Version

v2.12.3

Steps to Reproduce

  1. Generating mocks with --inpackage flag
  2. Generating mocks one more time

Expected Behavior

  • Only mocks for actual interfaces are generated, not interfaces inside mock files

Actual Behavior

  • New mock files will also be created for interfaces inside previous mock files
@LandonTClipp
Copy link
Contributor

I think this is a regression after we introduced testingT interfaces inside of the mock files. We'll need to figure out a way to exclude files that contain the preamble comment at the top of mock files.

@tinoquang
Copy link
Author

What I did temporarily is removing all the mock files first, then generating mocks again (I did it with Makefile). Can we use that approach for this case?

@LandonTClipp
Copy link
Contributor

I don't think mockery should be removing files. Actually, one workaround that might work (if/when we merge the PR) is to place a .mockery_skip_tree inside the mocks directory to skip it entirely. But, I'd prefer to not force people to do extra work just to prevent mockery from doing something unexpected.

@tinoquang
Copy link
Author

I see. So currently the finest solution could be igoring files that begin with Generated with mockery. Is that what you mean?

@LandonTClipp
Copy link
Contributor

LandonTClipp commented Jun 1, 2022

Correct I think so. That would break if people find a way to remove the preamble but I can't think of another reliable solution at the moment. We could key off of the file's name to determine whether it's a mock file or not, but the way people name their mock files could change... and it just seems kind of fragile.

phinze added a commit to hashicorp/vagrant-plugin-sdk that referenced this issue Jun 3, 2022
@LandonTClipp
Copy link
Contributor

This has been fixed in the most recent version. #472

@tinoquang
Copy link
Author

Sorry for the late response. I agree that the solution is a bit tricky, haha. I already tried your solution before and realized that we couldn't just check the file header since loadPackages function always get all the interfaces inside a pkg (including the mock interface). Good to see it's been fixed

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

No branches or pull requests

2 participants