-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient_test.go
97 lines (73 loc) · 2.5 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
package simpleresty
import (
"github.com/go-resty/resty/v2"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func TestClient_RequestURL_BaseUrlSet(t *testing.T) {
c := &Client{Client: resty.New(), baseURL: "https://sass.com/api/v1"}
assert.Equal(t, "https://sass.com/api/v1/apps", c.RequestURL("/apps"))
}
func TestClient_RequestURL_BaseUrlSetWithArgs(t *testing.T) {
c := &Client{Client: resty.New(), baseURL: "https://sass.com/api/v1"}
assert.Equal(t, "https://sass.com/api/v1/apps/123", c.RequestURL("/apps/%s", "123"))
}
func TestClient_RequestURL_BaseUrlNotSet(t *testing.T) {
c := &Client{Client: resty.New()}
assert.Panics(t, func() { c.RequestURL("/apps") })
}
func TestClient_SetBaseURL(t *testing.T) {
c := &Client{Client: resty.New()}
c.SetBaseURL("https://www.google.com/api/v1")
assert.Equal(t, "https://www.google.com/api/v1", c.baseURL)
}
func TestClient_RequestURLWithQueryParams(t *testing.T) {
c := &Client{Client: resty.New(), baseURL: "https://sass.com/api/v1"}
queryParams := struct {
Since string `url:"since,omitempty"`
Page int `url:"page,omitempty"`
}{
Since: "3days",
Page: 4,
}
url, err := c.RequestURLWithQueryParams("/apps", queryParams)
assert.Nil(t, err)
assert.Equal(t, "https://sass.com/api/v1/apps?page=4&since=3days", url)
}
func TestClient_RequestURLWithNoQueryParams(t *testing.T) {
c := &Client{Client: resty.New(), baseURL: "https://sass.com/api/v1"}
url, err := c.RequestURLWithQueryParams("/apps")
assert.Nil(t, err)
assert.Equal(t, "https://sass.com/api/v1/apps", url)
}
func TestDetermineSetProxy_HttpsBasic(t *testing.T) {
proxyURL := "some.url:8080"
c := &Client{Client: resty.New()}
c.proxyURL = &proxyURL
setErr := os.Setenv("https_proxy", "some.url:8080")
assert.Nil(t, setErr)
c.determineSetProxy()
assert.Equal(t, true, c.IsProxySet())
_ = os.Setenv("https_proxy", "")
}
func TestDetermineSetProxy_WithNoProxySet(t *testing.T) {
proxyURL := "some.url:8080"
c := &Client{Client: resty.New()}
c.proxyURL = &proxyURL
c.noProxyDomains = []string{"somedirect0.url", "somedirecturl.com"}
c.SetBaseURL("https://somedirecturl.com/api/1")
c.determineSetProxy()
assert.Equal(t, false, c.IsProxySet())
}
func TestDetermineSetProxy_NoneSet(t *testing.T) {
c := &Client{Client: resty.New()}
c.determineSetProxy()
assert.Equal(t, false, c.IsProxySet())
}
func TestDetermineSetProxy_ProxyAlreadySet(t *testing.T) {
c := &Client{Client: resty.New()}
c.SetProxy("some.url:8080")
c.determineSetProxy()
assert.Equal(t, true, c.IsProxySet())
}