Skip to content

Commit

Permalink
chore(*) remove deprecated fallback on field 'type' (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Sep 20, 2020
1 parent 7e1b338 commit 52a010c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ Versioning is strictly based on [Semantic Versioning](https://semver.org/)

### Unreleased

* BREAKING: fallback for deprecated top-level field `type` is now removed
(deprecated since `0.5.0`) [#56](https://github.com/Kong/lua-resty-healthcheck/pull/56)
* BREAKING: Bump `lua-resty-worker-events` dependency to `2.0.0`. This makes
a lot of the APIs in this library asynchronous as the worker events `post`
and `post_local` won't anymore call `poll` on a running worker automatically,
Expand Down
11 changes: 0 additions & 11 deletions lib/resty/healthcheck.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1341,19 +1341,8 @@ function _M.new(opts)
assert(worker_events.configured(), "please configure the " ..
"'lua-resty-worker-events' module before using 'lua-resty-healthcheck'")

local active_type = (((opts or EMPTY).checks or EMPTY).active or EMPTY).type
local passive_type = (((opts or EMPTY).checks or EMPTY).passive or EMPTY).type

local self = fill_in_settings(opts, defaults)

-- If using deprecated self.type, that takes precedence over
-- a default value. TODO: remove this in a future version
if self.type then
self.checks.active.type = active_type or self.type
self.checks.passive.type = passive_type or self.type
check_valid_type("type", self.type)
end

assert(self.checks.active.healthy.successes < 255, "checks.active.healthy.successes must be at most 254")
assert(self.checks.active.unhealthy.tcp_failures < 255, "checks.active.unhealthy.tcp_failures must be at most 254")
assert(self.checks.active.unhealthy.http_failures < 255, "checks.active.unhealthy.http_failures must be at most 254")
Expand Down
31 changes: 27 additions & 4 deletions t/00-new.t
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ GET /t
--- error_log
Healthchecker started!

=== TEST 6: new() only accepts http or tcp types
=== TEST 6: new() only accepts http(s) or tcp types
--- http_config eval: $::HttpConfig
--- config
location = /t {
Expand All @@ -130,19 +130,41 @@ Healthchecker started!
local ok, err = pcall(healthcheck.new, {
name = "testing",
shm_name = "test_shm",
type = "http",
checks = {
active = {
type = "http",
},
}
})
ngx.say(ok)
local ok, err = pcall(healthcheck.new, {
name = "testing",
shm_name = "test_shm",
type = "tcp",
checks = {
active = {
type = "https",
},
}
})
ngx.say(ok)
local ok, err = pcall(healthcheck.new, {
name = "testing",
shm_name = "test_shm",
type = "get lost",
checks = {
active = {
type = "tcp",
},
}
})
ngx.say(ok)
local ok, err = pcall(healthcheck.new, {
name = "testing",
shm_name = "test_shm",
checks = {
active = {
type = "get lost",
},
}
})
ngx.say(ok)
}
Expand All @@ -152,6 +174,7 @@ GET /t
--- response_body
true
true
true
false

=== TEST 7: new() deals with bad inputs
Expand Down
9 changes: 6 additions & 3 deletions t/05-report_failure.t
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ qq{
local checker = healthcheck.new({
name = "testing",
shm_name = "test_shm",
type = "http",
checks = {
active = {
type = "http",
http_path = "/status",
healthy = {
interval = 999, -- we don't want active checks
Expand All @@ -55,6 +55,7 @@ qq{
}
},
passive = {
type = "http",
healthy = {
successes = 3,
},
Expand Down Expand Up @@ -119,9 +120,9 @@ qq{
local checker = healthcheck.new({
name = "testing",
shm_name = "test_shm",
type = "tcp",
checks = {
active = {
type = "tcp",
http_path = "/status",
healthy = {
interval = 999, -- we don't want active checks
Expand All @@ -134,6 +135,7 @@ qq{
}
},
passive = {
type = "tcp",
healthy = {
successes = 3,
},
Expand Down Expand Up @@ -196,9 +198,9 @@ qq{
local checker = healthcheck.new({
name = "testing",
shm_name = "test_shm",
type = "tcp",
checks = {
active = {
type = "tcp",
http_path = "/status",
healthy = {
interval = 999, -- we don't want active checks
Expand All @@ -211,6 +213,7 @@ qq{
}
},
passive = {
type = "tcp",
healthy = {
successes = 3,
},
Expand Down

0 comments on commit 52a010c

Please sign in to comment.