-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretry_test.go
More file actions
71 lines (65 loc) · 1.48 KB
/
retry_test.go
File metadata and controls
71 lines (65 loc) · 1.48 KB
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
// 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 isTemporaryTests = []struct {
Err error
IsTemporary bool
}{
{Err: nil, IsTemporary: false},
{Err: io.EOF, IsTemporary: false},
{Err: url.InvalidHostError(""), IsTemporary: false},
{
Err: &url.Error{
Op: "GET",
URL: "http://127.0.0.1",
Err: net.UnknownNetworkError("unknown"),
},
IsTemporary: false,
},
{
Err: &url.Error{
Op: "GET",
URL: "http://127.0.0.1",
Err: io.EOF,
},
IsTemporary: true,
},
}
func TestIsTemporary(t *testing.T) {
for i, test := range isTemporaryTests {
temp := isTemporary(test.Err)
switch {
case test.IsTemporary == true && temp == false:
t.Fatalf("Test %d: err should be temporary but it is not", i)
case test.IsTemporary == false && temp == true:
t.Fatalf("Test %d: err should not be temporary but it is", i)
}
}
}