diff --git a/pkg/generator.go b/pkg/generator.go index 8d7afbf6..62b3a9e9 100644 --- a/pkg/generator.go +++ b/pkg/generator.go @@ -61,6 +61,7 @@ type GeneratorConfig struct { StructName string UnrollVariadic bool WithExpecter bool + ReplaceType []string } // Generator is responsible for generating the string containing @@ -206,7 +207,7 @@ func (g *Generator) addPackageImportWithName(ctx context.Context, path, name str } func (g *Generator) parseReplaceTypes(ctx context.Context) { - for _, replace := range g.Config.ReplaceType { + for _, replace := range g.config.ReplaceType { r := strings.SplitN(replace, "=", 2) if len(r) != 2 { log := zerolog.Ctx(ctx) diff --git a/pkg/generator_test.go b/pkg/generator_test.go index 26a1b162..0685be4c 100644 --- a/pkg/generator_test.go +++ b/pkg/generator_test.go @@ -2433,7 +2433,7 @@ import mock "github.com/stretchr/testify/mock" ` generator := NewGenerator( s.ctx, - config.Config{InPackage: false, LogLevel: "debug", ReplaceType: []string{ + GeneratorConfig{InPackage: false, ReplaceType: []string{ "github.com/vektra/mockery/v2/pkg/fixtures/example_project/baz/internal/foo.InternalBaz=baz:github.com/vektra/mockery/v2/pkg/fixtures/example_project/baz.Baz", }}, s.getInterfaceFromFile("example_project/baz/foo.go", "Foo"), @@ -2504,7 +2504,7 @@ func NewFoo(t mockConstructorTestingTNewFoo) *Foo { return mock } ` - cfg := config.Config{InPackage: false, LogLevel: "debug", ReplaceType: []string{ + cfg := GeneratorConfig{InPackage: false, ReplaceType: []string{ "github.com/vektra/mockery/v2/pkg/fixtures/example_project/baz/internal/foo.InternalBaz=baz:github.com/vektra/mockery/v2/pkg/fixtures/example_project/baz.Baz", }} diff --git a/pkg/outputter.go b/pkg/outputter.go index 34b43617..036ed034 100644 --- a/pkg/outputter.go +++ b/pkg/outputter.go @@ -240,6 +240,7 @@ func (m *Outputter) Generate(ctx context.Context, iface *Interface) error { StructName: interfaceConfig.StructName, UnrollVariadic: interfaceConfig.UnrollVariadic, WithExpecter: interfaceConfig.WithExpecter, + ReplaceType: interfaceConfig.ReplaceType, } generator := NewGenerator(ctx, g, iface, "") diff --git a/pkg/walker.go b/pkg/walker.go index 29cea8fd..b214339d 100644 --- a/pkg/walker.go +++ b/pkg/walker.go @@ -118,6 +118,7 @@ type GeneratorVisitorConfig struct { StructName string UnrollVariadic bool WithExpecter bool + ReplaceType []string } type GeneratorVisitor struct { @@ -173,6 +174,7 @@ func (v *GeneratorVisitor) VisitWalk(ctx context.Context, iface *Interface) erro StructName: v.config.StructName, UnrollVariadic: v.config.UnrollVariadic, WithExpecter: v.config.WithExpecter, + ReplaceType: v.config.ReplaceType, } gen := NewGenerator(ctx, generatorConfig, iface, "")