-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapping_rule_spec.lua
125 lines (106 loc) · 3.74 KB
/
mapping_rule_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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
local MappingRule = require('apicast.mapping_rule')
describe('mapping_rule', function()
describe('.from_proxy_rule', function()
it('sets "last"', function()
local mapping_rule = MappingRule.from_proxy_rule({
last = true,
http_method = 'GET',
pattern = '/abc',
querystring_parameters = { a_param = '1' },
metric_system_name = 'hits',
delta = 1
})
assert.is_true(mapping_rule.last)
end)
it('sets "last" to false by default', function()
local mapping_rule = MappingRule.from_proxy_rule({
http_method = 'GET',
pattern = '/abc',
querystring_parameters = { a_param = '1' },
metric_system_name = 'hits',
delta = 1
})
assert.is_false(mapping_rule.last)
end)
end)
describe('.matches', function()
it('returns true when method, URI, and args match', function()
local mapping_rule = MappingRule.from_proxy_rule({
http_method = 'GET',
pattern = '/abc',
querystring_parameters = { a_param = '1' },
metric_system_name = 'hits',
delta = 1
})
local match = mapping_rule:matches('GET', '/abc', { a_param = '1' })
assert.is_true(match)
end)
it('returns true when method and URI match, and no args are required', function()
local mapping_rule = MappingRule.from_proxy_rule({
http_method = 'GET',
pattern = '/abc',
querystring_parameters = { },
metric_system_name = 'hits',
delta = 1
})
local match = mapping_rule:matches('GET', '/abc', { a_param = '1' })
assert.is_true(match)
end)
it('returns false when the method does not match', function()
local mapping_rule = MappingRule.from_proxy_rule({
http_method = 'GET',
pattern = '/abc',
querystring_parameters = { a_param = '1' },
metric_system_name = 'hits',
delta = 1
})
local match = mapping_rule:matches('POST', '/abc', { a_param = '1' })
assert.is_false(match)
end)
it('returns false when the URI does not match', function()
local mapping_rule = MappingRule.from_proxy_rule({
http_method = 'GET',
pattern = '/abc',
querystring_parameters = { a_param = '1' },
metric_system_name = 'hits',
delta = 1
})
local match = mapping_rule:matches('GET', '/aaa', { a_param = '1' })
assert.is_false(match)
end)
it('returns false when the args do not match', function()
local mapping_rule = MappingRule.from_proxy_rule({
http_method = 'GET',
pattern = '/abc',
querystring_parameters = { a_param = '1' },
metric_system_name = 'hits',
delta = 1
})
local match = mapping_rule:matches('GET', '/abc', { a_param = '2' })
assert.is_false(match)
end)
it('returns false when method, URI, and args do not match', function()
local mapping_rule = MappingRule.from_proxy_rule({
http_method = 'GET',
pattern = '/abc',
querystring_parameters = { a_param = '1' },
metric_system_name = 'hits',
delta = 1
})
local match = mapping_rule:matches('POST', '/def', { x = 'y' })
assert.is_false(match)
end)
it('returns true when wildcard value has special characters: @ : % etc.', function()
local mapping_rule = MappingRule.from_proxy_rule({
http_method = 'GET',
pattern = '/foo/{wildcard}/bar',
querystring_parameters = { },
metric_system_name = 'hits',
delta = 1
})
assert.is_true(mapping_rule:matches('GET', '/foo/a@b/bar'))
assert.is_true(mapping_rule:matches('GET', '/foo/a:b/bar'))
assert.is_true(mapping_rule:matches('GET', "/foo/a%b/bar"))
end)
end)
end)