Skip to content

Commit

Permalink
fix(tests) healthcheck headers
Browse files Browse the repository at this point in the history
  • Loading branch information
mayocream committed Jan 2, 2022
1 parent 1589da5 commit bd64c8b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
5 changes: 3 additions & 2 deletions kong/db/schema/entities/upstreams.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ local check_verify_certificate = Schema.define {

local check_headers = Schema.define {
type = "array",
len_min = 1,
elements = {
type = "string",
len_min = 1,
unique = true,
},
}

Expand All @@ -99,7 +100,7 @@ local healthchecks_config = {
http_path = "/",
https_sni = NO_DEFAULT,
https_verify_certificate = true,
headers = {""},
headers = NO_DEFAULT,
healthy = {
interval = 0, -- 0 = probing disabled by default
http_statuses = { 200, 302 },
Expand Down
24 changes: 13 additions & 11 deletions spec/01-unit/01-db/01-schema/09-upstreams_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("load upstreams", function()
it("invalid healthckecks.active.headers produces error", function()
local ok, errs = validate({ healthchecks = { active = { headers = { 114514 } } } } )
assert.falsy(ok)
assert.truthy(errs.healthchecks.active.http_path)
assert.truthy(errs.healthchecks.active.headers)
end)

it("invalid healthckecks.active.http_path produces error", function()
Expand Down Expand Up @@ -276,11 +276,12 @@ describe("load upstreams", function()
local pos_integer = "value should be between 1 and 2147483648"
local zero_integer = "value should be between 0 and 255"
local status_code = "value should be between 100 and 999"
local string = "expected a string"
local empty_string = "vaule must be non-empty string"
local integer = "expected an integer"
local boolean = "expected a boolean"
local number = "expected a number"
local array = "expected an array"
local string = "expected a string"
local len_min_default = "length must be at least 1"
local invalid_host = "invalid value: "
local invalid_host_port = "must not have a port"
local invalid_ip = "must not be an IP"
Expand All @@ -291,7 +292,7 @@ describe("load upstreams", function()
{{ active = { concurrency = 0.5 }}, integer },
{{ active = { concurrency = 0 }}, pos_integer },
{{ active = { concurrency = -10 }}, pos_integer },
{{ active = { http_path = "" }}, "length must be at least 1" },
{{ active = { http_path = "" }}, len_min_default },
{{ active = { http_path = "ovo" }}, "should start with: /" },
{{ active = { https_sni = "127.0.0.1", }}, invalid_ip },
{{ active = { https_sni = "127.0.0.1:8080", }}, invalid_ip },
Expand All @@ -306,13 +307,14 @@ describe("load upstreams", function()
{{ active = { https_sni = "hello-.example.com", }}, invalid_host },
{{ active = { https_sni = "example.com:1234", }}, invalid_host_port },
{{ active = { https_verify_certificate = "ovo", }}, boolean },
{{ active = { headers = 0, }}, "expected an array" },
{{ active = { headers = 0, }}, array },
{{ active = { headers = {}, }}, len_min_default },
{{ active = { headers = { 0 }, }}, string },
{{ active = { headers = { "" }, }}, empty_string },
{{ active = { headers = { 0, "example" }, }}, string },
{{ active = { headers = { "" }, }}, len_min_default },
{{ active = { headers = { 123, "example" }, }}, string },
{{ active = { healthy = { interval = -1 }}}, seconds },
{{ active = { healthy = { interval = 1e+42 }}}, seconds },
{{ active = { healthy = { http_statuses = 404 }}}, "expected an array" },
{{ active = { healthy = { http_statuses = 404 }}}, array },
{{ active = { healthy = { http_statuses = { "ovo" }}}}, integer },
{{ active = { healthy = { http_statuses = { -1 }}}}, status_code },
{{ active = { healthy = { http_statuses = { 99 }}}}, status_code },
Expand All @@ -328,7 +330,7 @@ describe("load upstreams", function()
{{ active = { healthy = { successes = 256 }}}, zero_integer },
{{ active = { unhealthy = { interval = -1 }}}, seconds },
{{ active = { unhealthy = { interval = 1e+42 }}}, seconds },
{{ active = { unhealthy = { http_statuses = 404 }}}, "expected an array" },
{{ active = { unhealthy = { http_statuses = 404 }}}, array },
{{ active = { unhealthy = { http_statuses = { "ovo" }}}}, integer },
{{ active = { unhealthy = { http_statuses = { -1 }}}}, status_code },
{{ active = { unhealthy = { http_statuses = { 99 }}}}, status_code },
Expand All @@ -344,15 +346,15 @@ describe("load upstreams", function()
{{ active = { unhealthy = { http_failures = 0.5 }}}, integer},
{{ active = { unhealthy = { http_failures = -1 }}}, zero_integer },
{{ active = { unhealthy = { http_failures = 256 }}}, zero_integer },
{{ passive = { healthy = { http_statuses = 404 }}}, "expected an array" },
{{ passive = { healthy = { http_statuses = 404 }}}, array },
{{ passive = { healthy = { http_statuses = { "ovo" }}}}, integer },
{{ passive = { healthy = { http_statuses = { -1 }}}}, status_code },
{{ passive = { healthy = { http_statuses = { 99 }}}}, status_code },
{{ passive = { healthy = { http_statuses = { 1000 }}}}, status_code },
{{ passive = { healthy = { successes = 0.5 }}}, integer },
--{{ passive = { healthy = { successes = 0 }}}, integer },
{{ passive = { healthy = { successes = -1 }}}, zero_integer },
{{ passive = { unhealthy = { http_statuses = 404 }}}, "expected an array" },
{{ passive = { unhealthy = { http_statuses = 404 }}}, array },
{{ passive = { unhealthy = { http_statuses = { "ovo" }}}}, integer },
{{ passive = { unhealthy = { http_statuses = { -1 }}}}, status_code },
{{ passive = { unhealthy = { http_statuses = { 99 }}}}, status_code },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,7 @@ describe("declarative config: flatten", function()
http_path = "/",
https_sni = null,
https_verify_certificate = true,
headers = null,
timeout = 1,
type = "http",
unhealthy = {
Expand Down Expand Up @@ -1832,6 +1833,7 @@ describe("declarative config: flatten", function()
http_path = "/",
https_sni = null,
https_verify_certificate = true,
headers = null,
timeout = 1,
type = "http",
unhealthy = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ for _, strategy in helpers.each_strategy() do
http_path = "/status",
https_sni = cjson.null,
https_verify_certificate = true,
headers = cjson.null,
timeout = 1,
unhealthy = {
http_failures = 1,
Expand Down

0 comments on commit bd64c8b

Please sign in to comment.