-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathpolicy_config_validator_spec.lua
58 lines (49 loc) · 1.7 KB
/
policy_config_validator_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
local cjson = require('cjson')
local policy_config_validator = require('apicast.policy_config_validator')
describe('policy_config_validator', function()
-- We use the echo policy schema as an example for the tests.
local test_config_schema = cjson.decode([[
{
"type": "object",
"properties": {
"status": {
"description": "HTTP status code to be returned",
"type": "integer"
},
"exit": {
"description": "Exit mode",
"type": "string",
"oneOf": [{
"enum": ["request"],
"description": "Interrupts the processing of the request."
},
{
"enum": ["set"],
"description": "Only skips the rewrite phase."
}
]
}
}
}
]])
it('returns true with a config that conforms with the schema', function()
local valid_config = { status = 200, exit = "request" }
local is_valid, err = policy_config_validator.validate_config(
valid_config, test_config_schema)
assert.is_true(is_valid)
assert.is_nil(err)
end)
it('returns false with a config that does not conform with the schema', function()
local invalid_config = { status = "not_an_integer" }
local is_valid, err = policy_config_validator.validate_config(
invalid_config, test_config_schema)
assert.is_false(is_valid)
assert.is_not_nil(err)
end)
it('returns true when the schema is empty', function()
assert.is_true(policy_config_validator.validate_config({ a_param = 1 }, {}))
end)
it('returns true when the schema is nil', function()
assert.is_true(policy_config_validator.validate_config({ a_param = 1 }, nil))
end)
end)