Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: updated the error message after updated new jsonschema. #1011

Merged
merged 1 commit into from
Jan 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lua/apisix/schema_def.lua
Original file line number Diff line number Diff line change
@@ -218,6 +218,10 @@ local health_checker = {
}
},
additionalProperties = false,
anyOf = {
{required = {"active"}},
{required = {"active", "passive"}},
},
}


2 changes: 1 addition & 1 deletion rockspec/apisix-master-0.rockspec
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ dependencies = {
"luafilesystem = 1.7.0-2",
"lua-tinyyaml = 0.1",
"lua-resty-prometheus = 1.0",
"jsonschema = 0.4",
"jsonschema = 0.5",
"lua-resty-ipmatcher = 0.3",
}

48 changes: 48 additions & 0 deletions t/admin/health-check.t
Original file line number Diff line number Diff line change
@@ -106,6 +106,14 @@ passed
local t = require("lib.test_admin").test

req_data.upstream.checks = json.decode([[{
"active": {
"http_path": "/status",
"host": "foo.com",
"healthy": {
"interval": 2,
"successes": 1
}
},
"passive": {
"healthy": {
"http_statuses": [200, 201],
@@ -428,3 +436,43 @@ GET /t
{"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"checks\" validation failed: property \"active\" validation failed: property \"req_headers\" validation failed: failed to validate item 2: wrong type: expected string, got number"}
--- no_error_log
[error]



=== TEST 12: only passive
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test

req_data.upstream.checks = json.decode([[{
"passive": {
"healthy": {
"http_statuses": [200, 201],
"successes": 1
},
"unhealthy": {
"http_statuses": [500],
"http_failures": 2
}
}
}]])
exp_data.node.value.upstream.checks = req_data.upstream.checks

local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
req_data,
exp_data
)

ngx.status = code
ngx.print(body)
}
}
--- request
GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"checks\" validation failed: object matches none of the requireds: [\"active\"] or [\"active\",\"passive\"]"}
--- no_error_log
[error]
8 changes: 4 additions & 4 deletions t/admin/routes.t
Original file line number Diff line number Diff line change
@@ -447,7 +447,7 @@ GET /t
GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"service_id\" validation failed: object matches none of the alternatives"}
{"error_msg":"invalid configuration: property \"service_id\" validation failed: object matches none of the requireds"}
--- no_error_log
[error]

@@ -555,7 +555,7 @@ passed
GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the alternatives"}
{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the requireds"}
--- no_error_log
[error]

@@ -582,7 +582,7 @@ GET /t
GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"upstream_id\" validation failed: object matches none of the alternatives"}
{"error_msg":"invalid configuration: property \"upstream_id\" validation failed: object matches none of the requireds"}
--- no_error_log
[error]

@@ -949,7 +949,7 @@ passed
GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"remote_addr\" validation failed: object matches none of the alternatives"}
{"error_msg":"invalid configuration: property \"remote_addr\" validation failed: object matches none of the requireds"}
--- no_error_log
[error]

6 changes: 3 additions & 3 deletions t/admin/services.t
Original file line number Diff line number Diff line change
@@ -461,7 +461,7 @@ passed
GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the alternatives"}
{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the requireds"}
--- no_error_log
[error]

@@ -488,7 +488,7 @@ GET /t
GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the alternatives"}
{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the requireds"}
--- no_error_log
[error]

@@ -542,7 +542,7 @@ GET /t
GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"upstream_id\" validation failed: object matches none of the alternatives"}
{"error_msg":"invalid configuration: property \"upstream_id\" validation failed: object matches none of the requireds"}
--- no_error_log
[error]

4 changes: 2 additions & 2 deletions t/admin/upstream.t
Original file line number Diff line number Diff line change
@@ -360,7 +360,7 @@ passed
GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the alternatives"}
{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the requireds"}
--- no_error_log
[error]

@@ -390,7 +390,7 @@ GET /t
GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the alternatives"}
{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the requireds"}
--- no_error_log
[error]

2 changes: 1 addition & 1 deletion t/plugin/ip-restriction.t
Original file line number Diff line number Diff line change
@@ -565,6 +565,6 @@ GET /hello
GET /t
--- response_body
invalid ip address: ::1/129
property "whitelist" validation failed: failed to validate item 1: object matches none of the alternatives
property "whitelist" validation failed: failed to validate item 1: object matches none of the requireds
--- no_error_log
[error]