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

Fix empty error message when call is exhausted #460

Merged
merged 2 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 of the method %q have been exhausted for that received", method,
cvgw marked this conversation as resolved.
Show resolved Hide resolved
)
}

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")
}
})
}