This repository was archived by the owner on Apr 17, 2025. It is now read-only.
generated from mrz1836/go-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient_options_test.go
More file actions
122 lines (101 loc) · 3.02 KB
/
client_options_test.go
File metadata and controls
122 lines (101 loc) · 3.02 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package nownodes
import (
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestDefaultHTTPOptions(t *testing.T) {
t.Parallel()
options := DefaultHTTPOptions()
assert.Equal(t, 10, options.TransportMaxIdleConnections)
assert.Equal(t, 2*time.Millisecond, options.BackOffInitialTimeout)
assert.Equal(t, 2*time.Millisecond, options.BackOffMaximumJitterInterval)
assert.Equal(t, 2, options.RequestRetryCount)
assert.Equal(t, 2.0, options.BackOffExponentFactor)
assert.Equal(t, 20*time.Second, options.DialerKeepAlive)
assert.Equal(t, 20*time.Second, options.TransportIdleTimeout)
assert.Equal(t, 3*time.Second, options.TransportExpectContinueTimeout)
assert.Equal(t, 30*time.Second, options.RequestTimeout)
assert.Equal(t, 5*time.Second, options.DialerTimeout)
assert.Equal(t, 5*time.Second, options.TransportTLSHandshakeTimeout)
}
func TestWithAPIKey(t *testing.T) {
t.Parallel()
t.Run("check type", func(t *testing.T) {
opt := WithAPIKey("")
assert.IsType(t, *new(ClientOps), opt)
})
t.Run("test applying empty", func(t *testing.T) {
options := &ClientOptions{}
opt := WithAPIKey("")
opt(options)
assert.Equal(t, "", options.apiKey)
})
t.Run("test applying option", func(t *testing.T) {
options := &ClientOptions{}
opt := WithAPIKey(testKey)
opt(options)
assert.Equal(t, testKey, options.apiKey)
})
}
func TestWithHTTPClient(t *testing.T) {
t.Parallel()
t.Run("check type", func(t *testing.T) {
opt := WithHTTPClient(nil)
assert.IsType(t, *new(ClientOps), opt)
})
t.Run("test applying nil", func(t *testing.T) {
options := &ClientOptions{}
opt := WithHTTPClient(nil)
opt(options)
assert.Nil(t, options.httpClient)
})
t.Run("test applying option", func(t *testing.T) {
options := &ClientOptions{}
customClient := &http.Client{}
opt := WithHTTPClient(customClient)
opt(options)
assert.Equal(t, customClient, options.httpClient)
})
}
func TestWithHTTPOptions(t *testing.T) {
t.Parallel()
t.Run("check type", func(t *testing.T) {
opt := WithHTTPOptions(nil)
assert.IsType(t, *new(ClientOps), opt)
})
t.Run("test applying nil", func(t *testing.T) {
options := &ClientOptions{}
opt := WithHTTPOptions(nil)
opt(options)
assert.Nil(t, options.httpOptions)
})
t.Run("test applying option", func(t *testing.T) {
options := &ClientOptions{}
customHTTPOpts := DefaultHTTPOptions()
customHTTPOpts.RequestRetryCount = 3
opt := WithHTTPOptions(customHTTPOpts)
opt(options)
assert.Equal(t, customHTTPOpts, options.httpOptions)
})
}
func TestWithUserAgent(t *testing.T) {
t.Parallel()
t.Run("check type", func(t *testing.T) {
opt := WithUserAgent("")
assert.IsType(t, *new(ClientOps), opt)
})
t.Run("test applying empty", func(t *testing.T) {
options := &ClientOptions{}
opt := WithUserAgent("")
opt(options)
assert.Equal(t, "", options.userAgent)
})
t.Run("test applying option", func(t *testing.T) {
options := &ClientOptions{}
opt := WithUserAgent(testUserAgent)
opt(options)
assert.Equal(t, testUserAgent, options.userAgent)
})
}