generated from mrz1836/go-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_test.go
44 lines (37 loc) · 976 Bytes
/
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
package nownodes
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewClient(t *testing.T) {
t.Parallel()
t.Run("basic client", func(t *testing.T) {
c := NewClient()
require.NotNil(t, c)
client := c.HTTPClient()
require.NotNil(t, client)
ua := c.UserAgent()
assert.Equal(t, defaultUserAgent, ua)
})
t.Run("custom user agent", func(t *testing.T) {
c := NewClient(WithUserAgent("custom-agent"))
require.NotNil(t, c)
ua := c.UserAgent()
assert.Equal(t, "custom-agent", ua)
})
t.Run("custom http client", func(t *testing.T) {
hc := &http.Client{}
c := NewClient(WithHTTPClient(hc))
require.NotNil(t, c)
assert.Equal(t, hc, c.HTTPClient())
})
t.Run("custom http options, no retry", func(t *testing.T) {
opts := DefaultHTTPOptions()
opts.RequestRetryCount = 0
c := NewClient(WithHTTPOptions(opts))
require.NotNil(t, c)
require.NotNil(t, c.HTTPClient())
})
}