@@ -32,6 +32,7 @@ func TestRetry(t *testing.T) {
32
32
failCode int
33
33
failErr error
34
34
response string
35
+ expectError bool
35
36
}{
36
37
{
37
38
name : "no retries" ,
@@ -49,6 +50,12 @@ func TestRetry(t *testing.T) {
49
50
failErr : io .ErrUnexpectedEOF ,
50
51
timesToFail : 1 ,
51
52
},
53
+ {
54
+ name : "retry io.ErrUnexpectedEOF permanent" ,
55
+ failErr : io .ErrUnexpectedEOF ,
56
+ timesToFail : maxRetryAttempts + 1 ,
57
+ expectError : true ,
58
+ },
52
59
}
53
60
for _ , tt := range tests {
54
61
t .Run (tt .name , func (t * testing.T ) {
@@ -60,15 +67,23 @@ func TestRetry(t *testing.T) {
60
67
}
61
68
c := NewClient (& http.Client {Transport : ft })
62
69
s , err := c .Get ("" )
63
- if err != nil {
70
+ if tt .expectError && err == nil {
71
+ t .Fatalf ("did not receive expected error" )
72
+ } else if ! tt .expectError && err != nil {
64
73
t .Fatalf ("unexpected error: %v" , err )
65
74
}
66
- if ft .called != ft .failedAttempts + 1 {
67
- t .Fatalf ("failed %d times, want %d" , ft .called , ft .failedAttempts + 1 )
68
- }
69
- if s != tt .response {
75
+
76
+ expectedCount := ft .failedAttempts + 1
77
+ if tt .expectError {
78
+ expectedCount = ft .failedAttempts
79
+ } else if s != tt .response {
80
+ // Responses are only meaningful if err == nil
70
81
t .Fatalf ("c.Get() = %q, want %q" , s , tt .response )
71
82
}
83
+
84
+ if ft .called != expectedCount {
85
+ t .Fatalf ("failed %d times, want %d" , ft .called , expectedCount )
86
+ }
72
87
})
73
88
}
74
89
}
0 commit comments