-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrestclient_test.go
81 lines (69 loc) · 1.9 KB
/
restclient_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
package oneandone
import (
"testing"
)
func TestCreateUrl_1(t *testing.T) {
api := New("token", "http://test.de/v1")
result := createUrl(api)
if result != "http://test.de/v1" {
t.Errorf("Failed to create url.")
}
}
func TestCreateUrl_2(t *testing.T) {
api := New("token", "http://test.de/v1")
result := createUrl(api, "servers")
if result != "http://test.de/v1/servers" {
t.Errorf("Failed to create url.")
}
}
func TestCreateUrl_3(t *testing.T) {
api := New("token", "http://test.de/v1")
result := createUrl(api, "servers", 1)
if result != "http://test.de/v1/servers/1" {
t.Errorf("Failed to create url.")
}
}
func TestAppendQueryParams_1(t *testing.T) {
params := map[string]interface{}{
"foo": "bar",
}
result := appendQueryParams("http://test/", params)
if result != "http://test/?foo=bar" {
t.Errorf("Failed to create url with query parameters.")
}
}
func TestAppendQueryParams_2(t *testing.T) {
params := map[string]interface{}{
"foo": "bar",
"size": 5,
}
result := appendQueryParams("http://test/", params)
if result != "http://test/?foo=bar&size=5" {
t.Errorf("Failed to create url with query parameters.")
}
}
func TestAppendQueryParams_3(t *testing.T) {
params := map[string]interface{}{}
result := appendQueryParams("http://test/", params)
if result != "http://test/" {
t.Errorf("Failed to create url with query parameters.")
}
}
func TestAppendQueryParams_UrlEncode_1(t *testing.T) {
params := map[string]interface{}{
"test": "1&2=3",
}
result := appendQueryParams("http://test/", params)
if result != "http://test/?test=1%262%3D3" {
t.Errorf("Failed to create url with query parameters.")
}
}
func TestAppendQueryParams_UrlEncode_2(t *testing.T) {
params := map[string]interface{}{
"test!": "1&2=3",
}
result := appendQueryParams("http://test/", params)
if result != "http://test/?test%21=1%262%3D3" {
t.Errorf("Failed to create url with query parameters.")
}
}