-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_test.go
47 lines (44 loc) · 964 Bytes
/
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
package xeno
import (
"net/url"
"reflect"
"testing"
)
func TestProcessOptions(t *testing.T) {
tests := []struct {
name string
options []RequestOption
expected url.Values
}{
{
name: "Page option sets the correct page value",
options: []RequestOption{
Page(1),
},
expected: url.Values{"page": []string{"1"}},
},
{
name: "No options provided",
options: []RequestOption{},
expected: url.Values{},
},
{
name: "Multiple options set correct values",
options: []RequestOption{
Page(2),
func(o *requestOptions) {
o.urlParams.Set("size", "10")
},
},
expected: url.Values{"page": []string{"2"}, "size": []string{"10"}},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := processOptions(test.options...)
if !reflect.DeepEqual(result.urlParams, test.expected) {
t.Errorf("Expected %v, got %v", test.expected, result.urlParams)
}
})
}
}