-
Notifications
You must be signed in to change notification settings - Fork 182
/
Copy pathpath_pattern_2_spec.lua
executable file
·70 lines (62 loc) · 1.53 KB
/
path_pattern_2_spec.lua
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
before_each(function()
lor = _G.lor
app = lor({
debug = false
})
Request = _G.request
Response = _G.response
req = Request:new()
res = Response:new()
count = 0
match = 1
app:get("/all", function(req, res, next)
count = 1
end)
local testRouter = lor:Router()
testRouter:get("/all", function(req, res, next)
count = 6
match = 2
next()
end)
testRouter:get("/find/:type", function(req, res, next)
count = 7
next()
end)
app:use("/test", testRouter())
end)
after_each(function()
lor = nil
app = nil
Request = nil
Response = nil
req = nil
res = nil
match = nil
end)
describe("path match test", function()
it("test case 1", function()
req.path = "/test/all"
req.method = "get"
app:handle(req, res)
assert.is.equals(2, match)
assert.is.equals(6, count)
end)
it("test case 2", function()
req.path = "/test/find/all"
req.method = "get"
app:handle(req, res)
assert.is.equals(1, match) -- should not match "/test/all"
assert.is.equals(7, count)
end)
it("test case 3", function()
req.path = "/test/find/all/1"
req.method = "get"
app:erroruse(function(err, req, res, next) -- 404 error
assert.is.truthy(err)
assert.is.equals(false, req:is_found())
end)
app:handle(req, res)
assert.is.equals(1, match)
assert.is.equals(0, count)
end)
end)