forked from s32x/httpclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
70 lines (60 loc) · 1.51 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
package httpclient
import (
"net/http"
"sync"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestClient(t *testing.T) {
c := New()
assert.Equal(t, &Client{
client: &http.Client{},
baseURL: "",
header: sync.Map{},
}, c)
c = c.WithClient(&http.Client{Timeout: 20 * time.Second})
assert.Equal(t, &Client{
client: &http.Client{Timeout: 20 * time.Second},
baseURL: "",
header: sync.Map{},
}, c)
c = c.WithTimeout(time.Second * 10)
assert.Equal(t, &Client{
client: &http.Client{Timeout: 10 * time.Second},
baseURL: "",
header: sync.Map{},
}, c)
c = c.WithBaseURL("https://example.com")
assert.Equal(t, &Client{
client: &http.Client{Timeout: 10 * time.Second},
baseURL: "https://example.com",
header: sync.Map{},
}, c)
// var m sync.Map
// m.Store("hkey", "hval")
// c = c.WithHeader("hkey", "hval")
// assert.Equal(t, &Client{
// client: &http.Client{Timeout: 10 * time.Second},
// baseURL: "https://example.com",
// header: m,
// expectedStatus: 200,
// retryCount: 0,
// }, c)
req := c.Request(http.MethodGet, "/test")
assert.Equal(t, &Request{
client: &http.Client{Timeout: 10 * time.Second},
method: "GET",
baseURL: "https://example.com",
path: "/test",
header: sync.Map{},
body: nil,
ctx: nil,
}, req)
// Verify generating the request hasn't modified the Client
assert.Equal(t, &Client{
client: &http.Client{Timeout: 10 * time.Second},
baseURL: "https://example.com",
header: sync.Map{},
}, c)
}