From 134fb5cf4184a7cb56eee0c5a1f43f699826be0c Mon Sep 17 00:00:00 2001 From: Max Chechel Date: Mon, 5 Aug 2019 18:54:16 +0300 Subject: [PATCH] fixes #40 --- template.go | 20 +++++++------- tests/formatter_mock.go | 20 +++++++------- tests/tester_mock_test.go | 56 +++++++++++++++++++-------------------- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/template.go b/template.go index 184474c..3017414 100644 --- a/template.go +++ b/template.go @@ -173,15 +173,15 @@ const ( } {{if $method.HasParams}} - params := &{{$mock}}{{$method.Name}}Params{ {{$method.ParamsNames}} } + mm_params := &{{$mock}}{{$method.Name}}Params{ {{$method.ParamsNames}} } // Record call args {{$m}}.{{$method.Name}}Mock.mutex.Lock() - {{$m}}.{{$method.Name}}Mock.callArgs = append({{$m}}.{{$method.Name}}Mock.callArgs, params) + {{$m}}.{{$method.Name}}Mock.callArgs = append({{$m}}.{{$method.Name}}Mock.callArgs, mm_params) {{$m}}.{{$method.Name}}Mock.mutex.Unlock() for _, e := range {{$m}}.{{$method.Name}}Mock.expectations { - if minimock.Equal(e.params, params) { + if minimock.Equal(e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) {{$method.ReturnStruct "e.results" -}} } @@ -191,18 +191,18 @@ const ( if {{$m}}.{{$method.Name}}Mock.defaultExpectation != nil { mm_atomic.AddUint64(&{{$m}}.{{$method.Name}}Mock.defaultExpectation.Counter, 1) {{- if $method.HasParams }} - want := {{$m}}.{{$method.Name}}Mock.defaultExpectation.params - got := {{$mock}}{{$method.Name}}Params{ {{$method.ParamsNames}} } - if want != nil && !minimock.Equal(*want, got) { - {{$m}}.t.Errorf("{{$mock}}.{{$method.Name}} got unexpected parameters, want: %#v, got: %#v%s\n", *want, got, minimock.Diff(*want, got)) + mm_want := {{$m}}.{{$method.Name}}Mock.defaultExpectation.params + mm_got := {{$mock}}{{$method.Name}}Params{ {{$method.ParamsNames}} } + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + {{$m}}.t.Errorf("{{$mock}}.{{$method.Name}} got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } {{ end }} {{if $method.HasResults }} - results := {{$m}}.{{$method.Name}}Mock.defaultExpectation.results - if results == nil { + mm_results := {{$m}}.{{$method.Name}}Mock.defaultExpectation.results + if mm_results == nil { {{$m}}.t.Fatal("No results are set for the {{$mock}}.{{$method.Name}}") } - {{$method.ReturnStruct "(*results)" -}} + {{$method.ReturnStruct "(*mm_results)" -}} {{else}} return {{ end }} diff --git a/tests/formatter_mock.go b/tests/formatter_mock.go index 0bf936a..f70139e 100644 --- a/tests/formatter_mock.go +++ b/tests/formatter_mock.go @@ -152,15 +152,15 @@ func (mmFormat *FormatterMock) Format(s1 string, p1 ...interface{}) (s2 string) mmFormat.inspectFuncFormat(s1, p1...) } - params := &FormatterMockFormatParams{s1, p1} + mm_params := &FormatterMockFormatParams{s1, p1} // Record call args mmFormat.FormatMock.mutex.Lock() - mmFormat.FormatMock.callArgs = append(mmFormat.FormatMock.callArgs, params) + mmFormat.FormatMock.callArgs = append(mmFormat.FormatMock.callArgs, mm_params) mmFormat.FormatMock.mutex.Unlock() for _, e := range mmFormat.FormatMock.expectations { - if minimock.Equal(e.params, params) { + if minimock.Equal(e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return e.results.s2 } @@ -168,17 +168,17 @@ func (mmFormat *FormatterMock) Format(s1 string, p1 ...interface{}) (s2 string) if mmFormat.FormatMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmFormat.FormatMock.defaultExpectation.Counter, 1) - want := mmFormat.FormatMock.defaultExpectation.params - got := FormatterMockFormatParams{s1, p1} - if want != nil && !minimock.Equal(*want, got) { - mmFormat.t.Errorf("FormatterMock.Format got unexpected parameters, want: %#v, got: %#v%s\n", *want, got, minimock.Diff(*want, got)) + mm_want := mmFormat.FormatMock.defaultExpectation.params + mm_got := FormatterMockFormatParams{s1, p1} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmFormat.t.Errorf("FormatterMock.Format got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } - results := mmFormat.FormatMock.defaultExpectation.results - if results == nil { + mm_results := mmFormat.FormatMock.defaultExpectation.results + if mm_results == nil { mmFormat.t.Fatal("No results are set for the FormatterMock.Format") } - return (*results).s2 + return (*mm_results).s2 } if mmFormat.funcFormat != nil { return mmFormat.funcFormat(s1, p1...) diff --git a/tests/tester_mock_test.go b/tests/tester_mock_test.go index 426d541..3677ec2 100644 --- a/tests/tester_mock_test.go +++ b/tests/tester_mock_test.go @@ -160,15 +160,15 @@ func (mmError *TesterMock) Error(p1 ...interface{}) { mmError.inspectFuncError(p1...) } - params := &TesterMockErrorParams{p1} + mm_params := &TesterMockErrorParams{p1} // Record call args mmError.ErrorMock.mutex.Lock() - mmError.ErrorMock.callArgs = append(mmError.ErrorMock.callArgs, params) + mmError.ErrorMock.callArgs = append(mmError.ErrorMock.callArgs, mm_params) mmError.ErrorMock.mutex.Unlock() for _, e := range mmError.ErrorMock.expectations { - if minimock.Equal(e.params, params) { + if minimock.Equal(e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return } @@ -176,10 +176,10 @@ func (mmError *TesterMock) Error(p1 ...interface{}) { if mmError.ErrorMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmError.ErrorMock.defaultExpectation.Counter, 1) - want := mmError.ErrorMock.defaultExpectation.params - got := TesterMockErrorParams{p1} - if want != nil && !minimock.Equal(*want, got) { - mmError.t.Errorf("TesterMock.Error got unexpected parameters, want: %#v, got: %#v%s\n", *want, got, minimock.Diff(*want, got)) + mm_want := mmError.ErrorMock.defaultExpectation.params + mm_got := TesterMockErrorParams{p1} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmError.t.Errorf("TesterMock.Error got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } return @@ -348,15 +348,15 @@ func (mmErrorf *TesterMock) Errorf(format string, args ...interface{}) { mmErrorf.inspectFuncErrorf(format, args...) } - params := &TesterMockErrorfParams{format, args} + mm_params := &TesterMockErrorfParams{format, args} // Record call args mmErrorf.ErrorfMock.mutex.Lock() - mmErrorf.ErrorfMock.callArgs = append(mmErrorf.ErrorfMock.callArgs, params) + mmErrorf.ErrorfMock.callArgs = append(mmErrorf.ErrorfMock.callArgs, mm_params) mmErrorf.ErrorfMock.mutex.Unlock() for _, e := range mmErrorf.ErrorfMock.expectations { - if minimock.Equal(e.params, params) { + if minimock.Equal(e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return } @@ -364,10 +364,10 @@ func (mmErrorf *TesterMock) Errorf(format string, args ...interface{}) { if mmErrorf.ErrorfMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmErrorf.ErrorfMock.defaultExpectation.Counter, 1) - want := mmErrorf.ErrorfMock.defaultExpectation.params - got := TesterMockErrorfParams{format, args} - if want != nil && !minimock.Equal(*want, got) { - mmErrorf.t.Errorf("TesterMock.Errorf got unexpected parameters, want: %#v, got: %#v%s\n", *want, got, minimock.Diff(*want, got)) + mm_want := mmErrorf.ErrorfMock.defaultExpectation.params + mm_got := TesterMockErrorfParams{format, args} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmErrorf.t.Errorf("TesterMock.Errorf got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } return @@ -670,15 +670,15 @@ func (mmFatal *TesterMock) Fatal(args ...interface{}) { mmFatal.inspectFuncFatal(args...) } - params := &TesterMockFatalParams{args} + mm_params := &TesterMockFatalParams{args} // Record call args mmFatal.FatalMock.mutex.Lock() - mmFatal.FatalMock.callArgs = append(mmFatal.FatalMock.callArgs, params) + mmFatal.FatalMock.callArgs = append(mmFatal.FatalMock.callArgs, mm_params) mmFatal.FatalMock.mutex.Unlock() for _, e := range mmFatal.FatalMock.expectations { - if minimock.Equal(e.params, params) { + if minimock.Equal(e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return } @@ -686,10 +686,10 @@ func (mmFatal *TesterMock) Fatal(args ...interface{}) { if mmFatal.FatalMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmFatal.FatalMock.defaultExpectation.Counter, 1) - want := mmFatal.FatalMock.defaultExpectation.params - got := TesterMockFatalParams{args} - if want != nil && !minimock.Equal(*want, got) { - mmFatal.t.Errorf("TesterMock.Fatal got unexpected parameters, want: %#v, got: %#v%s\n", *want, got, minimock.Diff(*want, got)) + mm_want := mmFatal.FatalMock.defaultExpectation.params + mm_got := TesterMockFatalParams{args} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmFatal.t.Errorf("TesterMock.Fatal got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } return @@ -858,15 +858,15 @@ func (mmFatalf *TesterMock) Fatalf(format string, args ...interface{}) { mmFatalf.inspectFuncFatalf(format, args...) } - params := &TesterMockFatalfParams{format, args} + mm_params := &TesterMockFatalfParams{format, args} // Record call args mmFatalf.FatalfMock.mutex.Lock() - mmFatalf.FatalfMock.callArgs = append(mmFatalf.FatalfMock.callArgs, params) + mmFatalf.FatalfMock.callArgs = append(mmFatalf.FatalfMock.callArgs, mm_params) mmFatalf.FatalfMock.mutex.Unlock() for _, e := range mmFatalf.FatalfMock.expectations { - if minimock.Equal(e.params, params) { + if minimock.Equal(e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return } @@ -874,10 +874,10 @@ func (mmFatalf *TesterMock) Fatalf(format string, args ...interface{}) { if mmFatalf.FatalfMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmFatalf.FatalfMock.defaultExpectation.Counter, 1) - want := mmFatalf.FatalfMock.defaultExpectation.params - got := TesterMockFatalfParams{format, args} - if want != nil && !minimock.Equal(*want, got) { - mmFatalf.t.Errorf("TesterMock.Fatalf got unexpected parameters, want: %#v, got: %#v%s\n", *want, got, minimock.Diff(*want, got)) + mm_want := mmFatalf.FatalfMock.defaultExpectation.params + mm_got := TesterMockFatalfParams{format, args} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmFatalf.t.Errorf("TesterMock.Fatalf got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } return