diff --git a/Makefile b/Makefile index 1799d24d..17cf5a7e 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,7 @@ SHELL=bash .PHONY: all -all: clean fmt mocks test install docker integration - -.PHONY: clean -clean: - rm -rf mocks +all: fmt mocks test install docker integration .PHONY: fmt fmt: @@ -31,3 +27,7 @@ docker: .PHONY: integration integration: docker install ./hack/run-e2e.sh + +.PHONY: clean +clean: + rm -rf mocks diff --git a/mocks/pkg/fixtures/A.go b/mocks/pkg/fixtures/A.go index 1520a9a5..97d9213a 100644 --- a/mocks/pkg/fixtures/A.go +++ b/mocks/pkg/fixtures/A.go @@ -5,6 +5,8 @@ package mocks import ( mock "github.com/stretchr/testify/mock" test "github.com/vektra/mockery/v2/pkg/fixtures" + + testing "testing" ) // A is an autogenerated mock type for the A type @@ -32,3 +34,12 @@ func (_m *A) Call() (test.B, error) { return r0, r1 } + +// NewA creates a new instance of A. It also registers a cleanup function to assert the mocks expectations. +func NewA(t testing.TB) *A { + mock := &A{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/AsyncProducer.go b/mocks/pkg/fixtures/AsyncProducer.go index b879a170..cf527f8b 100644 --- a/mocks/pkg/fixtures/AsyncProducer.go +++ b/mocks/pkg/fixtures/AsyncProducer.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // AsyncProducer is an autogenerated mock type for the AsyncProducer type type AsyncProducer struct { @@ -56,3 +60,12 @@ func (_m *AsyncProducer) Whatever() chan bool { return r0 } + +// NewAsyncProducer creates a new instance of AsyncProducer. It also registers a cleanup function to assert the mocks expectations. +func NewAsyncProducer(t testing.TB) *AsyncProducer { + mock := &AsyncProducer{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/Blank.go b/mocks/pkg/fixtures/Blank.go index cf0e31bd..63f1e5f1 100644 --- a/mocks/pkg/fixtures/Blank.go +++ b/mocks/pkg/fixtures/Blank.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // Blank is an autogenerated mock type for the Blank type type Blank struct { @@ -22,3 +26,12 @@ func (_m *Blank) Create(x interface{}) error { return r0 } + +// NewBlank creates a new instance of Blank. It also registers a cleanup function to assert the mocks expectations. +func NewBlank(t testing.TB) *Blank { + mock := &Blank{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/ConsulLock.go b/mocks/pkg/fixtures/ConsulLock.go index 974ea3c7..f3204360 100644 --- a/mocks/pkg/fixtures/ConsulLock.go +++ b/mocks/pkg/fixtures/ConsulLock.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // ConsulLock is an autogenerated mock type for the ConsulLock type type ConsulLock struct { @@ -45,3 +49,12 @@ func (_m *ConsulLock) Unlock() error { return r0 } + +// NewConsulLock creates a new instance of ConsulLock. It also registers a cleanup function to assert the mocks expectations. +func NewConsulLock(t testing.TB) *ConsulLock { + mock := &ConsulLock{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/Example.go b/mocks/pkg/fixtures/Example.go index 518e541b..70d37739 100644 --- a/mocks/pkg/fixtures/Example.go +++ b/mocks/pkg/fixtures/Example.go @@ -8,6 +8,8 @@ import ( fixtureshttp "github.com/vektra/mockery/v2/pkg/fixtures/http" mock "github.com/stretchr/testify/mock" + + testing "testing" ) // Example is an autogenerated mock type for the Example type @@ -44,3 +46,12 @@ func (_m *Example) B(_a0 string) fixtureshttp.MyStruct { return r0 } + +// NewExample creates a new instance of Example. It also registers a cleanup function to assert the mocks expectations. +func NewExample(t testing.TB) *Example { + mock := &Example{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/ExpecterTest.go b/mocks/pkg/fixtures/ExpecterTest.go index b5a96995..3a4d7bbf 100644 --- a/mocks/pkg/fixtures/ExpecterTest.go +++ b/mocks/pkg/fixtures/ExpecterTest.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // ExpecterTest is an autogenerated mock type for the ExpecterTest type type ExpecterTest struct { @@ -87,3 +91,12 @@ func (_m *ExpecterTest) VariadicMany(i int, a string, intfs ...interface{}) erro return r0 } + +// NewExpecterTest creates a new instance of ExpecterTest. It also registers a cleanup function to assert the mocks expectations. +func NewExpecterTest(t testing.TB) *ExpecterTest { + mock := &ExpecterTest{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/Fooer.go b/mocks/pkg/fixtures/Fooer.go index d0acf376..4686c6ce 100644 --- a/mocks/pkg/fixtures/Fooer.go +++ b/mocks/pkg/fixtures/Fooer.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // Fooer is an autogenerated mock type for the Fooer type type Fooer struct { @@ -43,3 +47,12 @@ func (_m *Fooer) Foo(f func(string) string) error { return r0 } + +// NewFooer creates a new instance of Fooer. It also registers a cleanup function to assert the mocks expectations. +func NewFooer(t testing.TB) *Fooer { + mock := &Fooer{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/FuncArgsCollision.go b/mocks/pkg/fixtures/FuncArgsCollision.go index 448259f0..e27c1e0b 100644 --- a/mocks/pkg/fixtures/FuncArgsCollision.go +++ b/mocks/pkg/fixtures/FuncArgsCollision.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // FuncArgsCollision is an autogenerated mock type for the FuncArgsCollision type type FuncArgsCollision struct { @@ -22,3 +26,12 @@ func (_m *FuncArgsCollision) Foo(ret interface{}) error { return r0 } + +// NewFuncArgsCollision creates a new instance of FuncArgsCollision. It also registers a cleanup function to assert the mocks expectations. +func NewFuncArgsCollision(t testing.TB) *FuncArgsCollision { + mock := &FuncArgsCollision{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/HasConflictingNestedImports.go b/mocks/pkg/fixtures/HasConflictingNestedImports.go index c9c4f72d..ab1f0882 100644 --- a/mocks/pkg/fixtures/HasConflictingNestedImports.go +++ b/mocks/pkg/fixtures/HasConflictingNestedImports.go @@ -8,6 +8,8 @@ import ( fixtureshttp "github.com/vektra/mockery/v2/pkg/fixtures/http" mock "github.com/stretchr/testify/mock" + + testing "testing" ) // HasConflictingNestedImports is an autogenerated mock type for the HasConflictingNestedImports type @@ -49,3 +51,12 @@ func (_m *HasConflictingNestedImports) Z() fixtureshttp.MyStruct { return r0 } + +// NewHasConflictingNestedImports creates a new instance of HasConflictingNestedImports. It also registers a cleanup function to assert the mocks expectations. +func NewHasConflictingNestedImports(t testing.TB) *HasConflictingNestedImports { + mock := &HasConflictingNestedImports{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/ImportsSameAsPackage.go b/mocks/pkg/fixtures/ImportsSameAsPackage.go index f106e3ba..068b4851 100644 --- a/mocks/pkg/fixtures/ImportsSameAsPackage.go +++ b/mocks/pkg/fixtures/ImportsSameAsPackage.go @@ -7,6 +7,8 @@ import ( fixtures "github.com/vektra/mockery/v2/pkg/fixtures" test "github.com/vektra/mockery/v2/pkg/fixtures/test" + + testing "testing" ) // ImportsSameAsPackage is an autogenerated mock type for the ImportsSameAsPackage type @@ -48,3 +50,12 @@ func (_m *ImportsSameAsPackage) B() fixtures.KeyManager { func (_m *ImportsSameAsPackage) C(_a0 fixtures.C) { _m.Called(_a0) } + +// NewImportsSameAsPackage creates a new instance of ImportsSameAsPackage. It also registers a cleanup function to assert the mocks expectations. +func NewImportsSameAsPackage(t testing.TB) *ImportsSameAsPackage { + mock := &ImportsSameAsPackage{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/KeyManager.go b/mocks/pkg/fixtures/KeyManager.go index 491c81af..a62c54d0 100644 --- a/mocks/pkg/fixtures/KeyManager.go +++ b/mocks/pkg/fixtures/KeyManager.go @@ -5,6 +5,8 @@ package mocks import ( mock "github.com/stretchr/testify/mock" test "github.com/vektra/mockery/v2/pkg/fixtures" + + testing "testing" ) // KeyManager is an autogenerated mock type for the KeyManager type @@ -36,3 +38,12 @@ func (_m *KeyManager) GetKey(_a0 string, _a1 uint16) ([]byte, *test.Err) { return r0, r1 } + +// NewKeyManager creates a new instance of KeyManager. It also registers a cleanup function to assert the mocks expectations. +func NewKeyManager(t testing.TB) *KeyManager { + mock := &KeyManager{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/MapFunc.go b/mocks/pkg/fixtures/MapFunc.go index 7284e088..7db4112f 100644 --- a/mocks/pkg/fixtures/MapFunc.go +++ b/mocks/pkg/fixtures/MapFunc.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // MapFunc is an autogenerated mock type for the MapFunc type type MapFunc struct { @@ -22,3 +26,12 @@ func (_m *MapFunc) Get(m map[string]func(string) string) error { return r0 } + +// NewMapFunc creates a new instance of MapFunc. It also registers a cleanup function to assert the mocks expectations. +func NewMapFunc(t testing.TB) *MapFunc { + mock := &MapFunc{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/MapToInterface.go b/mocks/pkg/fixtures/MapToInterface.go index 2a48e951..0d53a8fd 100644 --- a/mocks/pkg/fixtures/MapToInterface.go +++ b/mocks/pkg/fixtures/MapToInterface.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // MapToInterface is an autogenerated mock type for the MapToInterface type type MapToInterface struct { @@ -19,3 +23,12 @@ func (_m *MapToInterface) Foo(arg1 ...map[string]interface{}) { _ca = append(_ca, _va...) _m.Called(_ca...) } + +// NewMapToInterface creates a new instance of MapToInterface. It also registers a cleanup function to assert the mocks expectations. +func NewMapToInterface(t testing.TB) *MapToInterface { + mock := &MapToInterface{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/MyReader.go b/mocks/pkg/fixtures/MyReader.go index 1fc8760a..c52c773b 100644 --- a/mocks/pkg/fixtures/MyReader.go +++ b/mocks/pkg/fixtures/MyReader.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // MyReader is an autogenerated mock type for the MyReader type type MyReader struct { @@ -29,3 +33,12 @@ func (_m *MyReader) Read(p []byte) (int, error) { return r0, r1 } + +// NewMyReader creates a new instance of MyReader. It also registers a cleanup function to assert the mocks expectations. +func NewMyReader(t testing.TB) *MyReader { + mock := &MyReader{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/Requester.go b/mocks/pkg/fixtures/Requester.go index 3eeef779..19c67ce9 100644 --- a/mocks/pkg/fixtures/Requester.go +++ b/mocks/pkg/fixtures/Requester.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // Requester is an autogenerated mock type for the Requester type type Requester struct { @@ -29,3 +33,12 @@ func (_m *Requester) Get(path string) (string, error) { return r0, r1 } + +// NewRequester creates a new instance of Requester. It also registers a cleanup function to assert the mocks expectations. +func NewRequester(t testing.TB) *Requester { + mock := &Requester{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/Requester2.go b/mocks/pkg/fixtures/Requester2.go index 3e8c5e23..53830866 100644 --- a/mocks/pkg/fixtures/Requester2.go +++ b/mocks/pkg/fixtures/Requester2.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // Requester2 is an autogenerated mock type for the Requester2 type type Requester2 struct { @@ -22,3 +26,12 @@ func (_m *Requester2) Get(path string) error { return r0 } + +// NewRequester2 creates a new instance of Requester2. It also registers a cleanup function to assert the mocks expectations. +func NewRequester2(t testing.TB) *Requester2 { + mock := &Requester2{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/Requester3.go b/mocks/pkg/fixtures/Requester3.go index ded0d3c1..4f0b6480 100644 --- a/mocks/pkg/fixtures/Requester3.go +++ b/mocks/pkg/fixtures/Requester3.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // Requester3 is an autogenerated mock type for the Requester3 type type Requester3 struct { @@ -22,3 +26,12 @@ func (_m *Requester3) Get() error { return r0 } + +// NewRequester3 creates a new instance of Requester3. It also registers a cleanup function to assert the mocks expectations. +func NewRequester3(t testing.TB) *Requester3 { + mock := &Requester3{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/Requester4.go b/mocks/pkg/fixtures/Requester4.go index f2fc563a..15126cc0 100644 --- a/mocks/pkg/fixtures/Requester4.go +++ b/mocks/pkg/fixtures/Requester4.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // Requester4 is an autogenerated mock type for the Requester4 type type Requester4 struct { @@ -13,3 +17,12 @@ type Requester4 struct { func (_m *Requester4) Get() { _m.Called() } + +// NewRequester4 creates a new instance of Requester4. It also registers a cleanup function to assert the mocks expectations. +func NewRequester4(t testing.TB) *Requester4 { + mock := &Requester4{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/RequesterArgSameAsImport.go b/mocks/pkg/fixtures/RequesterArgSameAsImport.go index 21472f2e..f4713628 100644 --- a/mocks/pkg/fixtures/RequesterArgSameAsImport.go +++ b/mocks/pkg/fixtures/RequesterArgSameAsImport.go @@ -6,6 +6,8 @@ import ( json "encoding/json" mock "github.com/stretchr/testify/mock" + + testing "testing" ) // RequesterArgSameAsImport is an autogenerated mock type for the RequesterArgSameAsImport type @@ -28,3 +30,12 @@ func (_m *RequesterArgSameAsImport) Get(_a0 string) *json.RawMessage { return r0 } + +// NewRequesterArgSameAsImport creates a new instance of RequesterArgSameAsImport. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterArgSameAsImport(t testing.TB) *RequesterArgSameAsImport { + mock := &RequesterArgSameAsImport{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/RequesterArgSameAsNamedImport.go b/mocks/pkg/fixtures/RequesterArgSameAsNamedImport.go index 022c164a..477cc79e 100644 --- a/mocks/pkg/fixtures/RequesterArgSameAsNamedImport.go +++ b/mocks/pkg/fixtures/RequesterArgSameAsNamedImport.go @@ -6,6 +6,8 @@ import ( json "encoding/json" mock "github.com/stretchr/testify/mock" + + testing "testing" ) // RequesterArgSameAsNamedImport is an autogenerated mock type for the RequesterArgSameAsNamedImport type @@ -28,3 +30,12 @@ func (_m *RequesterArgSameAsNamedImport) Get(_a0 string) *json.RawMessage { return r0 } + +// NewRequesterArgSameAsNamedImport creates a new instance of RequesterArgSameAsNamedImport. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterArgSameAsNamedImport(t testing.TB) *RequesterArgSameAsNamedImport { + mock := &RequesterArgSameAsNamedImport{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/RequesterArgSameAsPkg.go b/mocks/pkg/fixtures/RequesterArgSameAsPkg.go index e3413d04..e44d44e8 100644 --- a/mocks/pkg/fixtures/RequesterArgSameAsPkg.go +++ b/mocks/pkg/fixtures/RequesterArgSameAsPkg.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // RequesterArgSameAsPkg is an autogenerated mock type for the RequesterArgSameAsPkg type type RequesterArgSameAsPkg struct { @@ -13,3 +17,12 @@ type RequesterArgSameAsPkg struct { func (_m *RequesterArgSameAsPkg) Get(_a0 string) { _m.Called(_a0) } + +// NewRequesterArgSameAsPkg creates a new instance of RequesterArgSameAsPkg. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterArgSameAsPkg(t testing.TB) *RequesterArgSameAsPkg { + mock := &RequesterArgSameAsPkg{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/RequesterArray.go b/mocks/pkg/fixtures/RequesterArray.go index 9f830cb7..62a55754 100644 --- a/mocks/pkg/fixtures/RequesterArray.go +++ b/mocks/pkg/fixtures/RequesterArray.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // RequesterArray is an autogenerated mock type for the RequesterArray type type RequesterArray struct { @@ -31,3 +35,12 @@ func (_m *RequesterArray) Get(path string) ([2]string, error) { return r0, r1 } + +// NewRequesterArray creates a new instance of RequesterArray. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterArray(t testing.TB) *RequesterArray { + mock := &RequesterArray{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/RequesterElided.go b/mocks/pkg/fixtures/RequesterElided.go index dc109c93..c5cd7e28 100644 --- a/mocks/pkg/fixtures/RequesterElided.go +++ b/mocks/pkg/fixtures/RequesterElided.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // RequesterElided is an autogenerated mock type for the RequesterElided type type RequesterElided struct { @@ -22,3 +26,12 @@ func (_m *RequesterElided) Get(path string, url string) error { return r0 } + +// NewRequesterElided creates a new instance of RequesterElided. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterElided(t testing.TB) *RequesterElided { + mock := &RequesterElided{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/RequesterIface.go b/mocks/pkg/fixtures/RequesterIface.go index 07191707..7224ec0a 100644 --- a/mocks/pkg/fixtures/RequesterIface.go +++ b/mocks/pkg/fixtures/RequesterIface.go @@ -6,6 +6,8 @@ import ( io "io" mock "github.com/stretchr/testify/mock" + + testing "testing" ) // RequesterIface is an autogenerated mock type for the RequesterIface type @@ -28,3 +30,12 @@ func (_m *RequesterIface) Get() io.Reader { return r0 } + +// NewRequesterIface creates a new instance of RequesterIface. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterIface(t testing.TB) *RequesterIface { + mock := &RequesterIface{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/RequesterNS.go b/mocks/pkg/fixtures/RequesterNS.go index 27fe986c..98aa710c 100644 --- a/mocks/pkg/fixtures/RequesterNS.go +++ b/mocks/pkg/fixtures/RequesterNS.go @@ -6,6 +6,8 @@ import ( http "net/http" mock "github.com/stretchr/testify/mock" + + testing "testing" ) // RequesterNS is an autogenerated mock type for the RequesterNS type @@ -33,3 +35,12 @@ func (_m *RequesterNS) Get(path string) (http.Response, error) { return r0, r1 } + +// NewRequesterNS creates a new instance of RequesterNS. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterNS(t testing.TB) *RequesterNS { + mock := &RequesterNS{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/RequesterPtr.go b/mocks/pkg/fixtures/RequesterPtr.go index 7bd98c88..c3509039 100644 --- a/mocks/pkg/fixtures/RequesterPtr.go +++ b/mocks/pkg/fixtures/RequesterPtr.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // RequesterPtr is an autogenerated mock type for the RequesterPtr type type RequesterPtr struct { @@ -31,3 +35,12 @@ func (_m *RequesterPtr) Get(path string) (*string, error) { return r0, r1 } + +// NewRequesterPtr creates a new instance of RequesterPtr. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterPtr(t testing.TB) *RequesterPtr { + mock := &RequesterPtr{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/RequesterReturnElided.go b/mocks/pkg/fixtures/RequesterReturnElided.go index 10b6166a..15422658 100644 --- a/mocks/pkg/fixtures/RequesterReturnElided.go +++ b/mocks/pkg/fixtures/RequesterReturnElided.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // RequesterReturnElided is an autogenerated mock type for the RequesterReturnElided type type RequesterReturnElided struct { @@ -43,3 +47,12 @@ func (_m *RequesterReturnElided) Get(path string) (int, int, int, error) { return r0, r1, r2, r3 } + +// NewRequesterReturnElided creates a new instance of RequesterReturnElided. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterReturnElided(t testing.TB) *RequesterReturnElided { + mock := &RequesterReturnElided{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/RequesterSlice.go b/mocks/pkg/fixtures/RequesterSlice.go index 6c8cebdd..39b1788d 100644 --- a/mocks/pkg/fixtures/RequesterSlice.go +++ b/mocks/pkg/fixtures/RequesterSlice.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // RequesterSlice is an autogenerated mock type for the RequesterSlice type type RequesterSlice struct { @@ -31,3 +35,12 @@ func (_m *RequesterSlice) Get(path string) ([]string, error) { return r0, r1 } + +// NewRequesterSlice creates a new instance of RequesterSlice. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterSlice(t testing.TB) *RequesterSlice { + mock := &RequesterSlice{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/RequesterVariadic.go b/mocks/pkg/fixtures/RequesterVariadic.go index b2e3a76b..7049de7e 100644 --- a/mocks/pkg/fixtures/RequesterVariadic.go +++ b/mocks/pkg/fixtures/RequesterVariadic.go @@ -6,6 +6,8 @@ import ( io "io" mock "github.com/stretchr/testify/mock" + + testing "testing" ) // RequesterVariadic is an autogenerated mock type for the RequesterVariadic type @@ -86,3 +88,12 @@ func (_m *RequesterVariadic) Sprintf(format string, a ...interface{}) string { return r0 } + +// NewRequesterVariadic creates a new instance of RequesterVariadic. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterVariadic(t testing.TB) *RequesterVariadic { + mock := &RequesterVariadic{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/RequesterVariadicOneArgument.go b/mocks/pkg/fixtures/RequesterVariadicOneArgument.go index 6f3f0499..867dd987 100644 --- a/mocks/pkg/fixtures/RequesterVariadicOneArgument.go +++ b/mocks/pkg/fixtures/RequesterVariadicOneArgument.go @@ -6,6 +6,8 @@ import ( io "io" mock "github.com/stretchr/testify/mock" + + testing "testing" ) // RequesterVariadicOneArgument is an autogenerated mock type for the RequesterVariadic type @@ -68,3 +70,12 @@ func (_m *RequesterVariadicOneArgument) Sprintf(format string, a ...interface{}) return r0 } + +// NewRequesterVariadicOneArgument creates a new instance of RequesterVariadicOneArgument. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterVariadicOneArgument(t testing.TB) *RequesterVariadicOneArgument { + mock := &RequesterVariadicOneArgument{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/SendFunc.go b/mocks/pkg/fixtures/SendFunc.go index c2b4728d..86ddb626 100644 --- a/mocks/pkg/fixtures/SendFunc.go +++ b/mocks/pkg/fixtures/SendFunc.go @@ -6,6 +6,8 @@ import ( context "context" mock "github.com/stretchr/testify/mock" + + testing "testing" ) // SendFunc is an autogenerated mock type for the SendFunc type @@ -33,3 +35,12 @@ func (_m *SendFunc) Execute(ctx context.Context, data string) (int, error) { return r0, r1 } + +// NewSendFunc creates a new instance of SendFunc. It also registers a cleanup function to assert the mocks expectations. +func NewSendFunc(t testing.TB) *SendFunc { + mock := &SendFunc{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/Sibling.go b/mocks/pkg/fixtures/Sibling.go index 5fbeb4b0..41b37859 100644 --- a/mocks/pkg/fixtures/Sibling.go +++ b/mocks/pkg/fixtures/Sibling.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // Sibling is an autogenerated mock type for the Sibling type type Sibling struct { @@ -13,3 +17,12 @@ type Sibling struct { func (_m *Sibling) DoSomething() { _m.Called() } + +// NewSibling creates a new instance of Sibling. It also registers a cleanup function to assert the mocks expectations. +func NewSibling(t testing.TB) *Sibling { + mock := &Sibling{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/UsesOtherPkgIface.go b/mocks/pkg/fixtures/UsesOtherPkgIface.go index 0872ea25..807ffa13 100644 --- a/mocks/pkg/fixtures/UsesOtherPkgIface.go +++ b/mocks/pkg/fixtures/UsesOtherPkgIface.go @@ -5,6 +5,8 @@ package mocks import ( mock "github.com/stretchr/testify/mock" test "github.com/vektra/mockery/v2/pkg/fixtures" + + testing "testing" ) // UsesOtherPkgIface is an autogenerated mock type for the UsesOtherPkgIface type @@ -16,3 +18,12 @@ type UsesOtherPkgIface struct { func (_m *UsesOtherPkgIface) DoSomethingElse(obj test.Sibling) { _m.Called(obj) } + +// NewUsesOtherPkgIface creates a new instance of UsesOtherPkgIface. It also registers a cleanup function to assert the mocks expectations. +func NewUsesOtherPkgIface(t testing.TB) *UsesOtherPkgIface { + mock := &UsesOtherPkgIface{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/buildtag/comment/IfaceWithBuildTagInComment.go b/mocks/pkg/fixtures/buildtag/comment/IfaceWithBuildTagInComment.go index b4292115..68020eb9 100644 --- a/mocks/pkg/fixtures/buildtag/comment/IfaceWithBuildTagInComment.go +++ b/mocks/pkg/fixtures/buildtag/comment/IfaceWithBuildTagInComment.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + testing "testing" + + mock "github.com/stretchr/testify/mock" +) // IfaceWithBuildTagInComment is an autogenerated mock type for the IfaceWithBuildTagInComment type type IfaceWithBuildTagInComment struct { @@ -25,3 +29,12 @@ func (_m *IfaceWithBuildTagInComment) Sprintf(format string, a ...interface{}) s return r0 } + +// NewIfaceWithBuildTagInComment creates a new instance of IfaceWithBuildTagInComment. It also registers a cleanup function to assert the mocks expectations. +func NewIfaceWithBuildTagInComment(t testing.TB) *IfaceWithBuildTagInComment { + mock := &IfaceWithBuildTagInComment{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/buildtag/filename/IfaceWithBuildTagInFilename.go b/mocks/pkg/fixtures/buildtag/filename/IfaceWithBuildTagInFilename.go index 48a30f64..7dbeeff5 100644 --- a/mocks/pkg/fixtures/buildtag/filename/IfaceWithBuildTagInFilename.go +++ b/mocks/pkg/fixtures/buildtag/filename/IfaceWithBuildTagInFilename.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + testing "testing" + + mock "github.com/stretchr/testify/mock" +) // IfaceWithBuildTagInFilename is an autogenerated mock type for the IfaceWithBuildTagInFilename type type IfaceWithBuildTagInFilename struct { @@ -25,3 +29,12 @@ func (_m *IfaceWithBuildTagInFilename) Sprintf(format string, a ...interface{}) return r0 } + +// NewIfaceWithBuildTagInFilename creates a new instance of IfaceWithBuildTagInFilename. It also registers a cleanup function to assert the mocks expectations. +func NewIfaceWithBuildTagInFilename(t testing.TB) *IfaceWithBuildTagInFilename { + mock := &IfaceWithBuildTagInFilename{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/example_project/Root.go b/mocks/pkg/fixtures/example_project/Root.go index 5f827987..e39bbaa2 100644 --- a/mocks/pkg/fixtures/example_project/Root.go +++ b/mocks/pkg/fixtures/example_project/Root.go @@ -5,6 +5,8 @@ package mocks import ( mock "github.com/stretchr/testify/mock" foo "github.com/vektra/mockery/v2/pkg/fixtures/example_project/foo" + + testing "testing" ) // Root is an autogenerated mock type for the Root type @@ -39,3 +41,12 @@ func (_m *Root) ReturnsFoo() (foo.Foo, error) { func (_m *Root) TakesBaz(_a0 *foo.Baz) { _m.Called(_a0) } + +// NewRoot creates a new instance of Root. It also registers a cleanup function to assert the mocks expectations. +func NewRoot(t testing.TB) *Root { + mock := &Root{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/example_project/foo/Foo.go b/mocks/pkg/fixtures/example_project/foo/Foo.go index f1dfa886..c83fcbfb 100644 --- a/mocks/pkg/fixtures/example_project/foo/Foo.go +++ b/mocks/pkg/fixtures/example_project/foo/Foo.go @@ -5,6 +5,8 @@ package mocks import ( mock "github.com/stretchr/testify/mock" foo "github.com/vektra/mockery/v2/pkg/fixtures/example_project/foo" + + testing "testing" ) // Foo is an autogenerated mock type for the Foo type @@ -48,3 +50,12 @@ func (_m *Foo) GetBaz() (*foo.Baz, error) { return r0, r1 } + +// NewFoo creates a new instance of Foo. It also registers a cleanup function to assert the mocks expectations. +func NewFoo(t testing.TB) *Foo { + mock := &Foo{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/pkg/fixtures/requester_unexported.go b/mocks/pkg/fixtures/requester_unexported.go index 7d53b6a6..824bce23 100644 --- a/mocks/pkg/fixtures/requester_unexported.go +++ b/mocks/pkg/fixtures/requester_unexported.go @@ -2,7 +2,11 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + mock "github.com/stretchr/testify/mock" + + testing "testing" +) // requester_unexported is an autogenerated mock type for the requester_unexported type type requester_unexported struct { @@ -13,3 +17,12 @@ type requester_unexported struct { func (_m *requester_unexported) Get() { _m.Called() } + +// newRequester_unexported creates a new instance of requester_unexported. It also registers a cleanup function to assert the mocks expectations. +func newRequester_unexported(t testing.TB) *requester_unexported { + mock := &requester_unexported{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/fixtures/mocks/expecter.go b/pkg/fixtures/mocks/expecter.go index 7d44e4a1..e5eed8e1 100755 --- a/pkg/fixtures/mocks/expecter.go +++ b/pkg/fixtures/mocks/expecter.go @@ -2,7 +2,11 @@ package mocks -import "github.com/stretchr/testify/mock" +import ( + "testing" + + "github.com/stretchr/testify/mock" +) // ExpecterTest is an autogenerated mock type for the ExpecterTest type type ExpecterTest struct { @@ -226,3 +230,12 @@ func (_c *ExpecterTest_VariadicMany_Call) Return(_a0 error) *ExpecterTest_Variad _c.Call.Return(_a0) return _c } + +// NewExpecterTest creates a new instance of ExpecterTest. It also registers a cleanup function to assert the mocks expectations. +func NewExpecterTest(t testing.TB) *ExpecterTest { + mock := &ExpecterTest{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/generator.go b/pkg/generator.go index 60c0ce46..ec0d4ed4 100644 --- a/pkg/generator.go +++ b/pkg/generator.go @@ -61,6 +61,8 @@ func NewGenerator(ctx context.Context, c config.Config, iface *Interface, pkg st } g.addPackageImportWithName(ctx, "github.com/stretchr/testify/mock", "mock") + g.addPackageImportWithName(ctx, "testing", "testing") + return g } @@ -601,6 +603,8 @@ func (g *Generator) Generate(ctx context.Context) error { } } + g.generateConstructor() + return nil } @@ -699,6 +703,32 @@ func (_c *{{.CallStruct}}) Return({{range .Returns.Params}}{{.}},{{end}}) *{{.Ca `) } +func (g *Generator) generateConstructor() { + const constructor = ` +// %[1]s creates a new instance of %[2]s. It also registers a cleanup function to assert the mocks expectations. +func %[1]s(t testing.TB) *%[2]s { + mock := &%[2]s{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} +` + + funcFirstLetter := "N" + mockName := g.mockName() + + for _, firstLetter := range mockName { + if unicode.IsLower(firstLetter) { + funcFirstLetter = "n" + } + + break + } + + g.printf(constructor, funcFirstLetter+"ew"+upperFirstOnly(mockName), mockName) +} + // generateCalled returns the Mock.Called invocation string and, if necessary, prints the // steps to prepare its argument list. // diff --git a/pkg/generator_test.go b/pkg/generator_test.go index 8ed05f5e..fd2faec9 100644 --- a/pkg/generator_test.go +++ b/pkg/generator_test.go @@ -80,10 +80,11 @@ func (s *GeneratorSuite) checkGenerationWithConfig( expectedLines := strings.Split(expected, "\n") actualLines := strings.Split(string(actual), "\n") - // Error out at first unmatched line - for i := range actualLines { - s.Equal(expectedLines[i], actualLines[i]) - } + s.Equal( + expectedLines, actualLines, + "The generator produced unexpected output.", + ) + return generator } @@ -150,6 +151,15 @@ func (_m *Requester) Get(path string) (string, error) { return r0, r1 } + +// NewRequester creates a new instance of Requester. It also registers a cleanup function to assert the mocks expectations. +func NewRequester(t testing.TB) *Requester { + mock := &Requester{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration(testFile, "Requester", false, "", expected) } @@ -211,6 +221,15 @@ func (_c *Requester_Get_Call) Return(_a0 string, _a1 error) *Requester_Get_Call _c.Call.Return(_a0, _a1) return _c } + +// NewRequester creates a new instance of Requester. It also registers a cleanup function to assert the mocks expectations. +func NewRequester(t testing.TB) *Requester { + mock := &Requester{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` cfg := config.Config{ @@ -270,6 +289,15 @@ func (_m *SendFunc) Execute(ctx context.Context, data string) (int, error) { return r0, r1 } + +// NewSendFunc creates a new instance of SendFunc. It also registers a cleanup function to assert the mocks expectations. +func NewSendFunc(t testing.TB) *SendFunc { + mock := &SendFunc{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("function.go", "SendFunc", false, "", expected) } @@ -293,6 +321,15 @@ func (_m *Requester2) Get(path string) error { return r0 } + +// NewRequester2 creates a new instance of Requester2. It also registers a cleanup function to assert the mocks expectations. +func NewRequester2(t testing.TB) *Requester2 { + mock := &Requester2{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration(testFile2, "Requester2", false, "", expected) } @@ -316,6 +353,15 @@ func (_m *Requester3) Get() error { return r0 } + +// NewRequester3 creates a new instance of Requester3. It also registers a cleanup function to assert the mocks expectations. +func NewRequester3(t testing.TB) *Requester3 { + mock := &Requester3{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("requester3.go", "Requester3", false, "", expected) } @@ -330,6 +376,15 @@ type Requester4 struct { func (_m *Requester4) Get() { _m.Called() } + +// NewRequester4 creates a new instance of Requester4. It also registers a cleanup function to assert the mocks expectations. +func NewRequester4(t testing.TB) *Requester4 { + mock := &Requester4{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("requester4.go", "Requester4", false, "", expected) } @@ -344,6 +399,15 @@ type mockRequester_unexported struct { func (_m *mockRequester_unexported) Get() { _m.Called() } + +// newMockRequester_unexported creates a new instance of mockRequester_unexported. It also registers a cleanup function to assert the mocks expectations. +func newMockRequester_unexported(t testing.TB) *mockRequester_unexported { + mock := &mockRequester_unexported{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("requester_unexported.go", "requester_unexported", true, "", expected) } @@ -358,6 +422,15 @@ type Mockrequester_unexported struct { func (_m *Mockrequester_unexported) Get() { _m.Called() } + +// NewMockrequester_unexported creates a new instance of Mockrequester_unexported. It also registers a cleanup function to assert the mocks expectations. +func NewMockrequester_unexported(t testing.TB) *Mockrequester_unexported { + mock := &Mockrequester_unexported{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` generator := NewGenerator( s.ctx, config.Config{ @@ -391,6 +464,15 @@ type Requester_unexported struct { func (_m *Requester_unexported) Get() { _m.Called() } + +// NewRequester_unexported creates a new instance of Requester_unexported. It also registers a cleanup function to assert the mocks expectations. +func NewRequester_unexported(t testing.TB) *Requester_unexported { + mock := &Requester_unexported{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` generator := NewGenerator( s.ctx, config.Config{ @@ -420,6 +502,7 @@ func (s *GeneratorSuite) TestGeneratorPrologue() { import mock "github.com/stretchr/testify/mock" import test "github.com/vektra/mockery/v2/pkg/fixtures" +import testing "testing" ` s.checkPrologueGeneration(generator, expected) @@ -432,6 +515,7 @@ func (s *GeneratorSuite) TestGeneratorPrologueWithImports() { import http "net/http" import mock "github.com/stretchr/testify/mock" import test "github.com/vektra/mockery/v2/pkg/fixtures" +import testing "testing" ` s.checkPrologueGeneration(generator, expected) @@ -446,6 +530,7 @@ import fixtureshttp "github.com/vektra/mockery/v2/pkg/fixtures/http" import http "net/http" import mock "github.com/stretchr/testify/mock" import test "github.com/vektra/mockery/v2/pkg/fixtures" +import testing "testing" ` s.checkPrologueGeneration(generator, expected) @@ -527,6 +612,15 @@ func (_m *RequesterIface) Get() io.Reader { return r0 } + +// NewRequesterIface creates a new instance of RequesterIface. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterIface(t testing.TB) *RequesterIface { + mock := &RequesterIface{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("requester_iface.go", "RequesterIface", false, "", expected) } @@ -559,6 +653,15 @@ func (_m *RequesterPtr) Get(path string) (*string, error) { return r0, r1 } + +// NewRequesterPtr creates a new instance of RequesterPtr. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterPtr(t testing.TB) *RequesterPtr { + mock := &RequesterPtr{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("requester_ptr.go", "RequesterPtr", false, "", expected) } @@ -591,6 +694,15 @@ func (_m *RequesterSlice) Get(path string) ([]string, error) { return r0, r1 } + +// NewRequesterSlice creates a new instance of RequesterSlice. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterSlice(t testing.TB) *RequesterSlice { + mock := &RequesterSlice{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("requester_slice.go", "RequesterSlice", false, "", expected) } @@ -623,6 +735,15 @@ func (_m *RequesterArray) Get(path string) ([2]string, error) { return r0, r1 } + +// NewRequesterArray creates a new instance of RequesterArray. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterArray(t testing.TB) *RequesterArray { + mock := &RequesterArray{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("requester_array.go", "RequesterArray", false, "", expected) } @@ -653,6 +774,15 @@ func (_m *RequesterNS) Get(path string) (http.Response, error) { return r0, r1 } + +// NewRequesterNS creates a new instance of RequesterNS. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterNS(t testing.TB) *RequesterNS { + mock := &RequesterNS{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("requester_ns.go", "RequesterNS", false, "", expected) } @@ -678,6 +808,15 @@ func (_m *RequesterArgSameAsImport) Get(_a0 string) *json.RawMessage { return r0 } + +// NewRequesterArgSameAsImport creates a new instance of RequesterArgSameAsImport. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterArgSameAsImport(t testing.TB) *RequesterArgSameAsImport { + mock := &RequesterArgSameAsImport{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("requester_arg_same_as_import.go", "RequesterArgSameAsImport", false, "", expected) } @@ -703,6 +842,15 @@ func (_m *RequesterArgSameAsNamedImport) Get(_a0 string) *json.RawMessage { return r0 } + +// NewRequesterArgSameAsNamedImport creates a new instance of RequesterArgSameAsNamedImport. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterArgSameAsNamedImport(t testing.TB) *RequesterArgSameAsNamedImport { + mock := &RequesterArgSameAsNamedImport{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("requester_arg_same_as_named_import.go", "RequesterArgSameAsNamedImport", false, "", expected) } @@ -717,6 +865,15 @@ type RequesterArgSameAsPkg struct { func (_m *RequesterArgSameAsPkg) Get(_a0 string) { _m.Called(_a0) } + +// NewRequesterArgSameAsPkg creates a new instance of RequesterArgSameAsPkg. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterArgSameAsPkg(t testing.TB) *RequesterArgSameAsPkg { + mock := &RequesterArgSameAsPkg{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("requester_arg_same_as_pkg.go", "RequesterArgSameAsPkg", false, "", expected) } @@ -751,6 +908,15 @@ func (_m *KeyManager) GetKey(_a0 string, _a1 uint16) ([]byte, *test.Err) { return r0, r1 } + +// NewKeyManager creates a new instance of KeyManager. It also registers a cleanup function to assert the mocks expectations. +func NewKeyManager(t testing.TB) *KeyManager { + mock := &KeyManager{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("custom_error.go", "KeyManager", false, "", expected) } @@ -774,6 +940,15 @@ func (_m *RequesterElided) Get(path string, url string) error { return r0 } + +// NewRequesterElided creates a new instance of RequesterElided. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterElided(t testing.TB) *RequesterElided { + mock := &RequesterElided{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("requester_elided.go", "RequesterElided", false, "", expected) } @@ -818,6 +993,15 @@ func (_m *RequesterReturnElided) Get(path string) (int, int, int, error) { return r0, r1, r2, r3 } + +// NewRequesterReturnElided creates a new instance of RequesterReturnElided. It also registers a cleanup function to assert the mocks expectations. +func NewRequesterReturnElided(t testing.TB) *RequesterReturnElided { + mock := &RequesterReturnElided{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("requester_ret_elided.go", "RequesterReturnElided", false, "", expected) } @@ -987,6 +1171,15 @@ func (_m *Fooer) Foo(f func(string) string) error { return r0 } + +// NewFooer creates a new instance of Fooer. It also registers a cleanup function to assert the mocks expectations. +func NewFooer(t testing.TB) *Fooer { + mock := &Fooer{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("func_type.go", "Fooer", false, "", expected) } @@ -1044,6 +1237,15 @@ func (_m *AsyncProducer) Whatever() chan bool { return r0 } + +// NewAsyncProducer creates a new instance of AsyncProducer. It also registers a cleanup function to assert the mocks expectations. +func NewAsyncProducer(t testing.TB) *AsyncProducer { + mock := &AsyncProducer{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("async.go", "AsyncProducer", false, "", expected) } @@ -1074,6 +1276,15 @@ func (_m *MyReader) Read(p []byte) (int, error) { return r0, r1 } + +// NewMyReader creates a new instance of MyReader. It also registers a cleanup function to assert the mocks expectations. +func NewMyReader(t testing.TB) *MyReader { + mock := &MyReader{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("io_import.go", "MyReader", false, "", expected) } @@ -1120,6 +1331,15 @@ func (_m *ConsulLock) Unlock() error { return r0 } + +// NewConsulLock creates a new instance of ConsulLock. It also registers a cleanup function to assert the mocks expectations. +func NewConsulLock(t testing.TB) *ConsulLock { + mock := &ConsulLock{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("consul.go", "ConsulLock", false, "", expected) } @@ -1143,6 +1363,15 @@ func (_m *Blank) Create(x interface{}) error { return r0 } + +// NewBlank creates a new instance of Blank. It also registers a cleanup function to assert the mocks expectations. +func NewBlank(t testing.TB) *Blank { + mock := &Blank{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("empty_interface.go", "Blank", false, "", expected) } @@ -1166,6 +1395,15 @@ func (_m *MapFunc) Get(m map[string]func(string) string) error { return r0 } + +// NewMapFunc creates a new instance of MapFunc. It also registers a cleanup function to assert the mocks expectations. +func NewMapFunc(t testing.TB) *MapFunc { + mock := &MapFunc{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("map_func.go", "MapFunc", false, "", expected) } @@ -1180,6 +1418,15 @@ type UsesOtherPkgIface struct { func (_m *UsesOtherPkgIface) DoSomethingElse(obj test.Sibling) { _m.Called(obj) } + +// NewUsesOtherPkgIface creates a new instance of UsesOtherPkgIface. It also registers a cleanup function to assert the mocks expectations. +func NewUsesOtherPkgIface(t testing.TB) *UsesOtherPkgIface { + mock := &UsesOtherPkgIface{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("mock_method_uses_pkg_iface.go", "UsesOtherPkgIface", false, "", expected) } @@ -1194,6 +1441,15 @@ type MockUsesOtherPkgIface struct { func (_m *MockUsesOtherPkgIface) DoSomethingElse(obj Sibling) { _m.Called(obj) } + +// NewMockUsesOtherPkgIface creates a new instance of MockUsesOtherPkgIface. It also registers a cleanup function to assert the mocks expectations. +func NewMockUsesOtherPkgIface(t testing.TB) *MockUsesOtherPkgIface { + mock := &MockUsesOtherPkgIface{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("mock_method_uses_pkg_iface.go", "UsesOtherPkgIface", true, "", expected) } @@ -1233,6 +1489,15 @@ func (_m *Example) B(_a0 string) fixtureshttp.MyStruct { return r0 } + +// NewExample creates a new instance of Example. It also registers a cleanup function to assert the mocks expectations. +func NewExample(t testing.TB) *Example { + mock := &Example{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("same_name_imports.go", "Example", false, "", expected) } @@ -1263,6 +1528,15 @@ func (_m *MapToInterface) Foo(arg1 ...map[string]interface{}) { _ca = append(_ca, _va...) _m.Called(_ca...) } + +// NewMapToInterface creates a new instance of MapToInterface. It also registers a cleanup function to assert the mocks expectations. +func NewMapToInterface(t testing.TB) *MapToInterface { + mock := &MapToInterface{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("MapToInterface.go", "MapToInterface", false, "", expected) @@ -1287,6 +1561,15 @@ func (_m *FuncArgsCollision) Foo(ret interface{}) error { return r0 } + +// NewFuncArgsCollision creates a new instance of FuncArgsCollision. It also registers a cleanup function to assert the mocks expectations. +func NewFuncArgsCollision(t testing.TB) *FuncArgsCollision { + mock := &FuncArgsCollision{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("func_args_collision.go", "FuncArgsCollision", false, "", expected) } @@ -1331,6 +1614,15 @@ func (_m *ImportsSameAsPackage) B() fixtures.KeyManager { func (_m *ImportsSameAsPackage) C(_a0 fixtures.C) { _m.Called(_a0) } + +// NewImportsSameAsPackage creates a new instance of ImportsSameAsPackage. It also registers a cleanup function to assert the mocks expectations. +func NewImportsSameAsPackage(t testing.TB) *ImportsSameAsPackage { + mock := &ImportsSameAsPackage{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("imports_same_as_package.go", "ImportsSameAsPackage", false, "", expected) } @@ -1344,6 +1636,7 @@ func (s *GeneratorSuite) TestPrologueWithImportSameAsLocalPackage() { import fixtures "` + generator.iface.QualifiedName + `" import mock "github.com/stretchr/testify/mock" import test "github.com/vektra/mockery/v2/pkg/fixtures/test" +import testing "testing" ` s.checkPrologueGeneration(generator, expected) @@ -1359,6 +1652,7 @@ import fixtureshttp "github.com/vektra/mockery/v2/pkg/fixtures/http" import http "net/http" import mock "github.com/stretchr/testify/mock" import test "github.com/vektra/mockery/v2/pkg/fixtures" +import testing "testing" ` @@ -1391,6 +1685,15 @@ func (_m *A) Call() (test.B, error) { return r0, r1 } + +// NewA creates a new instance of A. It also registers a cleanup function to assert the mocks expectations. +func NewA(t testing.TB) *A { + mock := &A{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration("struct_value.go", "A", false, "", expected) } @@ -1414,6 +1717,15 @@ func (_m *Requester2OverrideName) Get(path string) error { return r0 } + +// NewRequester2OverrideName creates a new instance of Requester2OverrideName. It also registers a cleanup function to assert the mocks expectations. +func NewRequester2OverrideName(t testing.TB) *Requester2OverrideName { + mock := &Requester2OverrideName{} + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} ` s.checkGeneration(testFile2, "Requester2", false, "Requester2OverrideName", expected) } @@ -1431,12 +1743,14 @@ func (s *GeneratorSuite) TestKeepTreeInPackageCombined() { import example_project "github.com/vektra/mockery/v2/pkg/fixtures/example_project" import foo "github.com/vektra/mockery/v2/pkg/fixtures/example_project/foo" import mock "github.com/stretchr/testify/mock" +import testing "testing" `}, {path: filepath.Join("example_project", "foo", "foo.go"), name: "Foo", expected: `package foo import foo "github.com/vektra/mockery/v2/pkg/fixtures/example_project/foo" import mock "github.com/stretchr/testify/mock" +import testing "testing" `}, }