diff --git a/Makefile b/Makefile index 4305baee..2a353188 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +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 ExpecterTest --structname ExpecterTestWithExpecter --with-expecter=True > mocks/pkg/fixtures/ExpecterTestWithExpecter.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 00000000..e61efde0 --- /dev/null +++ b/mocks/pkg/fixtures/Expecter.go @@ -0,0 +1,243 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// 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 +} + +type NewExpecterT interface { + mock.TestingT + Cleanup(func()) +} + +// NewExpecter creates a new instance of Expecter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewExpecter(t NewExpecterT) *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 e9082b47..00000000 --- a/mocks/pkg/fixtures/ExpecterTest.go +++ /dev/null @@ -1,104 +0,0 @@ -// Code generated by mockery. DO NOT EDIT. - -package mocks - -import mock "github.com/stretchr/testify/mock" - -// 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 -} - -type NewExpecterTestT interface { - mock.TestingT - Cleanup(func()) -} - -// NewExpecterTest creates a new instance of ExpecterTest. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewExpecterTest(t NewExpecterTestT) *ExpecterTest { - mock := &ExpecterTest{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/mocks/pkg/fixtures/ExpecterTestWithExpecter.go b/mocks/pkg/fixtures/ExpecterTestWithExpecter.go deleted file mode 100644 index 5c6b1a11..00000000 --- a/mocks/pkg/fixtures/ExpecterTestWithExpecter.go +++ /dev/null @@ -1,243 +0,0 @@ -// Code generated by mockery. DO NOT EDIT. - -package mocks - -import mock "github.com/stretchr/testify/mock" - -// ExpecterTestWithExpecter is an autogenerated mock type for the ExpecterTest type -type ExpecterTestWithExpecter struct { - mock.Mock -} - -type ExpecterTestWithExpecter_Expecter struct { - mock *mock.Mock -} - -func (_m *ExpecterTestWithExpecter) EXPECT() *ExpecterTestWithExpecter_Expecter { - return &ExpecterTestWithExpecter_Expecter{mock: &_m.Mock} -} - -// ManyArgsReturns provides a mock function with given fields: str, i -func (_m *ExpecterTestWithExpecter) 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 -} - -// ExpecterTestWithExpecter_ManyArgsReturns_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ManyArgsReturns' -type ExpecterTestWithExpecter_ManyArgsReturns_Call struct { - *mock.Call -} - -// ManyArgsReturns is a helper method to define mock.On call -// - str string -// - i int -func (_e *ExpecterTestWithExpecter_Expecter) ManyArgsReturns(str interface{}, i interface{}) *ExpecterTestWithExpecter_ManyArgsReturns_Call { - return &ExpecterTestWithExpecter_ManyArgsReturns_Call{Call: _e.mock.On("ManyArgsReturns", str, i)} -} - -func (_c *ExpecterTestWithExpecter_ManyArgsReturns_Call) Run(run func(str string, i int)) *ExpecterTestWithExpecter_ManyArgsReturns_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(int)) - }) - return _c -} - -func (_c *ExpecterTestWithExpecter_ManyArgsReturns_Call) Return(strs []string, err error) *ExpecterTestWithExpecter_ManyArgsReturns_Call { - _c.Call.Return(strs, err) - return _c -} - -// NoArg provides a mock function with given fields: -func (_m *ExpecterTestWithExpecter) 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 -} - -// ExpecterTestWithExpecter_NoArg_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NoArg' -type ExpecterTestWithExpecter_NoArg_Call struct { - *mock.Call -} - -// NoArg is a helper method to define mock.On call -func (_e *ExpecterTestWithExpecter_Expecter) NoArg() *ExpecterTestWithExpecter_NoArg_Call { - return &ExpecterTestWithExpecter_NoArg_Call{Call: _e.mock.On("NoArg")} -} - -func (_c *ExpecterTestWithExpecter_NoArg_Call) Run(run func()) *ExpecterTestWithExpecter_NoArg_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *ExpecterTestWithExpecter_NoArg_Call) Return(_a0 string) *ExpecterTestWithExpecter_NoArg_Call { - _c.Call.Return(_a0) - return _c -} - -// NoReturn provides a mock function with given fields: str -func (_m *ExpecterTestWithExpecter) NoReturn(str string) { - _m.Called(str) -} - -// ExpecterTestWithExpecter_NoReturn_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NoReturn' -type ExpecterTestWithExpecter_NoReturn_Call struct { - *mock.Call -} - -// NoReturn is a helper method to define mock.On call -// - str string -func (_e *ExpecterTestWithExpecter_Expecter) NoReturn(str interface{}) *ExpecterTestWithExpecter_NoReturn_Call { - return &ExpecterTestWithExpecter_NoReturn_Call{Call: _e.mock.On("NoReturn", str)} -} - -func (_c *ExpecterTestWithExpecter_NoReturn_Call) Run(run func(str string)) *ExpecterTestWithExpecter_NoReturn_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} - -func (_c *ExpecterTestWithExpecter_NoReturn_Call) Return() *ExpecterTestWithExpecter_NoReturn_Call { - _c.Call.Return() - return _c -} - -// Variadic provides a mock function with given fields: ints -func (_m *ExpecterTestWithExpecter) 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 -} - -// ExpecterTestWithExpecter_Variadic_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Variadic' -type ExpecterTestWithExpecter_Variadic_Call struct { - *mock.Call -} - -// Variadic is a helper method to define mock.On call -// - ints ...int -func (_e *ExpecterTestWithExpecter_Expecter) Variadic(ints ...interface{}) *ExpecterTestWithExpecter_Variadic_Call { - return &ExpecterTestWithExpecter_Variadic_Call{Call: _e.mock.On("Variadic", - append([]interface{}{}, ints...)...)} -} - -func (_c *ExpecterTestWithExpecter_Variadic_Call) Run(run func(ints ...int)) *ExpecterTestWithExpecter_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 *ExpecterTestWithExpecter_Variadic_Call) Return(_a0 error) *ExpecterTestWithExpecter_Variadic_Call { - _c.Call.Return(_a0) - return _c -} - -// VariadicMany provides a mock function with given fields: i, a, intfs -func (_m *ExpecterTestWithExpecter) 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 -} - -// ExpecterTestWithExpecter_VariadicMany_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'VariadicMany' -type ExpecterTestWithExpecter_VariadicMany_Call struct { - *mock.Call -} - -// VariadicMany is a helper method to define mock.On call -// - i int -// - a string -// - intfs ...interface{} -func (_e *ExpecterTestWithExpecter_Expecter) VariadicMany(i interface{}, a interface{}, intfs ...interface{}) *ExpecterTestWithExpecter_VariadicMany_Call { - return &ExpecterTestWithExpecter_VariadicMany_Call{Call: _e.mock.On("VariadicMany", - append([]interface{}{i, a}, intfs...)...)} -} - -func (_c *ExpecterTestWithExpecter_VariadicMany_Call) Run(run func(i int, a string, intfs ...interface{})) *ExpecterTestWithExpecter_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 *ExpecterTestWithExpecter_VariadicMany_Call) Return(_a0 error) *ExpecterTestWithExpecter_VariadicMany_Call { - _c.Call.Return(_a0) - return _c -} - -type NewExpecterTestWithExpecterT interface { - mock.TestingT - Cleanup(func()) -} - -// NewExpecterTestWithExpecter creates a new instance of ExpecterTestWithExpecter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewExpecterTestWithExpecter(t NewExpecterTestWithExpecterT) *ExpecterTestWithExpecter { - mock := &ExpecterTestWithExpecter{} - 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 d9027c5f..23ba8808 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 a12a2a77..00000000 --- a/pkg/fixtures/mocks/expecter.go +++ /dev/null @@ -1,245 +0,0 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. - -package mocks - -import ( - "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 -} - -type NewExpecterTestT interface { - mock.TestingT - Cleanup(func()) -} - -// NewExpecterTest creates a new instance of ExpecterTest. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewExpecterTest(t NewExpecterTestT) *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 1e192641..abfc4524 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 2d5190f0..c5ca040e 100644 --- a/pkg/generator_test.go +++ b/pkg/generator_test.go @@ -252,17 +252,251 @@ func NewRequester(t NewRequesterT) *Requester { } func (s *GeneratorSuite) TestGeneratorExpecterComplete() { - expectedBytes, err := ioutil.ReadFile(getMocksPath("ExpecterTestWithExpecter.go")) - require.NoError(s.T(), err) - expected := string(expectedBytes) - expected = expected[strings.Index(expected, "// ExpecterTestWithExpecter 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 +} + +type NewExpecterT interface { + mock.TestingT + Cleanup(func()) +} + +// NewExpecter creates a new instance of Expecter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewExpecter(t NewExpecterT) *Expecter { + mock := &Expecter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} +` cfg := config.Config{ - StructName: "ExpecterTestWithExpecter", + StructName: "Expecter", WithExpecter: true, UnrollVariadic: true, } - s.checkGenerationWithConfig(testFile, "ExpecterTest", cfg, expected) + s.checkGenerationWithConfig("expecter.go", "Expecter", cfg, expected) } func (s *GeneratorSuite) TestGeneratorExpecterFailsWithoutUnrolledVariadic() { @@ -270,7 +504,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")