Skip to content

Commit f6e9b07

Browse files
English: Updated callIndex for awsm_stubber for testtools (#6695)
Currently if we use stubs in a single test func multiple times the callIndex will increase while the stubs decrease. If we run a for loop for the doing multiple tests, and stub twice for a loop, the call index will eventually become 3 while the stubs available is lesser then 3 throwing an error out. --------- Co-authored-by: Corey Pyle <[email protected]>
1 parent 82fa8c8 commit f6e9b07

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

gov2/testtools/awsm_stubber.go

+3
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ func (stubber *AwsmStubber) Next() *Stub {
150150
// Clear removes all stubs from the stubber.
151151
func (stubber *AwsmStubber) Clear() {
152152
stubber.stubs = nil
153+
stubber.callIndex = 0
153154
}
154155

155156
// VerifyAllStubsCalled returns an error if there are stubs in the slice that were not
@@ -159,6 +160,8 @@ func (stubber *AwsmStubber) VerifyAllStubsCalled() error {
159160
next := stubber.Next()
160161
if next != nil {
161162
err = fmt.Errorf("Remaining stub %v was never called.", next.OperationName)
163+
} else {
164+
stubber.callIndex = 0
162165
}
163166
return err
164167
}

0 commit comments

Comments
 (0)