From 53960fc89f446e3012bbabad8cd8629245c4b412 Mon Sep 17 00:00:00 2001 From: Julien Salleyron Date: Wed, 7 Feb 2024 11:33:01 +0100 Subject: [PATCH] Adds tests. --- testdata/src/a/d/d.go | 9 +++ testdata/src/a/e/v2/e.go | 14 ++++ testdata/src/a/mock_gen_test.go | 106 +++++++++++++++++++++++++ testdata/src/a/mock_gen_test.go.golden | 106 +++++++++++++++++++++++++ testdata/src/a/mock_test.go | 1 + 5 files changed, 236 insertions(+) create mode 100644 testdata/src/a/d/d.go create mode 100644 testdata/src/a/e/v2/e.go diff --git a/testdata/src/a/d/d.go b/testdata/src/a/d/d.go new file mode 100644 index 0000000..8d23fa4 --- /dev/null +++ b/testdata/src/a/d/d.go @@ -0,0 +1,9 @@ +package c + +import ( + "a/e/v2" +) + +type Cherry interface { + V2Carrot() e.V2Carrot +} diff --git a/testdata/src/a/e/v2/e.go b/testdata/src/a/e/v2/e.go new file mode 100644 index 0000000..5223ea2 --- /dev/null +++ b/testdata/src/a/e/v2/e.go @@ -0,0 +1,14 @@ +package e + +import ( + "a/c" +) + +type V2Carrot interface { + Bar(string) *V2Potato + Bur(string) *c.Cherry +} + +type V2Potato struct { + Name string +} diff --git a/testdata/src/a/mock_gen_test.go b/testdata/src/a/mock_gen_test.go index 62834ef..7cdce94 100644 --- a/testdata/src/a/mock_gen_test.go +++ b/testdata/src/a/mock_gen_test.go @@ -5,6 +5,7 @@ package a import ( "a/b" "a/c" + "a/e/v2" "bytes" "context" "testing" @@ -3395,3 +3396,108 @@ func (_c *orangeJuiceCall) OnJuice() *orangeJuiceCall { func (_c *orangeJuiceCall) OnJuiceRaw() *orangeJuiceCall { return _c.Parent.OnJuiceRaw() } + +// cherryMock mock of Cherry. +type cherryMock struct{ mock.Mock } + +// newCherryMock creates a new cherryMock. +func newCherryMock(tb testing.TB) *cherryMock { + tb.Helper() + + m := &cherryMock{} + m.Mock.Test(tb) + + tb.Cleanup(func() { m.AssertExpectations(tb) }) + + return m +} + +func (_m *cherryMock) V2Carrot() e.V2Carrot { + _ret := _m.Called() + + if _rf, ok := _ret.Get(0).(func() e.V2Carrot); ok { + return _rf() + } + + _ra0, _ := _ret.Get(0).(e.V2Carrot) + + return _ra0 +} + +func (_m *cherryMock) OnV2Carrot() *cherryV2CarrotCall { + return &cherryV2CarrotCall{Call: _m.Mock.On("V2Carrot"), Parent: _m} +} + +func (_m *cherryMock) OnV2CarrotRaw() *cherryV2CarrotCall { + return &cherryV2CarrotCall{Call: _m.Mock.On("V2Carrot"), Parent: _m} +} + +type cherryV2CarrotCall struct { + *mock.Call + Parent *cherryMock +} + +func (_c *cherryV2CarrotCall) Panic(msg string) *cherryV2CarrotCall { + _c.Call = _c.Call.Panic(msg) + return _c +} + +func (_c *cherryV2CarrotCall) Once() *cherryV2CarrotCall { + _c.Call = _c.Call.Once() + return _c +} + +func (_c *cherryV2CarrotCall) Twice() *cherryV2CarrotCall { + _c.Call = _c.Call.Twice() + return _c +} + +func (_c *cherryV2CarrotCall) Times(i int) *cherryV2CarrotCall { + _c.Call = _c.Call.Times(i) + return _c +} + +func (_c *cherryV2CarrotCall) WaitUntil(w <-chan time.Time) *cherryV2CarrotCall { + _c.Call = _c.Call.WaitUntil(w) + return _c +} + +func (_c *cherryV2CarrotCall) After(d time.Duration) *cherryV2CarrotCall { + _c.Call = _c.Call.After(d) + return _c +} + +func (_c *cherryV2CarrotCall) Run(fn func(args mock.Arguments)) *cherryV2CarrotCall { + _c.Call = _c.Call.Run(fn) + return _c +} + +func (_c *cherryV2CarrotCall) Maybe() *cherryV2CarrotCall { + _c.Call = _c.Call.Maybe() + return _c +} + +func (_c *cherryV2CarrotCall) TypedReturns(a e.V2Carrot) *cherryV2CarrotCall { + _c.Call = _c.Return(a) + return _c +} + +func (_c *cherryV2CarrotCall) ReturnsFn(fn func() e.V2Carrot) *cherryV2CarrotCall { + _c.Call = _c.Return(fn) + return _c +} + +func (_c *cherryV2CarrotCall) TypedRun(fn func()) *cherryV2CarrotCall { + _c.Call = _c.Call.Run(func(args mock.Arguments) { + fn() + }) + return _c +} + +func (_c *cherryV2CarrotCall) OnV2Carrot() *cherryV2CarrotCall { + return _c.Parent.OnV2Carrot() +} + +func (_c *cherryV2CarrotCall) OnV2CarrotRaw() *cherryV2CarrotCall { + return _c.Parent.OnV2CarrotRaw() +} diff --git a/testdata/src/a/mock_gen_test.go.golden b/testdata/src/a/mock_gen_test.go.golden index 62834ef..7cdce94 100644 --- a/testdata/src/a/mock_gen_test.go.golden +++ b/testdata/src/a/mock_gen_test.go.golden @@ -5,6 +5,7 @@ package a import ( "a/b" "a/c" + "a/e/v2" "bytes" "context" "testing" @@ -3395,3 +3396,108 @@ func (_c *orangeJuiceCall) OnJuice() *orangeJuiceCall { func (_c *orangeJuiceCall) OnJuiceRaw() *orangeJuiceCall { return _c.Parent.OnJuiceRaw() } + +// cherryMock mock of Cherry. +type cherryMock struct{ mock.Mock } + +// newCherryMock creates a new cherryMock. +func newCherryMock(tb testing.TB) *cherryMock { + tb.Helper() + + m := &cherryMock{} + m.Mock.Test(tb) + + tb.Cleanup(func() { m.AssertExpectations(tb) }) + + return m +} + +func (_m *cherryMock) V2Carrot() e.V2Carrot { + _ret := _m.Called() + + if _rf, ok := _ret.Get(0).(func() e.V2Carrot); ok { + return _rf() + } + + _ra0, _ := _ret.Get(0).(e.V2Carrot) + + return _ra0 +} + +func (_m *cherryMock) OnV2Carrot() *cherryV2CarrotCall { + return &cherryV2CarrotCall{Call: _m.Mock.On("V2Carrot"), Parent: _m} +} + +func (_m *cherryMock) OnV2CarrotRaw() *cherryV2CarrotCall { + return &cherryV2CarrotCall{Call: _m.Mock.On("V2Carrot"), Parent: _m} +} + +type cherryV2CarrotCall struct { + *mock.Call + Parent *cherryMock +} + +func (_c *cherryV2CarrotCall) Panic(msg string) *cherryV2CarrotCall { + _c.Call = _c.Call.Panic(msg) + return _c +} + +func (_c *cherryV2CarrotCall) Once() *cherryV2CarrotCall { + _c.Call = _c.Call.Once() + return _c +} + +func (_c *cherryV2CarrotCall) Twice() *cherryV2CarrotCall { + _c.Call = _c.Call.Twice() + return _c +} + +func (_c *cherryV2CarrotCall) Times(i int) *cherryV2CarrotCall { + _c.Call = _c.Call.Times(i) + return _c +} + +func (_c *cherryV2CarrotCall) WaitUntil(w <-chan time.Time) *cherryV2CarrotCall { + _c.Call = _c.Call.WaitUntil(w) + return _c +} + +func (_c *cherryV2CarrotCall) After(d time.Duration) *cherryV2CarrotCall { + _c.Call = _c.Call.After(d) + return _c +} + +func (_c *cherryV2CarrotCall) Run(fn func(args mock.Arguments)) *cherryV2CarrotCall { + _c.Call = _c.Call.Run(fn) + return _c +} + +func (_c *cherryV2CarrotCall) Maybe() *cherryV2CarrotCall { + _c.Call = _c.Call.Maybe() + return _c +} + +func (_c *cherryV2CarrotCall) TypedReturns(a e.V2Carrot) *cherryV2CarrotCall { + _c.Call = _c.Return(a) + return _c +} + +func (_c *cherryV2CarrotCall) ReturnsFn(fn func() e.V2Carrot) *cherryV2CarrotCall { + _c.Call = _c.Return(fn) + return _c +} + +func (_c *cherryV2CarrotCall) TypedRun(fn func()) *cherryV2CarrotCall { + _c.Call = _c.Call.Run(func(args mock.Arguments) { + fn() + }) + return _c +} + +func (_c *cherryV2CarrotCall) OnV2Carrot() *cherryV2CarrotCall { + return _c.Parent.OnV2Carrot() +} + +func (_c *cherryV2CarrotCall) OnV2CarrotRaw() *cherryV2CarrotCall { + return _c.Parent.OnV2CarrotRaw() +} diff --git a/testdata/src/a/mock_test.go b/testdata/src/a/mock_test.go index dc25eb6..1db79c8 100644 --- a/testdata/src/a/mock_test.go +++ b/testdata/src/a/mock_test.go @@ -11,6 +11,7 @@ import ( // mocktail:b.Carrot // mocktail-:fmt.Stringer // mocktail:Orange +// mocktail:d.Cherry func TestName(t *testing.T) { var s Pineapple = newPineappleMock(t).