forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
retries_test.go
60 lines (48 loc) · 1.33 KB
/
retries_test.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package linodego
import (
"net/http"
"testing"
"time"
"github.com/go-resty/resty/v2"
)
func TestLinodeBusyRetryCondition(t *testing.T) {
var retry bool
request := resty.Request{}
rawResponse := http.Response{StatusCode: http.StatusBadRequest}
response := resty.Response{
Request: &request,
RawResponse: &rawResponse,
}
retry = linodeBusyRetryCondition(&response, nil)
if retry {
t.Errorf("Should not have retried")
}
apiError := APIError{
Errors: []APIErrorReason{
{Reason: "Linode busy."},
},
}
request.SetError(&apiError)
retry = linodeBusyRetryCondition(&response, nil)
if !retry {
t.Errorf("Should have retried")
}
}
func TestLinodeServiceUnavailableRetryCondition(t *testing.T) {
request := resty.Request{}
rawResponse := http.Response{StatusCode: http.StatusServiceUnavailable, Header: http.Header{
retryAfterHeaderName: []string{"20"},
}}
response := resty.Response{
Request: &request,
RawResponse: &rawResponse,
}
if retry := serviceUnavailableRetryCondition(&response, nil); !retry {
t.Error("expected request to be retried")
}
if retryAfter, err := respectRetryAfter(NewClient(nil).resty, &response); err != nil {
t.Errorf("expected error to be nil but got %s", err)
} else if retryAfter != time.Second*20 {
t.Errorf("expected retryAfter to be 20 but got %d", retryAfter)
}
}