diff --git a/.mockery.yml b/.mockery.yml index c3cde5e7..ae8b4256 100644 --- a/.mockery.yml +++ b/.mockery.yml @@ -14,7 +14,6 @@ packages: interfaces: TypesPackage: github.com/vektra/mockery/v3/internal/fixtures: - interfaces: RequesterVariadic: configs: - mockname: MockRequesterVariadicOneArgument diff --git a/internal/cmd/mockery.go b/internal/cmd/mockery.go index 9cf7f719..6714d148 100644 --- a/internal/cmd/mockery.go +++ b/internal/cmd/mockery.go @@ -164,7 +164,7 @@ type InterfaceCollection struct { srcPkgPath string outFilePath *pathlib.Path srcPkg *packages.Package - pkgName string + outPkgName string interfaces []*pkg.Interface } @@ -172,12 +172,13 @@ func NewInterfaceCollection( srcPkgPath string, outFilePath *pathlib.Path, srcPkg *packages.Package, - pkgName string, + outPkgName string, ) *InterfaceCollection { return &InterfaceCollection{ srcPkgPath: srcPkgPath, outFilePath: outFilePath, srcPkg: srcPkg, + outPkgName: outPkgName, interfaces: make([]*pkg.Interface, 0), } } @@ -185,11 +186,11 @@ func NewInterfaceCollection( func (i *InterfaceCollection) Append(ctx context.Context, iface *pkg.Interface) error { log := zerolog.Ctx(ctx).With(). Str(logging.LogKeyInterface, iface.Name). - Str(logging.LogKeyPackageName, iface.Pkg.Name). + Str("source-pkgname", iface.Pkg.Name). Str(logging.LogKeyPackagePath, iface.Pkg.PkgPath). Str("expected-package-path", i.srcPkgPath).Logger() if iface.Pkg.PkgPath != i.srcPkgPath { - msg := "cannot mix interfaces from different packages in the same file." + msg := "cannot mix interfaces from different packages in the same file" log.Error().Msg(msg) return errors.New(msg) } @@ -198,9 +199,9 @@ func (i *InterfaceCollection) Append(ctx context.Context, iface *pkg.Interface) log.Error().Msg(msg) return errors.New(msg) } - if i.pkgName != iface.Config.PkgName { + if i.outPkgName != iface.Config.PkgName { msg := "all mocks in an output file must have the same pkgname" - log.Error().Str("expected-pkgname", i.pkgName).Str("interface-pkgname", iface.Config.PkgName).Msg(msg) + log.Error().Str("output-pkgname", i.outPkgName).Str("interface-pkgname", iface.Config.PkgName).Msg(msg) return errors.New(msg) } i.interfaces = append(i.interfaces, iface) @@ -256,7 +257,7 @@ func (r *RootApp) Run() error { ifaceLog := log. With(). Str(logging.LogKeyInterface, iface.Name). - Str(logging.LogKeyQualifiedName, iface.Pkg.Types.Path()). + Str(logging.LogKeyPackagePath, iface.Pkg.Types.Path()). Logger() ifaceCtx := ifaceLog.WithContext(ctx) @@ -287,10 +288,10 @@ func (r *RootApp) Run() error { iface.Pkg.PkgPath, pathlib.NewPath(ifaceConfig.Dir).Join(ifaceConfig.FileName), iface.Pkg, - iface.Config.PkgName, + ifaceConfig.PkgName, ) } - mockFileToInterfaces[filePath].Append( + if err := mockFileToInterfaces[filePath].Append( ctx, pkg.NewInterface( iface.Name, @@ -298,7 +299,9 @@ func (r *RootApp) Run() error { iface.File, iface.Pkg, ifaceConfig), - ) + ); err != nil { + return err + } } } @@ -320,7 +323,8 @@ func (r *RootApp) Run() error { interfacesInFile.outFilePath.Parent(), packageConfig.Template, pkg.Formatter(r.Config.Formatter), - interfacesInFile.pkgName, + packageConfig, + interfacesInFile.outPkgName, ) if err != nil { return err diff --git a/internal/fixtures/mocks_test.go b/internal/fixtures/mocks_test.go index d6519153..eef6427e 100644 --- a/internal/fixtures/mocks_test.go +++ b/internal/fixtures/mocks_test.go @@ -849,312 +849,6 @@ func (_c *MockBlank_Create_Call) RunAndReturn(run func(x interface{})error) *Moc return _c } -// NewMockExpecterAndRolledVariadic creates a new instance of MockExpecterAndRolledVariadic. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockExpecterAndRolledVariadic (t interface { - mock.TestingT - Cleanup(func()) -}) *MockExpecterAndRolledVariadic { - mock := &MockExpecterAndRolledVariadic{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} - - -// MockExpecterAndRolledVariadic is an autogenerated mock type for the Expecter type -type MockExpecterAndRolledVariadic struct { - mock.Mock -} - -type MockExpecterAndRolledVariadic_Expecter struct { - mock *mock.Mock -} - -func (_m *MockExpecterAndRolledVariadic) EXPECT() *MockExpecterAndRolledVariadic_Expecter { - return &MockExpecterAndRolledVariadic_Expecter{mock: &_m.Mock} -} - - - -// ManyArgsReturns provides a mock function for the type MockExpecterAndRolledVariadic -func (_mock *MockExpecterAndRolledVariadic) ManyArgsReturns(str string, i int) ([]string, error) { - ret := _mock.Called(str, i) - - if len(ret) == 0 { - panic("no return value specified for ManyArgsReturns") - } - - - var r0 []string - var r1 error - if returnFunc, ok := ret.Get(0).(func(string, int) ([]string, error)); ok { - return returnFunc(str, i) - } - if returnFunc, ok := ret.Get(0).(func(string, int) []string); ok { - r0 = returnFunc(str, i) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } - } - if returnFunc, ok := ret.Get(1).(func(string, int) error); ok { - r1 = returnFunc(str, i) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - - - -// MockExpecterAndRolledVariadic_ManyArgsReturns_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ManyArgsReturns' -type MockExpecterAndRolledVariadic_ManyArgsReturns_Call struct { - *mock.Call -} - - - -// ManyArgsReturns is a helper method to define mock.On call -// - str -// - i -func (_e *MockExpecterAndRolledVariadic_Expecter) ManyArgsReturns(str interface{}, i interface{}, ) *MockExpecterAndRolledVariadic_ManyArgsReturns_Call { - return &MockExpecterAndRolledVariadic_ManyArgsReturns_Call{Call: _e.mock.On("ManyArgsReturns",str,i, )} -} - -func (_c *MockExpecterAndRolledVariadic_ManyArgsReturns_Call) Run(run func(str string, i int)) *MockExpecterAndRolledVariadic_ManyArgsReturns_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string),args[1].(int),) - }) - return _c -} - -func (_c *MockExpecterAndRolledVariadic_ManyArgsReturns_Call) Return(strs []string, err error) *MockExpecterAndRolledVariadic_ManyArgsReturns_Call { - _c.Call.Return(strs, err) - return _c -} - -func (_c *MockExpecterAndRolledVariadic_ManyArgsReturns_Call) RunAndReturn(run func(str string, i int)([]string, error)) *MockExpecterAndRolledVariadic_ManyArgsReturns_Call { - _c.Call.Return(run) - return _c -} - - -// NoArg provides a mock function for the type MockExpecterAndRolledVariadic -func (_mock *MockExpecterAndRolledVariadic) NoArg() string { - ret := _mock.Called() - - if len(ret) == 0 { - panic("no return value specified for NoArg") - } - - - var r0 string - if returnFunc, ok := ret.Get(0).(func() string); ok { - r0 = returnFunc() - } else { - r0 = ret.Get(0).(string) - } - return r0 -} - - - -// MockExpecterAndRolledVariadic_NoArg_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NoArg' -type MockExpecterAndRolledVariadic_NoArg_Call struct { - *mock.Call -} - - - -// NoArg is a helper method to define mock.On call -func (_e *MockExpecterAndRolledVariadic_Expecter) NoArg() *MockExpecterAndRolledVariadic_NoArg_Call { - return &MockExpecterAndRolledVariadic_NoArg_Call{Call: _e.mock.On("NoArg", )} -} - -func (_c *MockExpecterAndRolledVariadic_NoArg_Call) Run(run func()) *MockExpecterAndRolledVariadic_NoArg_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *MockExpecterAndRolledVariadic_NoArg_Call) Return(s string) *MockExpecterAndRolledVariadic_NoArg_Call { - _c.Call.Return(s) - return _c -} - -func (_c *MockExpecterAndRolledVariadic_NoArg_Call) RunAndReturn(run func()string) *MockExpecterAndRolledVariadic_NoArg_Call { - _c.Call.Return(run) - return _c -} - - -// NoReturn provides a mock function for the type MockExpecterAndRolledVariadic -func (_mock *MockExpecterAndRolledVariadic) NoReturn(str string) { _mock.Called(str) - return -} - - - -// MockExpecterAndRolledVariadic_NoReturn_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NoReturn' -type MockExpecterAndRolledVariadic_NoReturn_Call struct { - *mock.Call -} - - - -// NoReturn is a helper method to define mock.On call -// - str -func (_e *MockExpecterAndRolledVariadic_Expecter) NoReturn(str interface{}, ) *MockExpecterAndRolledVariadic_NoReturn_Call { - return &MockExpecterAndRolledVariadic_NoReturn_Call{Call: _e.mock.On("NoReturn",str, )} -} - -func (_c *MockExpecterAndRolledVariadic_NoReturn_Call) Run(run func(str string)) *MockExpecterAndRolledVariadic_NoReturn_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string),) - }) - return _c -} - -func (_c *MockExpecterAndRolledVariadic_NoReturn_Call) Return() *MockExpecterAndRolledVariadic_NoReturn_Call { - _c.Call.Return() - return _c -} - -func (_c *MockExpecterAndRolledVariadic_NoReturn_Call) RunAndReturn(run func(str string)) *MockExpecterAndRolledVariadic_NoReturn_Call { - _c.Run(run) - return _c -} - - -// Variadic provides a mock function for the type MockExpecterAndRolledVariadic -func (_mock *MockExpecterAndRolledVariadic) Variadic(ints ...int) error { - var tmpRet mock.Arguments - if len(ints) > 0 {tmpRet = _mock.Called(ints) - } else {tmpRet = _mock.Called() - } - ret := tmpRet - - if len(ret) == 0 { - panic("no return value specified for Variadic") - } - - - var r0 error - if returnFunc, ok := ret.Get(0).(func(...int) error); ok { - r0 = returnFunc(ints...) - } else { - r0 = ret.Error(0) - } - return r0 -} - - - -// MockExpecterAndRolledVariadic_Variadic_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Variadic' -type MockExpecterAndRolledVariadic_Variadic_Call struct { - *mock.Call -} - - - -// Variadic is a helper method to define mock.On call -// - ints -func (_e *MockExpecterAndRolledVariadic_Expecter) Variadic(ints ...interface{}, ) *MockExpecterAndRolledVariadic_Variadic_Call { - return &MockExpecterAndRolledVariadic_Variadic_Call{Call: _e.mock.On("Variadic", - append([]interface{}{ }, ints... )... )} -} - -func (_c *MockExpecterAndRolledVariadic_Variadic_Call) Run(run func(ints ...int)) *MockExpecterAndRolledVariadic_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 *MockExpecterAndRolledVariadic_Variadic_Call) Return(err error) *MockExpecterAndRolledVariadic_Variadic_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockExpecterAndRolledVariadic_Variadic_Call) RunAndReturn(run func(ints ...int)error) *MockExpecterAndRolledVariadic_Variadic_Call { - _c.Call.Return(run) - return _c -} - - -// VariadicMany provides a mock function for the type MockExpecterAndRolledVariadic -func (_mock *MockExpecterAndRolledVariadic) VariadicMany(i int, a string, intfs ...interface{}) error { - var tmpRet mock.Arguments - if len(intfs) > 0 {tmpRet = _mock.Called(i, a, intfs) - } else {tmpRet = _mock.Called(i, a) - } - ret := tmpRet - - if len(ret) == 0 { - panic("no return value specified for VariadicMany") - } - - - var r0 error - if returnFunc, ok := ret.Get(0).(func(int, string, ...interface{}) error); ok { - r0 = returnFunc(i, a, intfs...) - } else { - r0 = ret.Error(0) - } - return r0 -} - - - -// MockExpecterAndRolledVariadic_VariadicMany_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'VariadicMany' -type MockExpecterAndRolledVariadic_VariadicMany_Call struct { - *mock.Call -} - - - -// VariadicMany is a helper method to define mock.On call -// - i -// - a -// - intfs -func (_e *MockExpecterAndRolledVariadic_Expecter) VariadicMany(i interface{}, a interface{}, intfs ...interface{}, ) *MockExpecterAndRolledVariadic_VariadicMany_Call { - return &MockExpecterAndRolledVariadic_VariadicMany_Call{Call: _e.mock.On("VariadicMany", - append([]interface{}{ i, a, }, intfs... )... )} -} - -func (_c *MockExpecterAndRolledVariadic_VariadicMany_Call) Run(run func(i int, a string, intfs ...interface{})) *MockExpecterAndRolledVariadic_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 *MockExpecterAndRolledVariadic_VariadicMany_Call) Return(err error) *MockExpecterAndRolledVariadic_VariadicMany_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockExpecterAndRolledVariadic_VariadicMany_Call) RunAndReturn(run func(i int, a string, intfs ...interface{})error) *MockExpecterAndRolledVariadic_VariadicMany_Call { - _c.Call.Return(run) - return _c -} - // NewMockExpecter creates a new instance of MockExpecter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewMockExpecter (t interface { @@ -1337,15 +1031,12 @@ func (_c *MockExpecter_NoReturn_Call) RunAndReturn(run func(str string)) *MockEx // Variadic provides a mock function for the type MockExpecter -func (_mock *MockExpecter) Variadic(ints ...int) error { - // int - _va := make([]interface{}, len(ints)) - for _i := range ints { - _va[_i] = ints[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _mock.Called(_ca...) +func (_mock *MockExpecter) Variadic(ints ...int) error { + var tmpRet mock.Arguments + if len(ints) > 0 {tmpRet = _mock.Called(ints) + } else {tmpRet = _mock.Called() + } + ret := tmpRet if len(ret) == 0 { panic("no return value specified for Variadic") @@ -1402,11 +1093,12 @@ func (_c *MockExpecter_Variadic_Call) RunAndReturn(run func(ints ...int)error) * // VariadicMany provides a mock function for the type MockExpecter -func (_mock *MockExpecter) VariadicMany(i int, a string, intfs ...interface{}) error { - var _ca []interface{} - _ca = append(_ca, i, a) - _ca = append(_ca, intfs...) - ret := _mock.Called(_ca...) +func (_mock *MockExpecter) VariadicMany(i int, a string, intfs ...interface{}) error { + var tmpRet mock.Arguments + if len(intfs) > 0 {tmpRet = _mock.Called(i, a, intfs) + } else {tmpRet = _mock.Called(i, a) + } + ret := tmpRet if len(ret) == 0 { panic("no return value specified for VariadicMany") @@ -4558,285 +4250,6 @@ func (_c *MockrequesterUnexported_Get_Call) RunAndReturn(run func()) *Mockreques return _c } -// NewMockRequesterVariadicOneArgument creates a new instance of MockRequesterVariadicOneArgument. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockRequesterVariadicOneArgument (t interface { - mock.TestingT - Cleanup(func()) -}) *MockRequesterVariadicOneArgument { - mock := &MockRequesterVariadicOneArgument{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} - - -// MockRequesterVariadicOneArgument is an autogenerated mock type for the RequesterVariadic type -type MockRequesterVariadicOneArgument struct { - mock.Mock -} - -type MockRequesterVariadicOneArgument_Expecter struct { - mock *mock.Mock -} - -func (_m *MockRequesterVariadicOneArgument) EXPECT() *MockRequesterVariadicOneArgument_Expecter { - return &MockRequesterVariadicOneArgument_Expecter{mock: &_m.Mock} -} - - - -// Get provides a mock function for the type MockRequesterVariadicOneArgument -func (_mock *MockRequesterVariadicOneArgument) Get(values ...string) bool { - var tmpRet mock.Arguments - if len(values) > 0 {tmpRet = _mock.Called(values) - } else {tmpRet = _mock.Called() - } - ret := tmpRet - - if len(ret) == 0 { - panic("no return value specified for Get") - } - - - var r0 bool - if returnFunc, ok := ret.Get(0).(func(...string) bool); ok { - r0 = returnFunc(values...) - } else { - r0 = ret.Get(0).(bool) - } - return r0 -} - - - -// MockRequesterVariadicOneArgument_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' -type MockRequesterVariadicOneArgument_Get_Call struct { - *mock.Call -} - - - -// Get is a helper method to define mock.On call -// - values -func (_e *MockRequesterVariadicOneArgument_Expecter) Get(values ...interface{}, ) *MockRequesterVariadicOneArgument_Get_Call { - return &MockRequesterVariadicOneArgument_Get_Call{Call: _e.mock.On("Get", - append([]interface{}{ }, values... )... )} -} - -func (_c *MockRequesterVariadicOneArgument_Get_Call) Run(run func(values ...string)) *MockRequesterVariadicOneArgument_Get_Call { - _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]string, len(args) - 0) - for i, a := range args[0:] { - if a != nil { - variadicArgs[i] = a.(string) - } - } - run(variadicArgs...) - }) - return _c -} - -func (_c *MockRequesterVariadicOneArgument_Get_Call) Return(b bool) *MockRequesterVariadicOneArgument_Get_Call { - _c.Call.Return(b) - return _c -} - -func (_c *MockRequesterVariadicOneArgument_Get_Call) RunAndReturn(run func(values ...string)bool) *MockRequesterVariadicOneArgument_Get_Call { - _c.Call.Return(run) - return _c -} - - -// MultiWriteToFile provides a mock function for the type MockRequesterVariadicOneArgument -func (_mock *MockRequesterVariadicOneArgument) MultiWriteToFile(filename string, w ...io.Writer) string { - var tmpRet mock.Arguments - if len(w) > 0 {tmpRet = _mock.Called(filename, w) - } else {tmpRet = _mock.Called(filename) - } - ret := tmpRet - - if len(ret) == 0 { - panic("no return value specified for MultiWriteToFile") - } - - - var r0 string - if returnFunc, ok := ret.Get(0).(func(string, ...io.Writer) string); ok { - r0 = returnFunc(filename, w...) - } else { - r0 = ret.Get(0).(string) - } - return r0 -} - - - -// MockRequesterVariadicOneArgument_MultiWriteToFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MultiWriteToFile' -type MockRequesterVariadicOneArgument_MultiWriteToFile_Call struct { - *mock.Call -} - - - -// MultiWriteToFile is a helper method to define mock.On call -// - filename -// - w -func (_e *MockRequesterVariadicOneArgument_Expecter) MultiWriteToFile(filename interface{}, w ...interface{}, ) *MockRequesterVariadicOneArgument_MultiWriteToFile_Call { - return &MockRequesterVariadicOneArgument_MultiWriteToFile_Call{Call: _e.mock.On("MultiWriteToFile", - append([]interface{}{ filename, }, w... )... )} -} - -func (_c *MockRequesterVariadicOneArgument_MultiWriteToFile_Call) Run(run func(filename string, w ...io.Writer)) *MockRequesterVariadicOneArgument_MultiWriteToFile_Call { - _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]io.Writer, len(args) - 1) - for i, a := range args[1:] { - if a != nil { - variadicArgs[i] = a.(io.Writer) - } - } - run(args[0].(string),variadicArgs...) - }) - return _c -} - -func (_c *MockRequesterVariadicOneArgument_MultiWriteToFile_Call) Return(s string) *MockRequesterVariadicOneArgument_MultiWriteToFile_Call { - _c.Call.Return(s) - return _c -} - -func (_c *MockRequesterVariadicOneArgument_MultiWriteToFile_Call) RunAndReturn(run func(filename string, w ...io.Writer)string) *MockRequesterVariadicOneArgument_MultiWriteToFile_Call { - _c.Call.Return(run) - return _c -} - - -// OneInterface provides a mock function for the type MockRequesterVariadicOneArgument -func (_mock *MockRequesterVariadicOneArgument) OneInterface(a ...interface{}) bool { - var tmpRet mock.Arguments - if len(a) > 0 {tmpRet = _mock.Called(a) - } else {tmpRet = _mock.Called() - } - ret := tmpRet - - if len(ret) == 0 { - panic("no return value specified for OneInterface") - } - - - var r0 bool - if returnFunc, ok := ret.Get(0).(func(...interface{}) bool); ok { - r0 = returnFunc(a...) - } else { - r0 = ret.Get(0).(bool) - } - return r0 -} - - - -// MockRequesterVariadicOneArgument_OneInterface_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneInterface' -type MockRequesterVariadicOneArgument_OneInterface_Call struct { - *mock.Call -} - - - -// OneInterface is a helper method to define mock.On call -// - a -func (_e *MockRequesterVariadicOneArgument_Expecter) OneInterface(a ...interface{}, ) *MockRequesterVariadicOneArgument_OneInterface_Call { - return &MockRequesterVariadicOneArgument_OneInterface_Call{Call: _e.mock.On("OneInterface", - append([]interface{}{ }, a... )... )} -} - -func (_c *MockRequesterVariadicOneArgument_OneInterface_Call) Run(run func(a ...interface{})) *MockRequesterVariadicOneArgument_OneInterface_Call { - _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]interface{}, len(args) - 0) - for i, a := range args[0:] { - if a != nil { - variadicArgs[i] = a.(interface{}) - } - } - run(variadicArgs...) - }) - return _c -} - -func (_c *MockRequesterVariadicOneArgument_OneInterface_Call) Return(b bool) *MockRequesterVariadicOneArgument_OneInterface_Call { - _c.Call.Return(b) - return _c -} - -func (_c *MockRequesterVariadicOneArgument_OneInterface_Call) RunAndReturn(run func(a ...interface{})bool) *MockRequesterVariadicOneArgument_OneInterface_Call { - _c.Call.Return(run) - return _c -} - - -// Sprintf provides a mock function for the type MockRequesterVariadicOneArgument -func (_mock *MockRequesterVariadicOneArgument) Sprintf(format string, a ...interface{}) string { - var tmpRet mock.Arguments - if len(a) > 0 {tmpRet = _mock.Called(format, a) - } else {tmpRet = _mock.Called(format) - } - ret := tmpRet - - if len(ret) == 0 { - panic("no return value specified for Sprintf") - } - - - var r0 string - if returnFunc, ok := ret.Get(0).(func(string, ...interface{}) string); ok { - r0 = returnFunc(format, a...) - } else { - r0 = ret.Get(0).(string) - } - return r0 -} - - - -// MockRequesterVariadicOneArgument_Sprintf_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Sprintf' -type MockRequesterVariadicOneArgument_Sprintf_Call struct { - *mock.Call -} - - - -// Sprintf is a helper method to define mock.On call -// - format -// - a -func (_e *MockRequesterVariadicOneArgument_Expecter) Sprintf(format interface{}, a ...interface{}, ) *MockRequesterVariadicOneArgument_Sprintf_Call { - return &MockRequesterVariadicOneArgument_Sprintf_Call{Call: _e.mock.On("Sprintf", - append([]interface{}{ format, }, a... )... )} -} - -func (_c *MockRequesterVariadicOneArgument_Sprintf_Call) Run(run func(format string, a ...interface{})) *MockRequesterVariadicOneArgument_Sprintf_Call { - _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]interface{}, len(args) - 1) - for i, a := range args[1:] { - if a != nil { - variadicArgs[i] = a.(interface{}) - } - } - run(args[0].(string),variadicArgs...) - }) - return _c -} - -func (_c *MockRequesterVariadicOneArgument_Sprintf_Call) Return(s string) *MockRequesterVariadicOneArgument_Sprintf_Call { - _c.Call.Return(s) - return _c -} - -func (_c *MockRequesterVariadicOneArgument_Sprintf_Call) RunAndReturn(run func(format string, a ...interface{})string) *MockRequesterVariadicOneArgument_Sprintf_Call { - _c.Call.Return(run) - return _c -} - // NewMockRequesterVariadic creates a new instance of MockRequesterVariadic. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewMockRequesterVariadic (t interface { @@ -4868,15 +4281,12 @@ func (_m *MockRequesterVariadic) EXPECT() *MockRequesterVariadic_Expecter { // Get provides a mock function for the type MockRequesterVariadic -func (_mock *MockRequesterVariadic) Get(values ...string) bool { - // string - _va := make([]interface{}, len(values)) - for _i := range values { - _va[_i] = values[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _mock.Called(_ca...) +func (_mock *MockRequesterVariadic) Get(values ...string) bool { + var tmpRet mock.Arguments + if len(values) > 0 {tmpRet = _mock.Called(values) + } else {tmpRet = _mock.Called() + } + ret := tmpRet if len(ret) == 0 { panic("no return value specified for Get") @@ -4933,16 +4343,12 @@ func (_c *MockRequesterVariadic_Get_Call) RunAndReturn(run func(values ...string // MultiWriteToFile provides a mock function for the type MockRequesterVariadic -func (_mock *MockRequesterVariadic) MultiWriteToFile(filename string, w ...io.Writer) string { - // io.Writer - _va := make([]interface{}, len(w)) - for _i := range w { - _va[_i] = w[_i] - } - var _ca []interface{} - _ca = append(_ca, filename) - _ca = append(_ca, _va...) - ret := _mock.Called(_ca...) +func (_mock *MockRequesterVariadic) MultiWriteToFile(filename string, w ...io.Writer) string { + var tmpRet mock.Arguments + if len(w) > 0 {tmpRet = _mock.Called(filename, w) + } else {tmpRet = _mock.Called(filename) + } + ret := tmpRet if len(ret) == 0 { panic("no return value specified for MultiWriteToFile") @@ -5000,10 +4406,12 @@ func (_c *MockRequesterVariadic_MultiWriteToFile_Call) RunAndReturn(run func(fil // OneInterface provides a mock function for the type MockRequesterVariadic -func (_mock *MockRequesterVariadic) OneInterface(a ...interface{}) bool { - var _ca []interface{} - _ca = append(_ca, a...) - ret := _mock.Called(_ca...) +func (_mock *MockRequesterVariadic) OneInterface(a ...interface{}) bool { + var tmpRet mock.Arguments + if len(a) > 0 {tmpRet = _mock.Called(a) + } else {tmpRet = _mock.Called() + } + ret := tmpRet if len(ret) == 0 { panic("no return value specified for OneInterface") @@ -5060,11 +4468,12 @@ func (_c *MockRequesterVariadic_OneInterface_Call) RunAndReturn(run func(a ...in // Sprintf provides a mock function for the type MockRequesterVariadic -func (_mock *MockRequesterVariadic) Sprintf(format string, a ...interface{}) string { - var _ca []interface{} - _ca = append(_ca, format) - _ca = append(_ca, a...) - ret := _mock.Called(_ca...) +func (_mock *MockRequesterVariadic) Sprintf(format string, a ...interface{}) string { + var tmpRet mock.Arguments + if len(a) > 0 {tmpRet = _mock.Called(format, a) + } else {tmpRet = _mock.Called(format) + } + ret := tmpRet if len(ret) == 0 { panic("no return value specified for Sprintf") diff --git a/internal/template_generator.go b/internal/template_generator.go index 7604a256..7b812ff6 100644 --- a/internal/template_generator.go +++ b/internal/template_generator.go @@ -102,8 +102,9 @@ type TemplateGenerator struct { templateName string registry *template.Registry formatter Formatter - pkgConfig *Config inPackage bool + pkgConfig *Config + pkgName string } func NewTemplateGenerator( @@ -112,6 +113,7 @@ func NewTemplateGenerator( outPkgFSPath *pathlib.Path, templateName string, formatter Formatter, + pkgConfig *Config, pkgName string, ) (*TemplateGenerator, error) { srcPkgFSPath := pathlib.NewPath(srcPkg.GoFiles[0]).Parent() @@ -156,8 +158,9 @@ func NewTemplateGenerator( templateName: templateName, registry: reg, formatter: formatter, - pkgConfig: pkgConfig, inPackage: inPackage, + pkgConfig: pkgConfig, + pkgName: pkgName, }, nil } @@ -300,7 +303,7 @@ func (g *TemplateGenerator) Generate( data := template.Data{ Boilerplate: boilerplate, BuildTags: g.pkgConfig.MockBuildTags, - PkgName: g.pkgConfig.PkgName, + PkgName: g.pkgName, SrcPkgQualifier: "", Mocks: mockData, TemplateData: g.pkgConfig.TemplateData,