File: methods_test.go

package info (click to toggle)
golang-goji 2.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 200 kB
  • sloc: makefile: 2
file content (96 lines) | stat: -rw-r--r-- 2,262 bytes parent folder | download
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package pat

import "testing"

func TestNewWithMethods(t *testing.T) {
	t.Parallel()
	pat := NewWithMethods("/", "LOCK", "UNLOCK")
	if pat.Match(mustReq("POST", "/")) != nil {
		t.Errorf("pattern was LOCK/UNLOCK, but matched POST")
	}
	if pat.Match(mustReq("LOCK", "/")) == nil {
		t.Errorf("pattern didn't match LOCK")
	}
	if pat.Match(mustReq("UNLOCK", "/")) == nil {
		t.Errorf("pattern didn't match UNLOCK")
	}
}
func TestDelete(t *testing.T) {
	t.Parallel()
	pat := Delete("/")
	if pat.Match(mustReq("GET", "/")) != nil {
		t.Errorf("pattern was DELETE, but matched GET")
	}
	if pat.Match(mustReq("DELETE", "/")) == nil {
		t.Errorf("pattern didn't match DELETE")
	}
}

func TestGet(t *testing.T) {
	t.Parallel()
	pat := Get("/")
	if pat.Match(mustReq("POST", "/")) != nil {
		t.Errorf("pattern was GET, but matched POST")
	}
	if pat.Match(mustReq("GET", "/")) == nil {
		t.Errorf("pattern didn't match GET")
	}
	if pat.Match(mustReq("HEAD", "/")) == nil {
		t.Errorf("pattern didn't match HEAD")
	}
}

func TestHead(t *testing.T) {
	t.Parallel()
	pat := Head("/")
	if pat.Match(mustReq("GET", "/")) != nil {
		t.Errorf("pattern was HEAD, but matched GET")
	}
	if pat.Match(mustReq("HEAD", "/")) == nil {
		t.Errorf("pattern didn't match HEAD")
	}
}

func TestOptions(t *testing.T) {
	t.Parallel()
	pat := Options("/")
	if pat.Match(mustReq("GET", "/")) != nil {
		t.Errorf("pattern was OPTIONS, but matched GET")
	}
	if pat.Match(mustReq("OPTIONS", "/")) == nil {
		t.Errorf("pattern didn't match OPTIONS")
	}
}

func TestPatch(t *testing.T) {
	t.Parallel()
	pat := Patch("/")
	if pat.Match(mustReq("GET", "/")) != nil {
		t.Errorf("pattern was PATCH, but matched GET")
	}
	if pat.Match(mustReq("PATCH", "/")) == nil {
		t.Errorf("pattern didn't match PATCH")
	}
}

func TestPost(t *testing.T) {
	t.Parallel()
	pat := Post("/")
	if pat.Match(mustReq("GET", "/")) != nil {
		t.Errorf("pattern was POST, but matched GET")
	}
	if pat.Match(mustReq("POST", "/")) == nil {
		t.Errorf("pattern didn't match POST")
	}
}

func TestPut(t *testing.T) {
	t.Parallel()
	pat := Put("/")
	if pat.Match(mustReq("GET", "/")) != nil {
		t.Errorf("pattern was PUT, but matched GET")
	}
	if pat.Match(mustReq("PUT", "/")) == nil {
		t.Errorf("pattern didn't match PUT")
	}
}