Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Fix empty error message when call is exhausted (#460)
Browse files Browse the repository at this point in the history
Fixes #404
  • Loading branch information
cvgw authored Aug 21, 2020
1 parent d2fe5cd commit aff3767
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gomock/callset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 for method %q have been exhausted", method,
)
}

if len(expected)+len(exhausted) == 0 {
Expand Down
23 changes: 23 additions & 0 deletions gomock/callset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
})
}

0 comments on commit aff3767

Please # to comment.