Skip to content

Commit 1962448

Browse files
uberboboyan-soubachov
authored andcommitted
Use Repeatability as tie-breaker for closest match
1 parent 92707c0 commit 1962448

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

mock/mock.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,17 @@ func (m *Mock) findExpectedCall(method string, arguments ...interface{}) (int, *
299299

300300
func (m *Mock) findClosestCall(method string, arguments ...interface{}) (*Call, string) {
301301
var diffCount int
302+
var repeatability int
302303
var closestCall *Call
303304
var err string
304305

305306
for _, call := range m.expectedCalls() {
306307
if call.Method == method {
307308

308309
errInfo, tempDiffCount := call.Arguments.Diff(arguments)
309-
if tempDiffCount < diffCount || diffCount == 0 {
310+
if tempDiffCount < diffCount || diffCount == 0 || (tempDiffCount == diffCount && call.Repeatability > repeatability) {
310311
diffCount = tempDiffCount
312+
repeatability = call.Repeatability
311313
closestCall = call
312314
err = errInfo
313315
}

0 commit comments

Comments
 (0)