-
Notifications
You must be signed in to change notification settings - Fork 14
/
client_private_test.go
92 lines (80 loc) · 2.14 KB
/
client_private_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
package getstream
import (
"net/url"
"testing"
)
func TestClientRequestBadPath(t *testing.T) {
client, err := New(&Config{
APIKey: "my_key",
APISecret: "my_secret",
AppID: "111111",
Location: "us-east",
})
if err != nil {
t.Fatal(err)
}
_, err = client.request(nil, "get", ":hfi", []byte{}, map[string]string{})
if err.Error() != "parse :hfi: missing protocol scheme" {
t.Fatal("Expected error about bad URL path mismatch, got:", err.Error())
}
}
func TestClientSetStandardParams(t *testing.T) {
baseURL, _ := url.Parse("https://google.com/")
client := &Client{
BaseURL: baseURL,
Config: &Config{
APIKey: "my_api_key",
},
}
tempURL, err := url.Parse("/")
if err != nil {
t.Fatal(err)
}
apiURL := client.BaseURL.ResolveReference(tempURL)
query := apiURL.Query()
query = client.setStandardParams(query)
if _, ok := query["api_key"]; !ok {
t.Error("API key not set in query params:", query)
}
if query["api_key"][0] != "my_api_key" {
t.Error("API key didn't set as a URL param as expected, got:", query["api_key"][0])
}
if _, ok := query["location"]; !ok {
t.Error("Location not set in query params:", query)
}
if query["location"][0] != "unspecified" {
t.Error("Location didn't set as a URL param as expected, got:", query["location"][0])
}
}
func TestClientSetRequestParams(t *testing.T) {
baseURL, _ := url.Parse("https://google.com/")
client := &Client{
BaseURL: baseURL,
Config: &Config{
APIKey: "my_api_key",
},
}
tempURL, err := url.Parse("/")
if err != nil {
t.Fatal(err)
}
apiURL := client.BaseURL.ResolveReference(tempURL)
query := apiURL.Query()
// passing no params should give us nothing back
values := client.setRequestParams(query, map[string]string{})
if len(values) != 0 {
t.Fatal("Expected empty urlValues, got:", values)
}
values = client.setRequestParams(query, map[string]string{
"foo": "bar",
})
if values == nil {
t.Fatal("Expected urlValues, got nil")
}
if _, ok := query["foo"]; !ok {
t.Error("foo key not set in query params:", query)
}
if query["foo"][0] != "bar" {
t.Error("foo key didn't set as a URL param as expected, got:", query["foo"][0])
}
}