From f0016133c9cfb070ee70e0055214908dabe256f6 Mon Sep 17 00:00:00 2001 From: "cgwippern@google.com" Date: Fri, 24 Jul 2020 14:34:26 -0700 Subject: [PATCH] Fix empty error message when call is exhausted issue-404 --- gomock/callset.go | 4 ++++ gomock/callset_test.go | 23 +++++++++++++++++++++++ sample/user_test.go | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) 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") + } + }) +} diff --git a/sample/user_test.go b/sample/user_test.go index d1de99cd..1267107f 100644 --- a/sample/user_test.go +++ b/sample/user_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/golang/mock/gomock" - "github.com/golang/mock/sample" + user "github.com/golang/mock/sample" "github.com/golang/mock/sample/imp1" mock_user "github.com/golang/mock/sample/mock_user" )