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 recursion should handle subpackages with their own config files #732

Open
1 of 5 tasks
devnev opened this issue Nov 15, 2023 · 0 comments
Open
1 of 5 tasks

Comments

@devnev
Copy link
Contributor

devnev commented Nov 15, 2023

Description

Split from #706

Subpackages/subdirectories may contain further mockery config files. Currently mockery recursion from a config in a parent directory will ignore these, meaning those packages/directories may have different mocks generated depending on where mockery is run from.

I'm not 100% sure I have a use-case for this, but in a larger mono-repo it would be nice to not have the entire configuration at the root of the repo so some subdirectory can customise, while still being able to run mockery across the repo. An alternative approach might be running a find -name .mockery.yaml -execdir mockery, but that still leaves the danger of someone creating mockery configs in subdirectories that cause inconsistent behaviour.

I took a quick try at implementing this but then realised that the config name is in theory variable (I think? viper gets it from somewhere)

Mockery Version

v2.33.3

Golang Version

go1.21.3

Installation Method

  • Binary Distribution
  • Docker
  • brew
  • go install
  • Other: [specify]

Steps to Reproduce

  1. go mod init github.com/something
  2. touch .mockery.yaml
  3. mkdir foo && touch foo/mockery.yaml
  4. set recursive:true for github.com/something in root .mockery.yaml
  5. set some extra setting like mockname for github.com/something/foo in foo/.mockery.yaml
  6. create an interface in a go file in the foo package
  7. run mockery in the root, notice that setting changes from the foo are ignored
  8. run mockery in the foo directory, settings from foo directory are applied

Expected Behavior

A few options:

  • Error as invalid on a subdirectory with a config
  • Stop recursion on a subdirectory with a config
  • Try to merge the encountered config into the semantics of the recursion

Actual Behavior

  • Config in subdirectory is silently ignored
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

1 participant