diff --git a/template.go b/template.go index 961616a..f2629bf 100644 --- a/template.go +++ b/template.go @@ -209,6 +209,7 @@ const ( } {{end}} + // Times sets number of times {{$.Interface.Name}}.{{$method.Name}} should be invoked func ({{$m}} *m{{$mock}}{{$method.Name}}{{(paramsRef)}}) Times(n uint64) *m{{$mock}}{{$method.Name}}{{(paramsRef)}} { if n == 0 { {{$m}}.mock.t.Fatalf("Times of {{$mock}}.{{$method.Name}} mock can not be zero") @@ -219,13 +220,9 @@ const ( func ({{$m}} *m{{$mock}}{{$method.Name}}{{(paramsRef)}}) invocationsDone() bool { if len({{$m}}.expectations) == 0 && {{$m}}.defaultExpectation == nil && {{$m}}.mock.func{{$method.Name}} == nil { - // does not need to check invocations if no expectations, defaultExpectation or func{{$method.Name}} set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&{{$m}}.mock.after{{$method.Name}}Counter) expectedInvocations := mm_atomic.LoadUint64(&{{$m}}.expectedInvocations) diff --git a/tests/actor_mock.go b/tests/actor_mock.go index 30c3b31..a88b2c0 100644 --- a/tests/actor_mock.go +++ b/tests/actor_mock.go @@ -205,6 +205,7 @@ func (e *ActorMockActionExpectation) Then(i1 int, err error) *ActorMock { return e.mock } +// Times sets number of times actor.Action should be invoked func (mmAction *mActorMockAction) Times(n uint64) *mActorMockAction { if n == 0 { mmAction.mock.t.Fatalf("Times of ActorMock.Action mock can not be zero") @@ -215,13 +216,9 @@ func (mmAction *mActorMockAction) Times(n uint64) *mActorMockAction { func (mmAction *mActorMockAction) invocationsDone() bool { if len(mmAction.expectations) == 0 && mmAction.defaultExpectation == nil && mmAction.mock.funcAction == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcAction set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmAction.mock.afterActionCounter) expectedInvocations := mm_atomic.LoadUint64(&mmAction.expectedInvocations) diff --git a/tests/context_accepter_mock.go b/tests/context_accepter_mock.go index d6f7b52..89d5ba8 100644 --- a/tests/context_accepter_mock.go +++ b/tests/context_accepter_mock.go @@ -173,6 +173,7 @@ func (mmAcceptContext *mContextAccepterMockAcceptContext) Set(f func(ctx context return mmAcceptContext.mock } +// Times sets number of times contextAccepter.AcceptContext should be invoked func (mmAcceptContext *mContextAccepterMockAcceptContext) Times(n uint64) *mContextAccepterMockAcceptContext { if n == 0 { mmAcceptContext.mock.t.Fatalf("Times of ContextAccepterMock.AcceptContext mock can not be zero") @@ -183,13 +184,9 @@ func (mmAcceptContext *mContextAccepterMockAcceptContext) Times(n uint64) *mCont func (mmAcceptContext *mContextAccepterMockAcceptContext) invocationsDone() bool { if len(mmAcceptContext.expectations) == 0 && mmAcceptContext.defaultExpectation == nil && mmAcceptContext.mock.funcAcceptContext == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcAcceptContext set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmAcceptContext.mock.afterAcceptContextCounter) expectedInvocations := mm_atomic.LoadUint64(&mmAcceptContext.expectedInvocations) @@ -475,6 +472,7 @@ func (e *ContextAccepterMockAcceptContextWithOtherArgsExpectation) Then(i2 int, return e.mock } +// Times sets number of times contextAccepter.AcceptContextWithOtherArgs should be invoked func (mmAcceptContextWithOtherArgs *mContextAccepterMockAcceptContextWithOtherArgs) Times(n uint64) *mContextAccepterMockAcceptContextWithOtherArgs { if n == 0 { mmAcceptContextWithOtherArgs.mock.t.Fatalf("Times of ContextAccepterMock.AcceptContextWithOtherArgs mock can not be zero") @@ -485,13 +483,9 @@ func (mmAcceptContextWithOtherArgs *mContextAccepterMockAcceptContextWithOtherAr func (mmAcceptContextWithOtherArgs *mContextAccepterMockAcceptContextWithOtherArgs) invocationsDone() bool { if len(mmAcceptContextWithOtherArgs.expectations) == 0 && mmAcceptContextWithOtherArgs.defaultExpectation == nil && mmAcceptContextWithOtherArgs.mock.funcAcceptContextWithOtherArgs == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcAcceptContextWithOtherArgs set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmAcceptContextWithOtherArgs.mock.afterAcceptContextWithOtherArgsCounter) expectedInvocations := mm_atomic.LoadUint64(&mmAcceptContextWithOtherArgs.expectedInvocations) @@ -783,6 +777,7 @@ func (e *ContextAccepterMockAcceptContextWithStructArgsExpectation) Then(i1 int, return e.mock } +// Times sets number of times contextAccepter.AcceptContextWithStructArgs should be invoked func (mmAcceptContextWithStructArgs *mContextAccepterMockAcceptContextWithStructArgs) Times(n uint64) *mContextAccepterMockAcceptContextWithStructArgs { if n == 0 { mmAcceptContextWithStructArgs.mock.t.Fatalf("Times of ContextAccepterMock.AcceptContextWithStructArgs mock can not be zero") @@ -793,13 +788,9 @@ func (mmAcceptContextWithStructArgs *mContextAccepterMockAcceptContextWithStruct func (mmAcceptContextWithStructArgs *mContextAccepterMockAcceptContextWithStructArgs) invocationsDone() bool { if len(mmAcceptContextWithStructArgs.expectations) == 0 && mmAcceptContextWithStructArgs.defaultExpectation == nil && mmAcceptContextWithStructArgs.mock.funcAcceptContextWithStructArgs == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcAcceptContextWithStructArgs set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmAcceptContextWithStructArgs.mock.afterAcceptContextWithStructArgsCounter) expectedInvocations := mm_atomic.LoadUint64(&mmAcceptContextWithStructArgs.expectedInvocations) diff --git a/tests/formatter_mock.go b/tests/formatter_mock.go index 0eccaec..6c73363 100644 --- a/tests/formatter_mock.go +++ b/tests/formatter_mock.go @@ -204,6 +204,7 @@ func (e *FormatterMockFormatExpectation) Then(s2 string) *FormatterMock { return e.mock } +// Times sets number of times Formatter.Format should be invoked func (mmFormat *mFormatterMockFormat) Times(n uint64) *mFormatterMockFormat { if n == 0 { mmFormat.mock.t.Fatalf("Times of FormatterMock.Format mock can not be zero") @@ -214,13 +215,9 @@ func (mmFormat *mFormatterMockFormat) Times(n uint64) *mFormatterMockFormat { func (mmFormat *mFormatterMockFormat) invocationsDone() bool { if len(mmFormat.expectations) == 0 && mmFormat.defaultExpectation == nil && mmFormat.mock.funcFormat == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcFormat set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmFormat.mock.afterFormatCounter) expectedInvocations := mm_atomic.LoadUint64(&mmFormat.expectedInvocations) diff --git a/tests/generic_complex_union.go b/tests/generic_complex_union.go index f988a22..42d66ae 100644 --- a/tests/generic_complex_union.go +++ b/tests/generic_complex_union.go @@ -154,6 +154,7 @@ func (mmName *mGenericComplexUnionMockName[T]) Set(f func(t1 T)) *GenericComplex return mmName.mock } +// Times sets number of times genericComplexUnion.Name should be invoked func (mmName *mGenericComplexUnionMockName[T]) Times(n uint64) *mGenericComplexUnionMockName[T] { if n == 0 { mmName.mock.t.Fatalf("Times of GenericComplexUnionMock.Name mock can not be zero") @@ -164,13 +165,9 @@ func (mmName *mGenericComplexUnionMockName[T]) Times(n uint64) *mGenericComplexU func (mmName *mGenericComplexUnionMockName[T]) invocationsDone() bool { if len(mmName.expectations) == 0 && mmName.defaultExpectation == nil && mmName.mock.funcName == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcName set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmName.mock.afterNameCounter) expectedInvocations := mm_atomic.LoadUint64(&mmName.expectedInvocations) diff --git a/tests/generic_in.go b/tests/generic_in.go index 496e73c..f77e549 100644 --- a/tests/generic_in.go +++ b/tests/generic_in.go @@ -154,6 +154,7 @@ func (mmName *mGenericInMockName[T]) Set(f func(t1 T)) *GenericInMock[T] { return mmName.mock } +// Times sets number of times genericIn.Name should be invoked func (mmName *mGenericInMockName[T]) Times(n uint64) *mGenericInMockName[T] { if n == 0 { mmName.mock.t.Fatalf("Times of GenericInMock.Name mock can not be zero") @@ -164,13 +165,9 @@ func (mmName *mGenericInMockName[T]) Times(n uint64) *mGenericInMockName[T] { func (mmName *mGenericInMockName[T]) invocationsDone() bool { if len(mmName.expectations) == 0 && mmName.defaultExpectation == nil && mmName.mock.funcName == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcName set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmName.mock.afterNameCounter) expectedInvocations := mm_atomic.LoadUint64(&mmName.expectedInvocations) diff --git a/tests/generic_inline_union.go b/tests/generic_inline_union.go index 9e3771b..59b69c2 100644 --- a/tests/generic_inline_union.go +++ b/tests/generic_inline_union.go @@ -154,6 +154,7 @@ func (mmName *mGenericInlineUnionMockName[T]) Set(f func(t1 T)) *GenericInlineUn return mmName.mock } +// Times sets number of times genericInlineUnion.Name should be invoked func (mmName *mGenericInlineUnionMockName[T]) Times(n uint64) *mGenericInlineUnionMockName[T] { if n == 0 { mmName.mock.t.Fatalf("Times of GenericInlineUnionMock.Name mock can not be zero") @@ -164,13 +165,9 @@ func (mmName *mGenericInlineUnionMockName[T]) Times(n uint64) *mGenericInlineUni func (mmName *mGenericInlineUnionMockName[T]) invocationsDone() bool { if len(mmName.expectations) == 0 && mmName.defaultExpectation == nil && mmName.mock.funcName == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcName set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmName.mock.afterNameCounter) expectedInvocations := mm_atomic.LoadUint64(&mmName.expectedInvocations) diff --git a/tests/generic_inline_with_many_options.go b/tests/generic_inline_with_many_options.go index 5a50ea8..b640bae 100644 --- a/tests/generic_inline_with_many_options.go +++ b/tests/generic_inline_with_many_options.go @@ -154,6 +154,7 @@ func (mmName *mGenericInlineUnionWithManyTypesMockName[T]) Set(f func(t1 T)) *Ge return mmName.mock } +// Times sets number of times genericInlineUnionWithManyTypes.Name should be invoked func (mmName *mGenericInlineUnionWithManyTypesMockName[T]) Times(n uint64) *mGenericInlineUnionWithManyTypesMockName[T] { if n == 0 { mmName.mock.t.Fatalf("Times of GenericInlineUnionWithManyTypesMock.Name mock can not be zero") @@ -164,13 +165,9 @@ func (mmName *mGenericInlineUnionWithManyTypesMockName[T]) Times(n uint64) *mGen func (mmName *mGenericInlineUnionWithManyTypesMockName[T]) invocationsDone() bool { if len(mmName.expectations) == 0 && mmName.defaultExpectation == nil && mmName.mock.funcName == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcName set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmName.mock.afterNameCounter) expectedInvocations := mm_atomic.LoadUint64(&mmName.expectedInvocations) diff --git a/tests/generic_inout.go b/tests/generic_inout.go index 123dd28..6808faa 100644 --- a/tests/generic_inout.go +++ b/tests/generic_inout.go @@ -180,6 +180,7 @@ func (e *GenericInoutMockNameExpectation[T]) Then(t2 T) *GenericInoutMock[T] { return e.mock } +// Times sets number of times genericInout.Name should be invoked func (mmName *mGenericInoutMockName[T]) Times(n uint64) *mGenericInoutMockName[T] { if n == 0 { mmName.mock.t.Fatalf("Times of GenericInoutMock.Name mock can not be zero") @@ -190,13 +191,9 @@ func (mmName *mGenericInoutMockName[T]) Times(n uint64) *mGenericInoutMockName[T func (mmName *mGenericInoutMockName[T]) invocationsDone() bool { if len(mmName.expectations) == 0 && mmName.defaultExpectation == nil && mmName.mock.funcName == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcName set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmName.mock.afterNameCounter) expectedInvocations := mm_atomic.LoadUint64(&mmName.expectedInvocations) diff --git a/tests/generic_multiple_args_with_different_types.go b/tests/generic_multiple_args_with_different_types.go index 39a496a..1df9d2e 100644 --- a/tests/generic_multiple_args_with_different_types.go +++ b/tests/generic_multiple_args_with_different_types.go @@ -179,6 +179,7 @@ func (mmName *mGenericMultipleTypesMockName[T, K]) Set(f func(t1 T, k1 K)) *Gene return mmName.mock } +// Times sets number of times genericMultipleTypes.Name should be invoked func (mmName *mGenericMultipleTypesMockName[T, K]) Times(n uint64) *mGenericMultipleTypesMockName[T, K] { if n == 0 { mmName.mock.t.Fatalf("Times of GenericMultipleTypesMock.Name mock can not be zero") @@ -189,13 +190,9 @@ func (mmName *mGenericMultipleTypesMockName[T, K]) Times(n uint64) *mGenericMult func (mmName *mGenericMultipleTypesMockName[T, K]) invocationsDone() bool { if len(mmName.expectations) == 0 && mmName.defaultExpectation == nil && mmName.mock.funcName == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcName set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmName.mock.afterNameCounter) expectedInvocations := mm_atomic.LoadUint64(&mmName.expectedInvocations) diff --git a/tests/generic_out.go b/tests/generic_out.go index 43687f7..916ad47 100644 --- a/tests/generic_out.go +++ b/tests/generic_out.go @@ -111,6 +111,7 @@ func (mmName *mGenericOutMockName[T]) Set(f func() (t1 T)) *GenericOutMock[T] { return mmName.mock } +// Times sets number of times genericOut.Name should be invoked func (mmName *mGenericOutMockName[T]) Times(n uint64) *mGenericOutMockName[T] { if n == 0 { mmName.mock.t.Fatalf("Times of GenericOutMock.Name mock can not be zero") @@ -121,13 +122,9 @@ func (mmName *mGenericOutMockName[T]) Times(n uint64) *mGenericOutMockName[T] { func (mmName *mGenericOutMockName[T]) invocationsDone() bool { if len(mmName.expectations) == 0 && mmName.defaultExpectation == nil && mmName.mock.funcName == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcName set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmName.mock.afterNameCounter) expectedInvocations := mm_atomic.LoadUint64(&mmName.expectedInvocations) diff --git a/tests/generic_simple_union.go b/tests/generic_simple_union.go index 0941949..0b06bda 100644 --- a/tests/generic_simple_union.go +++ b/tests/generic_simple_union.go @@ -154,6 +154,7 @@ func (mmName *mGenericSimpleUnionMockName[T]) Set(f func(t1 T)) *GenericSimpleUn return mmName.mock } +// Times sets number of times genericSimpleUnion.Name should be invoked func (mmName *mGenericSimpleUnionMockName[T]) Times(n uint64) *mGenericSimpleUnionMockName[T] { if n == 0 { mmName.mock.t.Fatalf("Times of GenericSimpleUnionMock.Name mock can not be zero") @@ -164,13 +165,9 @@ func (mmName *mGenericSimpleUnionMockName[T]) Times(n uint64) *mGenericSimpleUni func (mmName *mGenericSimpleUnionMockName[T]) invocationsDone() bool { if len(mmName.expectations) == 0 && mmName.defaultExpectation == nil && mmName.mock.funcName == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcName set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmName.mock.afterNameCounter) expectedInvocations := mm_atomic.LoadUint64(&mmName.expectedInvocations) diff --git a/tests/generic_specific.go b/tests/generic_specific.go index 8247a55..78ee0d2 100644 --- a/tests/generic_specific.go +++ b/tests/generic_specific.go @@ -155,6 +155,7 @@ func (mmName *mGenericSpecificMockName[T]) Set(f func(t1 T)) *GenericSpecificMoc return mmName.mock } +// Times sets number of times genericSpecific.Name should be invoked func (mmName *mGenericSpecificMockName[T]) Times(n uint64) *mGenericSpecificMockName[T] { if n == 0 { mmName.mock.t.Fatalf("Times of GenericSpecificMock.Name mock can not be zero") @@ -165,13 +166,9 @@ func (mmName *mGenericSpecificMockName[T]) Times(n uint64) *mGenericSpecificMock func (mmName *mGenericSpecificMockName[T]) invocationsDone() bool { if len(mmName.expectations) == 0 && mmName.defaultExpectation == nil && mmName.mock.funcName == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcName set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmName.mock.afterNameCounter) expectedInvocations := mm_atomic.LoadUint64(&mmName.expectedInvocations) diff --git a/tests/package_name_specified_test.go b/tests/package_name_specified_test.go index afcb4f3..1df2aa2 100644 --- a/tests/package_name_specified_test.go +++ b/tests/package_name_specified_test.go @@ -198,6 +198,7 @@ func (mmCleanup *mTesterMockCleanup) Set(f func(f func())) *TesterMock { return mmCleanup.mock } +// Times sets number of times Tester.Cleanup should be invoked func (mmCleanup *mTesterMockCleanup) Times(n uint64) *mTesterMockCleanup { if n == 0 { mmCleanup.mock.t.Fatalf("Times of TesterMock.Cleanup mock can not be zero") @@ -208,13 +209,9 @@ func (mmCleanup *mTesterMockCleanup) Times(n uint64) *mTesterMockCleanup { func (mmCleanup *mTesterMockCleanup) invocationsDone() bool { if len(mmCleanup.expectations) == 0 && mmCleanup.defaultExpectation == nil && mmCleanup.mock.funcCleanup == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcCleanup set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmCleanup.mock.afterCleanupCounter) expectedInvocations := mm_atomic.LoadUint64(&mmCleanup.expectedInvocations) @@ -449,6 +446,7 @@ func (mmError *mTesterMockError) Set(f func(p1 ...interface{})) *TesterMock { return mmError.mock } +// Times sets number of times Tester.Error should be invoked func (mmError *mTesterMockError) Times(n uint64) *mTesterMockError { if n == 0 { mmError.mock.t.Fatalf("Times of TesterMock.Error mock can not be zero") @@ -459,13 +457,9 @@ func (mmError *mTesterMockError) Times(n uint64) *mTesterMockError { func (mmError *mTesterMockError) invocationsDone() bool { if len(mmError.expectations) == 0 && mmError.defaultExpectation == nil && mmError.mock.funcError == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcError set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmError.mock.afterErrorCounter) expectedInvocations := mm_atomic.LoadUint64(&mmError.expectedInvocations) @@ -724,6 +718,7 @@ func (mmErrorf *mTesterMockErrorf) Set(f func(format string, args ...interface{} return mmErrorf.mock } +// Times sets number of times Tester.Errorf should be invoked func (mmErrorf *mTesterMockErrorf) Times(n uint64) *mTesterMockErrorf { if n == 0 { mmErrorf.mock.t.Fatalf("Times of TesterMock.Errorf mock can not be zero") @@ -734,13 +729,9 @@ func (mmErrorf *mTesterMockErrorf) Times(n uint64) *mTesterMockErrorf { func (mmErrorf *mTesterMockErrorf) invocationsDone() bool { if len(mmErrorf.expectations) == 0 && mmErrorf.defaultExpectation == nil && mmErrorf.mock.funcErrorf == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcErrorf set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmErrorf.mock.afterErrorfCounter) expectedInvocations := mm_atomic.LoadUint64(&mmErrorf.expectedInvocations) @@ -931,6 +922,7 @@ func (mmFailNow *mTesterMockFailNow) Set(f func()) *TesterMock { return mmFailNow.mock } +// Times sets number of times Tester.FailNow should be invoked func (mmFailNow *mTesterMockFailNow) Times(n uint64) *mTesterMockFailNow { if n == 0 { mmFailNow.mock.t.Fatalf("Times of TesterMock.FailNow mock can not be zero") @@ -941,13 +933,9 @@ func (mmFailNow *mTesterMockFailNow) Times(n uint64) *mTesterMockFailNow { func (mmFailNow *mTesterMockFailNow) invocationsDone() bool { if len(mmFailNow.expectations) == 0 && mmFailNow.defaultExpectation == nil && mmFailNow.mock.funcFailNow == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcFailNow set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmFailNow.mock.afterFailNowCounter) expectedInvocations := mm_atomic.LoadUint64(&mmFailNow.expectedInvocations) @@ -1137,6 +1125,7 @@ func (mmFatal *mTesterMockFatal) Set(f func(args ...interface{})) *TesterMock { return mmFatal.mock } +// Times sets number of times Tester.Fatal should be invoked func (mmFatal *mTesterMockFatal) Times(n uint64) *mTesterMockFatal { if n == 0 { mmFatal.mock.t.Fatalf("Times of TesterMock.Fatal mock can not be zero") @@ -1147,13 +1136,9 @@ func (mmFatal *mTesterMockFatal) Times(n uint64) *mTesterMockFatal { func (mmFatal *mTesterMockFatal) invocationsDone() bool { if len(mmFatal.expectations) == 0 && mmFatal.defaultExpectation == nil && mmFatal.mock.funcFatal == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcFatal set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmFatal.mock.afterFatalCounter) expectedInvocations := mm_atomic.LoadUint64(&mmFatal.expectedInvocations) @@ -1412,6 +1397,7 @@ func (mmFatalf *mTesterMockFatalf) Set(f func(format string, args ...interface{} return mmFatalf.mock } +// Times sets number of times Tester.Fatalf should be invoked func (mmFatalf *mTesterMockFatalf) Times(n uint64) *mTesterMockFatalf { if n == 0 { mmFatalf.mock.t.Fatalf("Times of TesterMock.Fatalf mock can not be zero") @@ -1422,13 +1408,9 @@ func (mmFatalf *mTesterMockFatalf) Times(n uint64) *mTesterMockFatalf { func (mmFatalf *mTesterMockFatalf) invocationsDone() bool { if len(mmFatalf.expectations) == 0 && mmFatalf.defaultExpectation == nil && mmFatalf.mock.funcFatalf == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcFatalf set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmFatalf.mock.afterFatalfCounter) expectedInvocations := mm_atomic.LoadUint64(&mmFatalf.expectedInvocations) diff --git a/tests/tester_mock_test.go b/tests/tester_mock_test.go index c92aefa..146ddf0 100644 --- a/tests/tester_mock_test.go +++ b/tests/tester_mock_test.go @@ -198,6 +198,7 @@ func (mmCleanup *mTesterMockCleanup) Set(f func(f func())) *TesterMock { return mmCleanup.mock } +// Times sets number of times Tester.Cleanup should be invoked func (mmCleanup *mTesterMockCleanup) Times(n uint64) *mTesterMockCleanup { if n == 0 { mmCleanup.mock.t.Fatalf("Times of TesterMock.Cleanup mock can not be zero") @@ -208,13 +209,9 @@ func (mmCleanup *mTesterMockCleanup) Times(n uint64) *mTesterMockCleanup { func (mmCleanup *mTesterMockCleanup) invocationsDone() bool { if len(mmCleanup.expectations) == 0 && mmCleanup.defaultExpectation == nil && mmCleanup.mock.funcCleanup == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcCleanup set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmCleanup.mock.afterCleanupCounter) expectedInvocations := mm_atomic.LoadUint64(&mmCleanup.expectedInvocations) @@ -449,6 +446,7 @@ func (mmError *mTesterMockError) Set(f func(p1 ...interface{})) *TesterMock { return mmError.mock } +// Times sets number of times Tester.Error should be invoked func (mmError *mTesterMockError) Times(n uint64) *mTesterMockError { if n == 0 { mmError.mock.t.Fatalf("Times of TesterMock.Error mock can not be zero") @@ -459,13 +457,9 @@ func (mmError *mTesterMockError) Times(n uint64) *mTesterMockError { func (mmError *mTesterMockError) invocationsDone() bool { if len(mmError.expectations) == 0 && mmError.defaultExpectation == nil && mmError.mock.funcError == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcError set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmError.mock.afterErrorCounter) expectedInvocations := mm_atomic.LoadUint64(&mmError.expectedInvocations) @@ -724,6 +718,7 @@ func (mmErrorf *mTesterMockErrorf) Set(f func(format string, args ...interface{} return mmErrorf.mock } +// Times sets number of times Tester.Errorf should be invoked func (mmErrorf *mTesterMockErrorf) Times(n uint64) *mTesterMockErrorf { if n == 0 { mmErrorf.mock.t.Fatalf("Times of TesterMock.Errorf mock can not be zero") @@ -734,13 +729,9 @@ func (mmErrorf *mTesterMockErrorf) Times(n uint64) *mTesterMockErrorf { func (mmErrorf *mTesterMockErrorf) invocationsDone() bool { if len(mmErrorf.expectations) == 0 && mmErrorf.defaultExpectation == nil && mmErrorf.mock.funcErrorf == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcErrorf set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmErrorf.mock.afterErrorfCounter) expectedInvocations := mm_atomic.LoadUint64(&mmErrorf.expectedInvocations) @@ -931,6 +922,7 @@ func (mmFailNow *mTesterMockFailNow) Set(f func()) *TesterMock { return mmFailNow.mock } +// Times sets number of times Tester.FailNow should be invoked func (mmFailNow *mTesterMockFailNow) Times(n uint64) *mTesterMockFailNow { if n == 0 { mmFailNow.mock.t.Fatalf("Times of TesterMock.FailNow mock can not be zero") @@ -941,13 +933,9 @@ func (mmFailNow *mTesterMockFailNow) Times(n uint64) *mTesterMockFailNow { func (mmFailNow *mTesterMockFailNow) invocationsDone() bool { if len(mmFailNow.expectations) == 0 && mmFailNow.defaultExpectation == nil && mmFailNow.mock.funcFailNow == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcFailNow set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmFailNow.mock.afterFailNowCounter) expectedInvocations := mm_atomic.LoadUint64(&mmFailNow.expectedInvocations) @@ -1137,6 +1125,7 @@ func (mmFatal *mTesterMockFatal) Set(f func(args ...interface{})) *TesterMock { return mmFatal.mock } +// Times sets number of times Tester.Fatal should be invoked func (mmFatal *mTesterMockFatal) Times(n uint64) *mTesterMockFatal { if n == 0 { mmFatal.mock.t.Fatalf("Times of TesterMock.Fatal mock can not be zero") @@ -1147,13 +1136,9 @@ func (mmFatal *mTesterMockFatal) Times(n uint64) *mTesterMockFatal { func (mmFatal *mTesterMockFatal) invocationsDone() bool { if len(mmFatal.expectations) == 0 && mmFatal.defaultExpectation == nil && mmFatal.mock.funcFatal == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcFatal set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmFatal.mock.afterFatalCounter) expectedInvocations := mm_atomic.LoadUint64(&mmFatal.expectedInvocations) @@ -1412,6 +1397,7 @@ func (mmFatalf *mTesterMockFatalf) Set(f func(format string, args ...interface{} return mmFatalf.mock } +// Times sets number of times Tester.Fatalf should be invoked func (mmFatalf *mTesterMockFatalf) Times(n uint64) *mTesterMockFatalf { if n == 0 { mmFatalf.mock.t.Fatalf("Times of TesterMock.Fatalf mock can not be zero") @@ -1422,13 +1408,9 @@ func (mmFatalf *mTesterMockFatalf) Times(n uint64) *mTesterMockFatalf { func (mmFatalf *mTesterMockFatalf) invocationsDone() bool { if len(mmFatalf.expectations) == 0 && mmFatalf.defaultExpectation == nil && mmFatalf.mock.funcFatalf == nil { - // does not need to check invocations if no expectations, defaultExpectation or funcFatalf set return true } - // if expectations were set we check total invocations - // if default expectation was set then invocations count should be greater than zero - // if func was set then invocations count should be greater than zero totalInvocations := mm_atomic.LoadUint64(&mmFatalf.mock.afterFatalfCounter) expectedInvocations := mm_atomic.LoadUint64(&mmFatalf.expectedInvocations)