From aa9e21ce21c9958ded2888f99c40505e3ef60a58 Mon Sep 17 00:00:00 2001 From: "cgwippern@google.com" Date: Fri, 24 Jul 2020 14:34:26 -0700 Subject: [PATCH 1/2] Fix empty error message when call is exhausted issue-404 --- gomock/callset.go | 4 ++++ gomock/callset_test.go | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/gomock/callset.go b/gomock/callset.go index b046b525..7bb056bc 100644 --- a/gomock/callset.go +++ b/gomock/callset.go @@ -84,7 +84,11 @@ func (cs callSet) FindMatch(receiver interface{}, method string, args []interfac for _, call := range exhausted { if err := call.matches(args); err != nil { _, _ = fmt.Fprintf(&callsErrors, "\n%v", err) + continue } + _, _ = fmt.Fprintf( + &callsErrors, "all expected calls of the method %q have been exhausted for that received", method, + ) } if len(expected)+len(exhausted) == 0 { diff --git a/gomock/callset_test.go b/gomock/callset_test.go index 7fc711a4..a2835f34 100644 --- a/gomock/callset_test.go +++ b/gomock/callset_test.go @@ -74,3 +74,26 @@ func TestCallSetRemove(t *testing.T) { cs.Remove(c) } } + +func TestCallSetFindMatch(t *testing.T) { + t.Run("call is exhausted", func(t *testing.T) { + cs := callSet{} + var receiver interface{} = "TestReceiver" + method := "TestMethod" + args := []interface{}{} + + c1 := newCall(t, receiver, method, reflect.TypeOf(receiverType{}.Func)) + cs.exhausted = map[callSetKey][]*Call{ + callSetKey{receiver: receiver, fname: method}: []*Call{c1}, + } + + _, err := cs.FindMatch(receiver, method, args) + if err == nil { + t.Fatal("expected error, but was nil") + } + + if err.Error() == "" { + t.Fatal("expected error to have message, but was empty") + } + }) +} From 6de07a353920901454db49e2193123dc9bd8634c Mon Sep 17 00:00:00 2001 From: Cole Wippern Date: Fri, 21 Aug 2020 13:21:00 -0700 Subject: [PATCH 2/2] Update gomock/callset.go error message update Co-authored-by: Cody Oss <6331106+codyoss@users.noreply.github.com> --- gomock/callset.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gomock/callset.go b/gomock/callset.go index 7bb056bc..e4e85d60 100644 --- a/gomock/callset.go +++ b/gomock/callset.go @@ -87,7 +87,7 @@ func (cs callSet) FindMatch(receiver interface{}, method string, args []interfac continue } _, _ = fmt.Fprintf( - &callsErrors, "all expected calls of the method %q have been exhausted for that received", method, + &callsErrors, "all expected calls for method %q have been exhausted", method, ) }