-
Notifications
You must be signed in to change notification settings - Fork 0
/
retry_test.go
79 lines (73 loc) · 1.65 KB
/
retry_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2020 - MinIO, Inc. All rights reserved.
// Use of this source code is governed by the AGPLv3
// license that can be found in the LICENSE file.
package kes
import (
"bytes"
"io"
"net"
"net/url"
"testing"
)
var retryBodyTests = []struct {
Body io.ReadSeeker
}{
{Body: nil},
{Body: bytes.NewReader(nil)},
}
func TestRetryBody(t *testing.T) {
for i, test := range retryBodyTests {
body := retryBody(test.Body)
if test.Body == nil && body != nil {
t.Fatalf("Test %d: invalid retry body: got %v - want %v", i, body, test.Body)
}
if test.Body != nil {
if _, ok := body.(io.Seeker); !ok {
t.Fatalf("Test %d: retry body does not implement io.Seeker", i)
}
}
}
}
var isNetworkErrorTests = []struct {
Err error
IsNetworkError bool
}{
{Err: nil, IsNetworkError: false},
{Err: io.EOF, IsNetworkError: false},
{Err: url.InvalidHostError(""), IsNetworkError: false},
{
Err: &url.Error{
Op: "GET",
URL: "http://127.0.0.1",
Err: net.UnknownNetworkError("unknown"),
},
IsNetworkError: true,
},
{
Err: &url.Error{
Op: "GET",
URL: "http://127.0.0.1",
Err: &net.DNSError{},
},
IsNetworkError: true,
},
{
Err: &url.Error{
Op: "GET",
URL: "http://127.0.0.1",
Err: io.EOF,
},
IsNetworkError: true,
},
}
func TestIsNetworkError(t *testing.T) {
for i, test := range isNetworkErrorTests {
temp := isNetworkError(test.Err)
switch {
case test.IsNetworkError == true && temp == false:
t.Fatalf("Test %d: err should be a network error but it is not", i)
case test.IsNetworkError == false && temp == true:
t.Fatalf("Test %d: err should not be a network error but it is", i)
}
}
}