Skip to content

Commit

Permalink
simulate problem
Browse files Browse the repository at this point in the history
  • Loading branch information
RangelReale committed Sep 23, 2023
1 parent 72c48ed commit 5c62b62
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/fixtures/example_project/fiz/fiz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fiz

import (
"github.com/vektra/mockery/v2/pkg/fixtures/example_project/fiz/fizi/fiz1"
"github.com/vektra/mockery/v2/pkg/fixtures/example_project/fiz/fizi/fiz2"
)

type Fiz interface {
FA(f fiz1.Fiz1)
FB(f fiz2.Fiz2)
}
5 changes: 5 additions & 0 deletions pkg/fixtures/example_project/fiz/fizi/fiz1/fiz1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package fiz1

import "github.com/vektra/mockery/v2/pkg/fixtures/example_project/fiz/fizi/internal"

type Fiz1 = internal.FizI1
5 changes: 5 additions & 0 deletions pkg/fixtures/example_project/fiz/fizi/fiz2/fiz2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package fiz2

import "github.com/vektra/mockery/v2/pkg/fixtures/example_project/fiz/fizi/internal"

type Fiz2 = internal.FizI2
9 changes: 9 additions & 0 deletions pkg/fixtures/example_project/fiz/fizi/internal/fizi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package internal

type FizI1 struct {
A int
}

type FizI2 struct {
B string
}
36 changes: 36 additions & 0 deletions pkg/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,42 @@ func (s *GeneratorSuite) TestReplaceTypePackage() {
})
}

func (s *GeneratorSuite) TestReplaceTypePackageMultiplePrologue() {
expected := `package mocks
import fiz "github.com/vektra/mockery/v2/pkg/fixtures/example_project/fiz"
import fiz1 "github.com/vektra/mockery/v2/pkg/fixtures/example_project/fiz/fiz1"
import fiz2 "github.com/vektra/mockery/v2/pkg/fixtures/example_project/fiz/fiz2"
import mock "github.com/stretchr/testify/mock"
`
generator := NewGenerator(
s.ctx,
GeneratorConfig{InPackage: false, ReplaceType: []string{
"github.com/vektra/mockery/v2/pkg/fixtures/example_project/fiz/fizi/internal.FizI1=fiz1:github.com/vektra/mockery/v2/pkg/fixtures/example_project/fiz/fiz1.Fiz1",
"github.com/vektra/mockery/v2/pkg/fixtures/example_project/fiz/fizi/internal.FizI2=fiz2:github.com/vektra/mockery/v2/pkg/fixtures/example_project/fiz/fiz2.Fiz2",
}},
s.getInterfaceFromFile("example_project/fiz/fiz.go", "Fiz"),
pkg,
)

s.checkPrologueGeneration(generator, expected)
}

func (s *GeneratorSuite) TestReplaceTypePackageMultiple() {
cfg := GeneratorConfig{InPackage: false, ReplaceType: []string{
"github.com/vektra/mockery/v2/pkg/fixtures/example_project/fiz/fizi/internal.FizI1=fiz1:github.com/vektra/mockery/v2/pkg/fixtures/example_project/fiz/fiz1.Fiz1",
"github.com/vektra/mockery/v2/pkg/fixtures/example_project/fiz/fizi/internal.FizI2=fiz2:github.com/vektra/mockery/v2/pkg/fixtures/example_project/fiz/fiz2.Fiz2",
}}

s.checkGenerationRegexWithConfig("example_project/fiz/fiz.go", "Fiz", cfg, []regexpExpected{
// func (_m *Foo) GetBaz() (*baz.Baz, error)
{true, regexp.MustCompile(`func \([^\)]+\) FA\(\) \(\*fiz1\.Fiz1`)},
// func (_m *Foo) GetBaz() (*foo.InternalBaz, error)
{false, regexp.MustCompile(`func \([^\)]+\) FB\(\) \(\*fiz2\.Fiz2`)},
})
}

func (s *GeneratorSuite) TestGenericGenerator() {
s.checkGeneration("generic.go", "RequesterGenerics", false, "", "")
}
Expand Down

0 comments on commit 5c62b62

Please sign in to comment.