Skip to content

Commit

Permalink
Merge pull request #709 from kpaulisse/kpaulisse-packages-excludes
Browse files Browse the repository at this point in the history
Support "exclude" in package config
  • Loading branch information
LandonTClipp authored Sep 24, 2023
2 parents 72c48ed + 1407ff8 commit a4a945a
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 stackerr.NewStackErrf(err, "failed to get path for %s relative to %s", subPkg, pkgPath)
}
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 a4a945a

Please sign in to comment.