-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify.go
28 lines (24 loc) · 1001 Bytes
/
verify.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package mockhttp
// CallVerifier is a helper to verify invocations of a specific HTTP call
type CallVerifier struct {
api *APIMock
call *HTTPCall
}
// HasBeenCalled asserts that the HTTP call has been made the expected number of times.
// It returns all invocations of the call.
func (verifier *CallVerifier) HasBeenCalled(expectedCallsCount int) []*Invocation {
invocations := verifier.api.invocations[*verifier.call]
actualCallsCount := len(invocations)
if actualCallsCount != expectedCallsCount {
verifier.api.testState.Fatalf("got %d http calls but was expecting %d\n", actualCallsCount, expectedCallsCount)
}
return invocations
}
// HasBeenCalledOnce asserts that the HTTP call has been made exactly once then returns the invocation.
func (verifier *CallVerifier) HasBeenCalledOnce() *Invocation {
return verifier.HasBeenCalled(1)[0]
}
// HasNotBeenCalled asserts that no HTTP call has been made.
func (verifier *CallVerifier) HasNotBeenCalled() {
_ = verifier.HasBeenCalled(0)
}