forked from cloudfoundry-attic/bosh-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_request_retryable.go
46 lines (36 loc) · 973 Bytes
/
fake_request_retryable.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package fakes
import (
"net/http"
)
type attemptOutput struct {
response *http.Response
isRetryable bool
err error
}
type FakeRequestRetryable struct {
attemptOutputs []attemptOutput
lastResponse *http.Response
AttemptCalled int
}
func NewFakeRequestRetryable() *FakeRequestRetryable {
return &FakeRequestRetryable{
attemptOutputs: []attemptOutput{},
}
}
func (r *FakeRequestRetryable) Attempt() (bool, error) {
r.AttemptCalled++
currentAttempt := r.attemptOutputs[0]
r.attemptOutputs = r.attemptOutputs[1:]
r.lastResponse = currentAttempt.response
return currentAttempt.isRetryable, currentAttempt.err
}
func (r *FakeRequestRetryable) Response() *http.Response {
return r.lastResponse
}
func (r *FakeRequestRetryable) AddAttemptBehavior(response *http.Response, isRetryable bool, err error) {
r.attemptOutputs = append(r.attemptOutputs, attemptOutput{
response: response,
isRetryable: isRetryable,
err: err,
})
}