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

Support "exclude" in package config #709

Merged
merged 2 commits into from
Sep 24, 2023
Merged

Support "exclude" in package config #709

merged 2 commits into from
Sep 24, 2023

Conversation

kpaulisse
Copy link
Contributor

@kpaulisse kpaulisse commented Sep 21, 2023

Description

This PR recognizes the "exclude" directive in a package configuration. The following configuration snippet now excludes the "client/common" directory (and everything therein):

---
with-expecter: False
filename: "{{.InterfaceName}}.go"
include-auto-generated: false
mockname: "{{.InterfaceName}}"
outpkg: "mocks"
packages:
  github.com/organization/reponame/core/clients:
    config:
      all: true
      dir: mocks/{{ .InterfaceDirRelative }}
      recursive: true
      exclude:
        - common

This is motivated by errors we get from mockery arising from imports in github.com/organization/reponame/core/clients/common. We want to be able to use the recursive functionality (since we have a bunch of different clients) but skip the one directory that has only test helpers and no interfaces to mock. The "exclude" feature lets us do that in the old style configuration format, but there was no implementation of this in the new packages format.

Fixes #708

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Version of Golang used when building/testing:

  • 1.11
  • 1.12
  • 1.13
  • 1.14
  • 1.15
  • 1.16
  • 1.17
  • 1.18
  • 1.19
  • 1.20

How Has This Been Tested?

Added a unit test to the existing table driven test that exercises the revised functionality. (It may look a bit strange to add a stanza where the input YAML equals the output YAML. However without the change in the code, the output YAML would be auto-populated with the information about subpkg3).

Tested in our use case, as running mockery against our configuration (represented by the YAML snippet above) correctly logs that it is skipping the subpackage and exits without error.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Regarding documentation updates: exclude is in the table of deprecated parameters for v3. I am hoping that this use case allows it to be brought back.

Copy link
Collaborator

@LandonTClipp LandonTClipp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one change but otherwise this is good to go. Please address that and we can get this merged.

p := pathlib.NewPath(subPkg)
relativePath, err := p.RelativeToStr(pkgPath)
if err != nil {
return fmt.Errorf("failed to get path for %s relative to %s: %w", subPkg, pkgPath, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1407ff8

exclude:
- subpkg3
`,
wantCfgMap: `dir: foobar
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand about the funkiness of the test. That's okay, people can come back to this PR if they're confused :)

@codecov
Copy link

codecov bot commented Sep 22, 2023

Codecov Report

Patch coverage: 66.66667% and project coverage change: -0.03209% ⚠️

Comparison is base (72c48ed) 74.89121% compared to head (1407ff8) 74.85912%.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master        #709         +/-   ##
===================================================
- Coverage   74.89121%   74.85912%   -0.03209%     
===================================================
  Files              9           9                 
  Lines           2298        2307          +9     
===================================================
+ Hits            1721        1727          +6     
- Misses           440         442          +2     
- Partials         137         138          +1     
Files Changed Coverage Δ
pkg/config/config.go 67.50449% <66.66667%> (-0.01376%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@LandonTClipp LandonTClipp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, will merge when tests pass.

@LandonTClipp LandonTClipp merged commit a4a945a into vektra:master Sep 24, 2023
4 of 5 checks passed
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.

Support "exclude" in packages config
2 participants