Skip to content

Commit

Permalink
Support "exclude" in package config
Browse files Browse the repository at this point in the history
  • Loading branch information
kpaulisse committed Sep 21, 2023
1 parent 72c48ed commit 6a48ff3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
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 @@ func (c *Config) discoverRecursivePackages(ctx context.Context) error {
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 fmt.Errorf("failed to get path for %s relative to %s: %w", subPkg, pkgPath, err)
}

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
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

0 comments on commit 6a48ff3

Please sign in to comment.