-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathoptions_test.go
64 lines (52 loc) · 1.59 KB
/
options_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
package nationbuilder
import (
"net/url"
"testing"
)
const testQueryParam = "testQueryParam"
const testQueryValue = "testQueryValue"
const testURL = "https://testslug.nationbuilder.com/api/v1/foo"
func TestSetQueryOptions(t *testing.T) {
o := NewOptions()
o.SetQueryOption(testQueryParam, testQueryValue)
v := o.queryOpts.Get(testQueryParam)
if v != testQueryValue {
t.Errorf("Expected query param %s to be set with value %s but saw %s instead", testQueryParam, testQueryValue, v)
}
// contains nil queryOpts - should be initialised if nil
o = &Options{}
o.SetQueryOption(testQueryParam, testQueryValue)
v = o.queryOpts.Get(testQueryParam)
if v != testQueryValue {
t.Errorf("Expected query param %s to be set with value %s but saw %s instead", testQueryParam, testQueryValue, v)
}
}
func TestSetQuery(t *testing.T) {
u, err := url.Parse(testURL)
if err != nil {
t.Fatal(err.Error())
}
o := NewOptions()
o.SetQueryOption(testQueryParam, testQueryValue)
o.setQuery(u)
expectedURL := testURL + "?" + testQueryParam + "=" + testQueryValue
if u.String() != expectedURL {
t.Errorf("Expected SetQuery to make url %s but saw %s", expectedURL, u.String())
}
testToken := "testToken"
testNonce := "testNonce"
o = &Options{
Limit: 100,
PageToken: testToken,
PageNonce: testNonce,
}
u, err = url.Parse(testURL)
if err != nil {
t.Fatal(err.Error())
}
o.setQuery(u)
expectedURL = testURL + "?__nonce=" + testNonce + "&__token=" + testToken + "&limit=100"
if u.String() != expectedURL {
t.Errorf("Expected SetQuery to make url %s but saw %s", expectedURL, u.String())
}
}