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

Commit aff3767

Browse files
authored
Fix empty error message when call is exhausted (#460)
Fixes #404
1 parent d2fe5cd commit aff3767

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

gomock/callset.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ func (cs callSet) FindMatch(receiver interface{}, method string, args []interfac
8484
for _, call := range exhausted {
8585
if err := call.matches(args); err != nil {
8686
_, _ = fmt.Fprintf(&callsErrors, "\n%v", err)
87+
continue
8788
}
89+
_, _ = fmt.Fprintf(
90+
&callsErrors, "all expected calls for method %q have been exhausted", method,
91+
)
8892
}
8993

9094
if len(expected)+len(exhausted) == 0 {

gomock/callset_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,26 @@ func TestCallSetRemove(t *testing.T) {
7474
cs.Remove(c)
7575
}
7676
}
77+
78+
func TestCallSetFindMatch(t *testing.T) {
79+
t.Run("call is exhausted", func(t *testing.T) {
80+
cs := callSet{}
81+
var receiver interface{} = "TestReceiver"
82+
method := "TestMethod"
83+
args := []interface{}{}
84+
85+
c1 := newCall(t, receiver, method, reflect.TypeOf(receiverType{}.Func))
86+
cs.exhausted = map[callSetKey][]*Call{
87+
callSetKey{receiver: receiver, fname: method}: []*Call{c1},
88+
}
89+
90+
_, err := cs.FindMatch(receiver, method, args)
91+
if err == nil {
92+
t.Fatal("expected error, but was nil")
93+
}
94+
95+
if err.Error() == "" {
96+
t.Fatal("expected error to have message, but was empty")
97+
}
98+
})
99+
}

0 commit comments

Comments
 (0)