From f9cad3c005eb356b3cb110228a6aaf9b2ca563ec Mon Sep 17 00:00:00 2001 From: Gevrai Jodoin-Tremblay Date: Mon, 25 Apr 2022 23:26:57 -0400 Subject: [PATCH] Move generated ExpecterTest to mocks directory --- Makefile | 1 + mocks/pkg/fixtures/Expecter.go | 242 ++++++++++++++++++ mocks/pkg/fixtures/ExpecterTest.go | 103 -------- .../context/CollideWithStdLib.go | 31 +++ pkg/fixtures/{expecterTest.go => expecter.go} | 2 +- pkg/fixtures/mocks/expecter.go | 242 ------------------ pkg/fixtures/mocks/expecter_test.go | 4 +- pkg/generator_test.go | 241 ++++++++++++++++- 8 files changed, 513 insertions(+), 353 deletions(-) create mode 100644 mocks/pkg/fixtures/Expecter.go delete mode 100644 mocks/pkg/fixtures/ExpecterTest.go create mode 100644 mocks/pkg/fixtures/example_project/context/CollideWithStdLib.go rename pkg/fixtures/{expecterTest.go => expecter.go} (87%) delete mode 100755 pkg/fixtures/mocks/expecter.go diff --git a/Makefile b/Makefile index 17cf5a7e7..2a353188a 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ test: mocks mocks: $(shell find . -type f -name '*.go' -not -name '*_test.go') go run . --dir pkg/fixtures --output mocks/pkg/fixtures go run . --all=false --print --dir pkg/fixtures --name RequesterVariadic --structname RequesterVariadicOneArgument --unroll-variadic=False > mocks/pkg/fixtures/RequesterVariadicOneArgument.go + go run . --all=false --print --dir pkg/fixtures --name Expecter --with-expecter > mocks/pkg/fixtures/Expecter.go @touch mocks .PHONY: install diff --git a/mocks/pkg/fixtures/Expecter.go b/mocks/pkg/fixtures/Expecter.go new file mode 100644 index 000000000..4968274e5 --- /dev/null +++ b/mocks/pkg/fixtures/Expecter.go @@ -0,0 +1,242 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) + +// Expecter is an autogenerated mock type for the Expecter type +type Expecter struct { + mock.Mock +} + +type Expecter_Expecter struct { + mock *mock.Mock +} + +func (_m *Expecter) EXPECT() *Expecter_Expecter { + return &Expecter_Expecter{mock: &_m.Mock} +} + +// ManyArgsReturns provides a mock function with given fields: str, i +func (_m *Expecter) ManyArgsReturns(str string, i int) ([]string, error) { + ret := _m.Called(str, i) + + var r0 []string + if rf, ok := ret.Get(0).(func(string, int) []string); ok { + r0 = rf(str, i) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string, int) error); ok { + r1 = rf(str, i) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Expecter_ManyArgsReturns_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ManyArgsReturns' +type Expecter_ManyArgsReturns_Call struct { + *mock.Call +} + +// ManyArgsReturns is a helper method to define mock.On call +// - str string +// - i int +func (_e *Expecter_Expecter) ManyArgsReturns(str interface{}, i interface{}) *Expecter_ManyArgsReturns_Call { + return &Expecter_ManyArgsReturns_Call{Call: _e.mock.On("ManyArgsReturns", str, i)} +} + +func (_c *Expecter_ManyArgsReturns_Call) Run(run func(str string, i int)) *Expecter_ManyArgsReturns_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(int)) + }) + return _c +} + +func (_c *Expecter_ManyArgsReturns_Call) Return(strs []string, err error) *Expecter_ManyArgsReturns_Call { + _c.Call.Return(strs, err) + return _c +} + +// NoArg provides a mock function with given fields: +func (_m *Expecter) NoArg() string { + ret := _m.Called() + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Expecter_NoArg_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NoArg' +type Expecter_NoArg_Call struct { + *mock.Call +} + +// NoArg is a helper method to define mock.On call +func (_e *Expecter_Expecter) NoArg() *Expecter_NoArg_Call { + return &Expecter_NoArg_Call{Call: _e.mock.On("NoArg")} +} + +func (_c *Expecter_NoArg_Call) Run(run func()) *Expecter_NoArg_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Expecter_NoArg_Call) Return(_a0 string) *Expecter_NoArg_Call { + _c.Call.Return(_a0) + return _c +} + +// NoReturn provides a mock function with given fields: str +func (_m *Expecter) NoReturn(str string) { + _m.Called(str) +} + +// Expecter_NoReturn_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NoReturn' +type Expecter_NoReturn_Call struct { + *mock.Call +} + +// NoReturn is a helper method to define mock.On call +// - str string +func (_e *Expecter_Expecter) NoReturn(str interface{}) *Expecter_NoReturn_Call { + return &Expecter_NoReturn_Call{Call: _e.mock.On("NoReturn", str)} +} + +func (_c *Expecter_NoReturn_Call) Run(run func(str string)) *Expecter_NoReturn_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Expecter_NoReturn_Call) Return() *Expecter_NoReturn_Call { + _c.Call.Return() + return _c +} + +// Variadic provides a mock function with given fields: ints +func (_m *Expecter) Variadic(ints ...int) error { + _va := make([]interface{}, len(ints)) + for _i := range ints { + _va[_i] = ints[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 error + if rf, ok := ret.Get(0).(func(...int) error); ok { + r0 = rf(ints...) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Expecter_Variadic_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Variadic' +type Expecter_Variadic_Call struct { + *mock.Call +} + +// Variadic is a helper method to define mock.On call +// - ints ...int +func (_e *Expecter_Expecter) Variadic(ints ...interface{}) *Expecter_Variadic_Call { + return &Expecter_Variadic_Call{Call: _e.mock.On("Variadic", + append([]interface{}{}, ints...)...)} +} + +func (_c *Expecter_Variadic_Call) Run(run func(ints ...int)) *Expecter_Variadic_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]int, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(int) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *Expecter_Variadic_Call) Return(_a0 error) *Expecter_Variadic_Call { + _c.Call.Return(_a0) + return _c +} + +// VariadicMany provides a mock function with given fields: i, a, intfs +func (_m *Expecter) VariadicMany(i int, a string, intfs ...interface{}) error { + var _ca []interface{} + _ca = append(_ca, i, a) + _ca = append(_ca, intfs...) + ret := _m.Called(_ca...) + + var r0 error + if rf, ok := ret.Get(0).(func(int, string, ...interface{}) error); ok { + r0 = rf(i, a, intfs...) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Expecter_VariadicMany_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'VariadicMany' +type Expecter_VariadicMany_Call struct { + *mock.Call +} + +// VariadicMany is a helper method to define mock.On call +// - i int +// - a string +// - intfs ...interface{} +func (_e *Expecter_Expecter) VariadicMany(i interface{}, a interface{}, intfs ...interface{}) *Expecter_VariadicMany_Call { + return &Expecter_VariadicMany_Call{Call: _e.mock.On("VariadicMany", + append([]interface{}{i, a}, intfs...)...)} +} + +func (_c *Expecter_VariadicMany_Call) Run(run func(i int, a string, intfs ...interface{})) *Expecter_VariadicMany_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]interface{}, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(interface{}) + } + } + run(args[0].(int), args[1].(string), variadicArgs...) + }) + return _c +} + +func (_c *Expecter_VariadicMany_Call) Return(_a0 error) *Expecter_VariadicMany_Call { + _c.Call.Return(_a0) + return _c +} + +// NewExpecter creates a new instance of Expecter. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. +func NewExpecter(t testing.TB) *Expecter { + mock := &Expecter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/ExpecterTest.go b/mocks/pkg/fixtures/ExpecterTest.go deleted file mode 100644 index 57bf1829d..000000000 --- a/mocks/pkg/fixtures/ExpecterTest.go +++ /dev/null @@ -1,103 +0,0 @@ -// Code generated by mockery. DO NOT EDIT. - -package mocks - -import ( - mock "github.com/stretchr/testify/mock" - - testing "testing" -) - -// ExpecterTest is an autogenerated mock type for the ExpecterTest type -type ExpecterTest struct { - mock.Mock -} - -// ManyArgsReturns provides a mock function with given fields: str, i -func (_m *ExpecterTest) ManyArgsReturns(str string, i int) ([]string, error) { - ret := _m.Called(str, i) - - var r0 []string - if rf, ok := ret.Get(0).(func(string, int) []string); ok { - r0 = rf(str, i) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(string, int) error); ok { - r1 = rf(str, i) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// NoArg provides a mock function with given fields: -func (_m *ExpecterTest) NoArg() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// NoReturn provides a mock function with given fields: str -func (_m *ExpecterTest) NoReturn(str string) { - _m.Called(str) -} - -// Variadic provides a mock function with given fields: ints -func (_m *ExpecterTest) Variadic(ints ...int) error { - _va := make([]interface{}, len(ints)) - for _i := range ints { - _va[_i] = ints[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 error - if rf, ok := ret.Get(0).(func(...int) error); ok { - r0 = rf(ints...) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// VariadicMany provides a mock function with given fields: i, a, intfs -func (_m *ExpecterTest) VariadicMany(i int, a string, intfs ...interface{}) error { - var _ca []interface{} - _ca = append(_ca, i, a) - _ca = append(_ca, intfs...) - ret := _m.Called(_ca...) - - var r0 error - if rf, ok := ret.Get(0).(func(int, string, ...interface{}) error); ok { - r0 = rf(i, a, intfs...) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// NewExpecterTest creates a new instance of ExpecterTest. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewExpecterTest(t testing.TB) *ExpecterTest { - mock := &ExpecterTest{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/mocks/pkg/fixtures/example_project/context/CollideWithStdLib.go b/mocks/pkg/fixtures/example_project/context/CollideWithStdLib.go new file mode 100644 index 000000000..7e4cf1c07 --- /dev/null +++ b/mocks/pkg/fixtures/example_project/context/CollideWithStdLib.go @@ -0,0 +1,31 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + + testing "testing" +) + +// CollideWithStdLib is an autogenerated mock type for the CollideWithStdLib type +type CollideWithStdLib struct { + mock.Mock +} + +// NewClient provides a mock function with given fields: ctx +func (_m *CollideWithStdLib) NewClient(ctx context.Context) { + _m.Called(ctx) +} + +// NewCollideWithStdLib creates a new instance of CollideWithStdLib. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. +func NewCollideWithStdLib(t testing.TB) *CollideWithStdLib { + mock := &CollideWithStdLib{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/fixtures/expecterTest.go b/pkg/fixtures/expecter.go similarity index 87% rename from pkg/fixtures/expecterTest.go rename to pkg/fixtures/expecter.go index d9027c5f0..23ba88086 100644 --- a/pkg/fixtures/expecterTest.go +++ b/pkg/fixtures/expecter.go @@ -1,6 +1,6 @@ package test -type ExpecterTest interface { +type Expecter interface { NoArg() string NoReturn(str string) ManyArgsReturns(str string, i int) (strs []string, err error) diff --git a/pkg/fixtures/mocks/expecter.go b/pkg/fixtures/mocks/expecter.go deleted file mode 100755 index 36b6971b6..000000000 --- a/pkg/fixtures/mocks/expecter.go +++ /dev/null @@ -1,242 +0,0 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. - -package mocks - -import ( - "testing" - - "github.com/stretchr/testify/mock" -) - -// ExpecterTest is an autogenerated mock type for the ExpecterTest type -type ExpecterTest struct { - mock.Mock -} - -type ExpecterTest_Expecter struct { - mock *mock.Mock -} - -func (_m *ExpecterTest) EXPECT() *ExpecterTest_Expecter { - return &ExpecterTest_Expecter{mock: &_m.Mock} -} - -// ManyArgsReturns provides a mock function with given fields: str, i -func (_m *ExpecterTest) ManyArgsReturns(str string, i int) ([]string, error) { - ret := _m.Called(str, i) - - var r0 []string - if rf, ok := ret.Get(0).(func(string, int) []string); ok { - r0 = rf(str, i) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(string, int) error); ok { - r1 = rf(str, i) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// ExpecterTest_ManyArgsReturns_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ManyArgsReturns' -type ExpecterTest_ManyArgsReturns_Call struct { - *mock.Call -} - -// ManyArgsReturns is a helper method to define mock.On call -// - str string -// - i int -func (_e *ExpecterTest_Expecter) ManyArgsReturns(str interface{}, i interface{}) *ExpecterTest_ManyArgsReturns_Call { - return &ExpecterTest_ManyArgsReturns_Call{Call: _e.mock.On("ManyArgsReturns", str, i)} -} - -func (_c *ExpecterTest_ManyArgsReturns_Call) Run(run func(str string, i int)) *ExpecterTest_ManyArgsReturns_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(int)) - }) - return _c -} - -func (_c *ExpecterTest_ManyArgsReturns_Call) Return(strs []string, err error) *ExpecterTest_ManyArgsReturns_Call { - _c.Call.Return(strs, err) - return _c -} - -// NoArg provides a mock function with given fields: -func (_m *ExpecterTest) NoArg() string { - ret := _m.Called() - - var r0 string - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -// ExpecterTest_NoArg_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NoArg' -type ExpecterTest_NoArg_Call struct { - *mock.Call -} - -// NoArg is a helper method to define mock.On call -func (_e *ExpecterTest_Expecter) NoArg() *ExpecterTest_NoArg_Call { - return &ExpecterTest_NoArg_Call{Call: _e.mock.On("NoArg")} -} - -func (_c *ExpecterTest_NoArg_Call) Run(run func()) *ExpecterTest_NoArg_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *ExpecterTest_NoArg_Call) Return(_a0 string) *ExpecterTest_NoArg_Call { - _c.Call.Return(_a0) - return _c -} - -// NoReturn provides a mock function with given fields: str -func (_m *ExpecterTest) NoReturn(str string) { - _m.Called(str) -} - -// ExpecterTest_NoReturn_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NoReturn' -type ExpecterTest_NoReturn_Call struct { - *mock.Call -} - -// NoReturn is a helper method to define mock.On call -// - str string -func (_e *ExpecterTest_Expecter) NoReturn(str interface{}) *ExpecterTest_NoReturn_Call { - return &ExpecterTest_NoReturn_Call{Call: _e.mock.On("NoReturn", str)} -} - -func (_c *ExpecterTest_NoReturn_Call) Run(run func(str string)) *ExpecterTest_NoReturn_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} - -func (_c *ExpecterTest_NoReturn_Call) Return() *ExpecterTest_NoReturn_Call { - _c.Call.Return() - return _c -} - -// Variadic provides a mock function with given fields: ints -func (_m *ExpecterTest) Variadic(ints ...int) error { - _va := make([]interface{}, len(ints)) - for _i := range ints { - _va[_i] = ints[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 error - if rf, ok := ret.Get(0).(func(...int) error); ok { - r0 = rf(ints...) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// ExpecterTest_Variadic_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Variadic' -type ExpecterTest_Variadic_Call struct { - *mock.Call -} - -// Variadic is a helper method to define mock.On call -// - ints ...int -func (_e *ExpecterTest_Expecter) Variadic(ints ...interface{}) *ExpecterTest_Variadic_Call { - return &ExpecterTest_Variadic_Call{Call: _e.mock.On("Variadic", - append([]interface{}{}, ints...)...)} -} - -func (_c *ExpecterTest_Variadic_Call) Run(run func(ints ...int)) *ExpecterTest_Variadic_Call { - _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]int, len(args)-0) - for i, a := range args[0:] { - if a != nil { - variadicArgs[i] = a.(int) - } - } - run(variadicArgs...) - }) - return _c -} - -func (_c *ExpecterTest_Variadic_Call) Return(_a0 error) *ExpecterTest_Variadic_Call { - _c.Call.Return(_a0) - return _c -} - -// VariadicMany provides a mock function with given fields: i, a, intfs -func (_m *ExpecterTest) VariadicMany(i int, a string, intfs ...interface{}) error { - var _ca []interface{} - _ca = append(_ca, i, a) - _ca = append(_ca, intfs...) - ret := _m.Called(_ca...) - - var r0 error - if rf, ok := ret.Get(0).(func(int, string, ...interface{}) error); ok { - r0 = rf(i, a, intfs...) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// ExpecterTest_VariadicMany_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'VariadicMany' -type ExpecterTest_VariadicMany_Call struct { - *mock.Call -} - -// VariadicMany is a helper method to define mock.On call -// - i int -// - a string -// - intfs ...interface{} -func (_e *ExpecterTest_Expecter) VariadicMany(i interface{}, a interface{}, intfs ...interface{}) *ExpecterTest_VariadicMany_Call { - return &ExpecterTest_VariadicMany_Call{Call: _e.mock.On("VariadicMany", - append([]interface{}{i, a}, intfs...)...)} -} - -func (_c *ExpecterTest_VariadicMany_Call) Run(run func(i int, a string, intfs ...interface{})) *ExpecterTest_VariadicMany_Call { - _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]interface{}, len(args)-2) - for i, a := range args[2:] { - if a != nil { - variadicArgs[i] = a.(interface{}) - } - } - run(args[0].(int), args[1].(string), variadicArgs...) - }) - return _c -} - -func (_c *ExpecterTest_VariadicMany_Call) Return(_a0 error) *ExpecterTest_VariadicMany_Call { - _c.Call.Return(_a0) - return _c -} - -// NewExpecterTest creates a new instance of ExpecterTest. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewExpecterTest(t testing.TB) *ExpecterTest { - mock := &ExpecterTest{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/fixtures/mocks/expecter_test.go b/pkg/fixtures/mocks/expecter_test.go index 1e192641e..abfc45248 100644 --- a/pkg/fixtures/mocks/expecter_test.go +++ b/pkg/fixtures/mocks/expecter_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + mocks "github.com/vektra/mockery/v2/mocks/pkg/fixtures" ) var ( @@ -17,7 +18,8 @@ var ( // Test that the generated code for ExpecterTest interface is usable func TestExpecter(t *testing.T) { - expMock := &ExpecterTest{} + + expMock := mocks.Expecter{} t.Run("NoArg", func(t *testing.T) { var runCalled bool diff --git a/pkg/generator_test.go b/pkg/generator_test.go index ed694622e..d29220ba6 100644 --- a/pkg/generator_test.go +++ b/pkg/generator_test.go @@ -242,16 +242,245 @@ func NewRequester(t testing.TB) *Requester { } func (s *GeneratorSuite) TestGeneratorExpecterComplete() { - expectedBytes, err := ioutil.ReadFile(getFixturePath("mocks", "expecter.go")) - s.NoError(err) - expected := string(expectedBytes) - expected = expected[strings.Index(expected, "// ExpecterTest is"):] + expected := `// Expecter is an autogenerated mock type for the Expecter type +type Expecter struct { + mock.Mock +} + +type Expecter_Expecter struct { + mock *mock.Mock +} + +func (_m *Expecter) EXPECT() *Expecter_Expecter { + return &Expecter_Expecter{mock: &_m.Mock} +} + +// ManyArgsReturns provides a mock function with given fields: str, i +func (_m *Expecter) ManyArgsReturns(str string, i int) ([]string, error) { + ret := _m.Called(str, i) + + var r0 []string + if rf, ok := ret.Get(0).(func(string, int) []string); ok { + r0 = rf(str, i) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string, int) error); ok { + r1 = rf(str, i) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Expecter_ManyArgsReturns_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ManyArgsReturns' +type Expecter_ManyArgsReturns_Call struct { + *mock.Call +} + +// ManyArgsReturns is a helper method to define mock.On call +// - str string +// - i int +func (_e *Expecter_Expecter) ManyArgsReturns(str interface{}, i interface{}) *Expecter_ManyArgsReturns_Call { + return &Expecter_ManyArgsReturns_Call{Call: _e.mock.On("ManyArgsReturns", str, i)} +} + +func (_c *Expecter_ManyArgsReturns_Call) Run(run func(str string, i int)) *Expecter_ManyArgsReturns_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(int)) + }) + return _c +} + +func (_c *Expecter_ManyArgsReturns_Call) Return(strs []string, err error) *Expecter_ManyArgsReturns_Call { + _c.Call.Return(strs, err) + return _c +} + +// NoArg provides a mock function with given fields: +func (_m *Expecter) NoArg() string { + ret := _m.Called() + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Expecter_NoArg_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NoArg' +type Expecter_NoArg_Call struct { + *mock.Call +} + +// NoArg is a helper method to define mock.On call +func (_e *Expecter_Expecter) NoArg() *Expecter_NoArg_Call { + return &Expecter_NoArg_Call{Call: _e.mock.On("NoArg")} +} + +func (_c *Expecter_NoArg_Call) Run(run func()) *Expecter_NoArg_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Expecter_NoArg_Call) Return(_a0 string) *Expecter_NoArg_Call { + _c.Call.Return(_a0) + return _c +} + +// NoReturn provides a mock function with given fields: str +func (_m *Expecter) NoReturn(str string) { + _m.Called(str) +} + +// Expecter_NoReturn_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NoReturn' +type Expecter_NoReturn_Call struct { + *mock.Call +} + +// NoReturn is a helper method to define mock.On call +// - str string +func (_e *Expecter_Expecter) NoReturn(str interface{}) *Expecter_NoReturn_Call { + return &Expecter_NoReturn_Call{Call: _e.mock.On("NoReturn", str)} +} + +func (_c *Expecter_NoReturn_Call) Run(run func(str string)) *Expecter_NoReturn_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Expecter_NoReturn_Call) Return() *Expecter_NoReturn_Call { + _c.Call.Return() + return _c +} + +// Variadic provides a mock function with given fields: ints +func (_m *Expecter) Variadic(ints ...int) error { + _va := make([]interface{}, len(ints)) + for _i := range ints { + _va[_i] = ints[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 error + if rf, ok := ret.Get(0).(func(...int) error); ok { + r0 = rf(ints...) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Expecter_Variadic_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Variadic' +type Expecter_Variadic_Call struct { + *mock.Call +} + +// Variadic is a helper method to define mock.On call +// - ints ...int +func (_e *Expecter_Expecter) Variadic(ints ...interface{}) *Expecter_Variadic_Call { + return &Expecter_Variadic_Call{Call: _e.mock.On("Variadic", + append([]interface{}{}, ints...)...)} +} + +func (_c *Expecter_Variadic_Call) Run(run func(ints ...int)) *Expecter_Variadic_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]int, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(int) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *Expecter_Variadic_Call) Return(_a0 error) *Expecter_Variadic_Call { + _c.Call.Return(_a0) + return _c +} + +// VariadicMany provides a mock function with given fields: i, a, intfs +func (_m *Expecter) VariadicMany(i int, a string, intfs ...interface{}) error { + var _ca []interface{} + _ca = append(_ca, i, a) + _ca = append(_ca, intfs...) + ret := _m.Called(_ca...) + + var r0 error + if rf, ok := ret.Get(0).(func(int, string, ...interface{}) error); ok { + r0 = rf(i, a, intfs...) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Expecter_VariadicMany_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'VariadicMany' +type Expecter_VariadicMany_Call struct { + *mock.Call +} + +// VariadicMany is a helper method to define mock.On call +// - i int +// - a string +// - intfs ...interface{} +func (_e *Expecter_Expecter) VariadicMany(i interface{}, a interface{}, intfs ...interface{}) *Expecter_VariadicMany_Call { + return &Expecter_VariadicMany_Call{Call: _e.mock.On("VariadicMany", + append([]interface{}{i, a}, intfs...)...)} +} + +func (_c *Expecter_VariadicMany_Call) Run(run func(i int, a string, intfs ...interface{})) *Expecter_VariadicMany_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]interface{}, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(interface{}) + } + } + run(args[0].(int), args[1].(string), variadicArgs...) + }) + return _c +} + +func (_c *Expecter_VariadicMany_Call) Return(_a0 error) *Expecter_VariadicMany_Call { + _c.Call.Return(_a0) + return _c +} + +// NewExpecter creates a new instance of Expecter. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. +func NewExpecter(t testing.TB) *Expecter { + mock := &Expecter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} +` cfg := config.Config{ WithExpecter: true, UnrollVariadic: true, } - s.checkGenerationWithConfig(testFile, "ExpecterTest", cfg, expected) + s.checkGenerationWithConfig("expecter.go", "Expecter", cfg, expected) } func (s *GeneratorSuite) TestGeneratorExpecterFailsWithoutUnrolledVariadic() { @@ -259,7 +488,7 @@ func (s *GeneratorSuite) TestGeneratorExpecterFailsWithoutUnrolledVariadic() { WithExpecter: true, UnrollVariadic: false, } - gen := s.getGeneratorWithConfig(testFile, "ExpecterTest", cfg) + gen := s.getGeneratorWithConfig("expecter.go", "Expecter", cfg) err := gen.Generate(s.ctx) s.Error(err) s.Contains(err.Error(), "cannot generate a valid expecter for variadic method with unroll-variadic=false")