-
Notifications
You must be signed in to change notification settings - Fork 689
/
route_test.go
76 lines (67 loc) · 1.99 KB
/
route_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
package restful
import (
"testing"
)
// accept should match produces
func TestMatchesAcceptPlainTextWhenProducePlainTextAsLast(t *testing.T) {
r := Route{Produces: []string{"application/json", "text/plain"}}
if !r.matchesAccept("text/plain") {
t.Errorf("accept should match text/plain")
}
}
// accept should match produces
func TestMatchesAcceptStar(t *testing.T) {
r := Route{Produces: []string{"application/xml"}}
if !r.matchesAccept("*/*") {
t.Errorf("accept should match star")
}
}
// accept should match produces
func TestMatchesAcceptIE(t *testing.T) {
r := Route{Produces: []string{"application/xml"}}
if !r.matchesAccept("text/html, application/xhtml+xml, */*") {
t.Errorf("accept should match star")
}
}
// accept should match produces
func TestMatchesAcceptXml(t *testing.T) {
r := Route{Produces: []string{"application/xml"}}
if r.matchesAccept("application/json") {
t.Errorf("accept should not match json")
}
if !r.matchesAccept("application/xml") {
t.Errorf("accept should match xml")
}
}
// accept should match produces
func TestMatchesAcceptAny(t *testing.T) {
r := Route{Produces: []string{"*/*"}}
if !r.matchesAccept("application/json") {
t.Errorf("accept should match json")
}
if !r.matchesAccept("application/xml") {
t.Errorf("accept should match xml")
}
}
// content type should match consumes
func TestMatchesContentTypeXml(t *testing.T) {
r := Route{Consumes: []string{"application/xml"}}
if r.matchesContentType("application/json") {
t.Errorf("accept should not match json")
}
if !r.matchesContentType("application/xml") {
t.Errorf("accept should match xml")
}
}
// content type should match consumes
func TestMatchesContentTypeCharsetInformation(t *testing.T) {
r := Route{Consumes: []string{"application/json"}}
if !r.matchesContentType("application/json; charset=UTF-8") {
t.Errorf("matchesContentType should ignore charset information")
}
}
func TestTokenizePath(t *testing.T) {
if len(tokenizePath("/")) != 0 {
t.Errorf("not empty path tokens")
}
}