diff --git a/pkg/config/config.go b/pkg/config/config.go index 3fd013ad..964d02de 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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) + } + 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") diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index ffe4a7b0..2e151e07 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -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 `, }, }