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

Commit 7897399

Browse files
committed
Fix empty error message when call is exhausted
issue-404
1 parent a5953ef commit 7897399

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
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 of the method %q have been exhausted for that received", method,
91+
)
8892
}
8993

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

gomock/callset_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import (
2121

2222
type receiverType struct{}
2323

24-
func (receiverType) Func() {}
24+
func (receiverType) Func() {}
25+
func (receiverType) Func2(a string) {}
2526

2627
func TestCallSetAdd(t *testing.T) {
2728
method := "TestMethod"
@@ -74,3 +75,26 @@ func TestCallSetRemove(t *testing.T) {
7475
cs.Remove(c)
7576
}
7677
}
78+
79+
func TestCallSetFindMatch(t *testing.T) {
80+
t.Run("call is exhausted", func(t *testing.T) {
81+
cs := callSet{}
82+
var receiver interface{} = "TestReceiver"
83+
method := "TestMethod"
84+
args := []interface{}{}
85+
86+
c1 := newCall(t, receiver, method, reflect.TypeOf(receiverType{}.Func))
87+
cs.exhausted = map[callSetKey][]*Call{
88+
callSetKey{receiver: receiver, fname: method}: []*Call{c1},
89+
}
90+
91+
_, err := cs.FindMatch(receiver, method, args)
92+
if err == nil {
93+
t.Fatal("expected error, but was nil")
94+
}
95+
96+
if err.Error() == "" {
97+
t.Fatal("expected error to have message, but was empty")
98+
}
99+
})
100+
}

sample/user_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66

77
"github.com/golang/mock/gomock"
8-
"github.com/golang/mock/sample"
8+
user "github.com/golang/mock/sample"
99
"github.com/golang/mock/sample/imp1"
1010
mock_user "github.com/golang/mock/sample/mock_user"
1111
)

0 commit comments

Comments
 (0)