From 6a48ff338473a0e498acf985058267888c8b5138 Mon Sep 17 00:00:00 2001 From: Kevin Paulisse Date: Thu, 21 Sep 2023 14:59:11 -0500 Subject: [PATCH 1/2] Support "exclude" in package config --- pkg/config/config.go | 12 ++++++++++++ pkg/config/config_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) 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 `, }, } From 1407ff88ea428c24756ba122d01fc79392977b7e Mon Sep 17 00:00:00 2001 From: Kevin Paulisse Date: Fri, 22 Sep 2023 17:15:46 -0500 Subject: [PATCH 2/2] Update error to use NewStackErrf --- pkg/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 964d02de..86439929 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -599,7 +599,7 @@ func (c *Config) discoverRecursivePackages(ctx context.Context) error { 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) + 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")