forked from galaxydi/go-loghub
-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathdefault_http_client_test.go
74 lines (67 loc) · 2.49 KB
/
default_http_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
package sls
import (
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestClientHttpClient(t *testing.T) {
assert.NotEqual(t, defaultRequestTimeout, time.Second*33)
{
c := CreateNormalInterface("cn-hangzhou.log.aliyuncs.com", "", "", "")
client := c.(*Client)
assert.True(t, client.HTTPClient == defaultHttpClient || client.HTTPClient == nil)
if client.HTTPClient != nil {
transport := client.HTTPClient.Transport.(*http.Transport)
assert.Equal(t, transport.IdleConnTimeout, defaultHTTPIdleTimeout)
assert.Equal(t, defaultHttpClient.Timeout, defaultRequestTimeout)
}
}
{
// with proxy
c := CreateNormalInterface("127.0.0.1", "", "", "")
client := c.(*Client)
assert.True(t, client.HTTPClient == defaultHttpClient || client.HTTPClient == nil)
{
transport := defaultHttpClient.Transport.(*http.Transport)
assert.Equal(t, transport.IdleConnTimeout, defaultHTTPIdleTimeout)
assert.Equal(t, defaultHttpClient.Timeout, defaultRequestTimeout)
}
p := convert(client, "test")
assert.NotNil(t, p.httpClient)
assert.NotEqual(t, p.httpClient, defaultHttpClient) // changed
{
transport := p.httpClient.Transport.(*http.Transport)
assert.Equal(t, p.httpClient.Timeout, defaultRequestTimeout)
assert.Equal(t, transport.IdleConnTimeout, defaultHTTPIdleTimeout)
assert.NotNil(t, transport.Proxy)
}
p = p.WithRequestTimeout(time.Second * 33)
assert.Equal(t, p.httpClient.Timeout, time.Second*33)
}
}
func TestProjectHttpClient(t *testing.T) {
assert.NotEqual(t, defaultRequestTimeout, time.Second*33)
{
p, err := NewLogProject("test-project", "cn-hangzhou.log.aliyuncs.com", "", "")
assert.NoError(t, err)
assert.Equal(t, p.httpClient, defaultHttpClient)
transport := p.httpClient.Transport.(*http.Transport)
assert.Equal(t, transport.IdleConnTimeout, defaultHTTPIdleTimeout)
assert.Equal(t, defaultHttpClient.Timeout, defaultRequestTimeout)
p = p.WithRequestTimeout(time.Second * 19)
assert.Equal(t, p.httpClient.Timeout, time.Second*19)
}
{
// with proxy
p, err := NewLogProject("test-project", "127.0.0.1", "", "")
assert.NoError(t, err)
assert.NotEqual(t, p.httpClient, defaultHttpClient) // changed
transport := p.httpClient.Transport.(*http.Transport)
assert.Equal(t, p.httpClient.Timeout, defaultRequestTimeout)
assert.Equal(t, transport.IdleConnTimeout, defaultHTTPIdleTimeout)
assert.NotNil(t, transport.Proxy)
p = p.WithRequestTimeout(time.Second * 19)
assert.Equal(t, p.httpClient.Timeout, time.Second*19)
}
}