...
Source file
src/goji.io/pat/methods_test.go
1 package pat
2
3 import "testing"
4
5 func TestNewWithMethods(t *testing.T) {
6 t.Parallel()
7 pat := NewWithMethods("/", "LOCK", "UNLOCK")
8 if pat.Match(mustReq("POST", "/")) != nil {
9 t.Errorf("pattern was LOCK/UNLOCK, but matched POST")
10 }
11 if pat.Match(mustReq("LOCK", "/")) == nil {
12 t.Errorf("pattern didn't match LOCK")
13 }
14 if pat.Match(mustReq("UNLOCK", "/")) == nil {
15 t.Errorf("pattern didn't match UNLOCK")
16 }
17 }
18 func TestDelete(t *testing.T) {
19 t.Parallel()
20 pat := Delete("/")
21 if pat.Match(mustReq("GET", "/")) != nil {
22 t.Errorf("pattern was DELETE, but matched GET")
23 }
24 if pat.Match(mustReq("DELETE", "/")) == nil {
25 t.Errorf("pattern didn't match DELETE")
26 }
27 }
28
29 func TestGet(t *testing.T) {
30 t.Parallel()
31 pat := Get("/")
32 if pat.Match(mustReq("POST", "/")) != nil {
33 t.Errorf("pattern was GET, but matched POST")
34 }
35 if pat.Match(mustReq("GET", "/")) == nil {
36 t.Errorf("pattern didn't match GET")
37 }
38 if pat.Match(mustReq("HEAD", "/")) == nil {
39 t.Errorf("pattern didn't match HEAD")
40 }
41 }
42
43 func TestHead(t *testing.T) {
44 t.Parallel()
45 pat := Head("/")
46 if pat.Match(mustReq("GET", "/")) != nil {
47 t.Errorf("pattern was HEAD, but matched GET")
48 }
49 if pat.Match(mustReq("HEAD", "/")) == nil {
50 t.Errorf("pattern didn't match HEAD")
51 }
52 }
53
54 func TestOptions(t *testing.T) {
55 t.Parallel()
56 pat := Options("/")
57 if pat.Match(mustReq("GET", "/")) != nil {
58 t.Errorf("pattern was OPTIONS, but matched GET")
59 }
60 if pat.Match(mustReq("OPTIONS", "/")) == nil {
61 t.Errorf("pattern didn't match OPTIONS")
62 }
63 }
64
65 func TestPatch(t *testing.T) {
66 t.Parallel()
67 pat := Patch("/")
68 if pat.Match(mustReq("GET", "/")) != nil {
69 t.Errorf("pattern was PATCH, but matched GET")
70 }
71 if pat.Match(mustReq("PATCH", "/")) == nil {
72 t.Errorf("pattern didn't match PATCH")
73 }
74 }
75
76 func TestPost(t *testing.T) {
77 t.Parallel()
78 pat := Post("/")
79 if pat.Match(mustReq("GET", "/")) != nil {
80 t.Errorf("pattern was POST, but matched GET")
81 }
82 if pat.Match(mustReq("POST", "/")) == nil {
83 t.Errorf("pattern didn't match POST")
84 }
85 }
86
87 func TestPut(t *testing.T) {
88 t.Parallel()
89 pat := Put("/")
90 if pat.Match(mustReq("GET", "/")) != nil {
91 t.Errorf("pattern was PUT, but matched GET")
92 }
93 if pat.Match(mustReq("PUT", "/")) == nil {
94 t.Errorf("pattern didn't match PUT")
95 }
96 }
97
View as plain text