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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,18 @@
subPkgLog := pkgLog.With().Str("sub-package", subPkg).Logger()
subPkgCtx := subPkgLog.WithContext(pkgCtx)

if len(conf.Exclude) > 0 {
p := pathlib.NewPath(subPkg)
relativePath, err := p.RelativeToStr(pkgPath)
if err != nil {
return stackerr.NewStackErrf(err, "failed to get path for %s relative to %s", subPkg, pkgPath)
}

Check warning on line 603 in pkg/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/config.go#L602-L603

Added lines #L602 - L603 were not covered by tests
if conf.ExcludePath(relativePath.String()) {
subPkgLog.Info().Msg("subpackage is excluded")
continue
}
}

subPkgLog.Debug().Msg("adding sub-package config")
if err := c.addSubPkgConfig(subPkgCtx, subPkg, pkgPath); err != nil {
subPkgLog.Err(err).Msg("failed to add sub-package config")
Expand Down
27 changes: 27 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,33 @@ packages:
recursive: true
with-expecter: false
with-expecter: false
`,
},
{
name: "test with excluded subpackage",
cfgYaml: `
with-expecter: False
dir: foobar
packages:
github.com/vektra/mockery/v2/pkg/fixtures/example_project/pkg_with_subpkgs/subpkg2:
config:
recursive: True
with-expecter: True
all: True
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 :)

packages:
github.com/vektra/mockery/v2/pkg/fixtures/example_project/pkg_with_subpkgs/subpkg2:
config:
all: true
dir: foobar
exclude:
- subpkg3
recursive: true
with-expecter: true
with-expecter: false
`,
},
}
Expand Down
Loading