Skip to content

Commit

Permalink
Use Repeatability as tie-breaker for closest match
Browse files Browse the repository at this point in the history
  • Loading branch information
uberbo authored and boyan-soubachov committed Jan 13, 2021
1 parent 92707c0 commit 1962448
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,17 @@ func (m *Mock) findExpectedCall(method string, arguments ...interface{}) (int, *

func (m *Mock) findClosestCall(method string, arguments ...interface{}) (*Call, string) {
var diffCount int
var repeatability int
var closestCall *Call
var err string

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

errInfo, tempDiffCount := call.Arguments.Diff(arguments)
if tempDiffCount < diffCount || diffCount == 0 {
if tempDiffCount < diffCount || diffCount == 0 || (tempDiffCount == diffCount && call.Repeatability > repeatability) {
diffCount = tempDiffCount
repeatability = call.Repeatability
closestCall = call
err = errInfo
}
Expand Down

0 comments on commit 1962448

Please sign in to comment.