Skip to content

Commit

Permalink
Fix for stretchr#1236
Browse files Browse the repository at this point in the history
This PR aims to fix stretchr#1236. While it's not the pretties fix, it avoids panic

Motivation:
As library user, I want this function to work.

Example usage:
n/a

Feature or bug fix?
Bug fix
  • Loading branch information
DubbaThony committed Jul 27, 2022
1 parent 181cea6 commit 83db660
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions mock/mock.go
Expand Up @@ -217,17 +217,19 @@ func (c *Call) Unset() *Call {
defer unlockOnce.Do(c.unlock)

foundMatchingCall := false

for i, call := range c.Parent.ExpectedCalls {

tmp := make([]*Call, 0)
for _, call := range c.Parent.ExpectedCalls {
if call.Method == c.Method {
_, diffCount := call.Arguments.Diff(c.Arguments)
if diffCount == 0 {
foundMatchingCall = true
// Remove from ExpectedCalls
c.Parent.ExpectedCalls = append(c.Parent.ExpectedCalls[:i], c.Parent.ExpectedCalls[i+1:]...)
} else {
tmp = append(tmp, call)
}
}
}
c.Parent.ExpectedCalls = tmp

if !foundMatchingCall {
unlockOnce.Do(c.unlock)
Expand Down

0 comments on commit 83db660

Please sign in to comment.