-
Notifications
You must be signed in to change notification settings - Fork 0
/
restful_test.go
54 lines (50 loc) · 1.11 KB
/
restful_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
package httputils
import (
"fmt"
"log"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetFilters(t *testing.T) {
testCases := []struct {
url string
pagination map[string]int
filters map[string][]string
}{
{
"http://test.domain/ressource?filter1=foo&filter2=bar&filter3=foo,bar",
map[string]int{
"limit": 100,
"page": 1,
},
map[string][]string{
"filter1": {"foo"},
"filter2": {"bar"},
"filter3": {"foo", "bar"},
},
},
{
"http://test.domain/ressource?limit=25&filter1=foo&filter2=bar&filter3=foo,bar",
map[string]int{
"limit": 25,
"page": 1,
},
map[string][]string{
"filter1": {"foo"},
"filter2": {"bar"},
"filter3": {"foo", "bar"},
},
},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("GetFilters %d", i), func(st *testing.T) {
url, _ := url.Parse(tc.url)
p, f, _ := GetFilters(url)
assert.Equal(t, tc.pagination["limit"], p["limit"])
assert.Equal(t, tc.pagination["page"], p["page"])
// assert.Equal(t, len(tc.expected.filters), len(f.filters))
log.Printf("%+v\n", f)
})
}
}