This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient_test.go
102 lines (79 loc) · 2.76 KB
/
client_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package polynym
import (
"fmt"
"testing"
"time"
)
// TestNewClient test new client
func TestNewClient(t *testing.T) {
t.Parallel()
client := NewClient(nil)
if len(client.UserAgent) == 0 {
t.Fatal("missing user agent")
}
}
// ExampleNewClient example using NewClient()
func ExampleNewClient() {
client := NewClient(nil)
fmt.Println(client.UserAgent)
// Output:go-polynym: v0.4.7
}
// BenchmarkNewClient benchmarks the NewClient method
func BenchmarkNewClient(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = NewClient(nil)
}
}
// TestClientDefaultOptions tests setting ClientDefaultOptions()
func TestClientDefaultOptions(t *testing.T) {
t.Parallel()
options := ClientDefaultOptions()
if options.UserAgent != defaultUserAgent {
t.Fatalf("expected value: %s got: %s", defaultUserAgent, options.UserAgent)
}
if options.BackOffExponentFactor != 2.0 {
t.Fatalf("expected value: %f got: %f", 2.0, options.BackOffExponentFactor)
}
if options.BackOffInitialTimeout != 2*time.Millisecond {
t.Fatalf("expected value: %v got: %v", 2*time.Millisecond, options.BackOffInitialTimeout)
}
if options.BackOffMaximumJitterInterval != 2*time.Millisecond {
t.Fatalf("expected value: %v got: %v", 2*time.Millisecond, options.BackOffMaximumJitterInterval)
}
if options.BackOffMaxTimeout != 10*time.Millisecond {
t.Fatalf("expected value: %v got: %v", 10*time.Millisecond, options.BackOffMaxTimeout)
}
if options.DialerKeepAlive != 20*time.Second {
t.Fatalf("expected value: %v got: %v", 20*time.Second, options.DialerKeepAlive)
}
if options.DialerTimeout != 5*time.Second {
t.Fatalf("expected value: %v got: %v", 5*time.Second, options.DialerTimeout)
}
if options.RequestRetryCount != 2 {
t.Fatalf("expected value: %v got: %v", 2, options.RequestRetryCount)
}
if options.RequestTimeout != 10*time.Second {
t.Fatalf("expected value: %v got: %v", 10*time.Second, options.RequestTimeout)
}
if options.TransportExpectContinueTimeout != 3*time.Second {
t.Fatalf("expected value: %v got: %v", 3*time.Second, options.TransportExpectContinueTimeout)
}
if options.TransportIdleTimeout != 20*time.Second {
t.Fatalf("expected value: %v got: %v", 20*time.Second, options.TransportIdleTimeout)
}
if options.TransportMaxIdleConnections != 10 {
t.Fatalf("expected value: %v got: %v", 10, options.TransportMaxIdleConnections)
}
if options.TransportTLSHandshakeTimeout != 5*time.Second {
t.Fatalf("expected value: %v got: %v", 5*time.Second, options.TransportTLSHandshakeTimeout)
}
}
// TestClientDefaultOptions_NoRetry will set 0 retry counts
func TestClientDefaultOptions_NoRetry(t *testing.T) {
options := ClientDefaultOptions()
options.RequestRetryCount = 0
client := NewClient(options)
if client.UserAgent != defaultUserAgent {
t.Errorf("user agent mismatch")
}
}