Skip to content

Commit

Permalink
tests(busted): use lazy_ variants of setup/teardown helpers
Browse files Browse the repository at this point in the history
Our tests should pretty much always prefer lazy_setup/lazy_teardown so
that these handlers are not executed when tests are filtered out.
  • Loading branch information
flrgh committed Dec 6, 2024
1 parent d921983 commit e41a61f
Show file tree
Hide file tree
Showing 45 changed files with 126 additions and 126 deletions.
4 changes: 2 additions & 2 deletions spec/01-unit/01-db/06-postgres_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe("kong.db [#postgres] connector", function()
-- connector in a new scope
local connector

setup(function()
lazy_setup(function()
local new_config = {
pg_database = "kong",
pg_max_concurrent_queries = 1,
Expand Down Expand Up @@ -189,7 +189,7 @@ describe("kong.db [#postgres] connector", function()
-- connector in a new scope
local connector

setup(function()
lazy_setup(function()
local new_config = {
pg_database = "kong",
pg_max_concurrent_queries = 2,
Expand Down
12 changes: 6 additions & 6 deletions spec/01-unit/09-balancer/01-generic_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ for _, algorithm in ipairs{ "consistent-hashing", "least-connections", "round-ro

local snapshot

setup(function()
lazy_setup(function()
_G.package.loaded["kong.resty.dns.client"] = nil -- make sure module is reloaded
_G.package.loaded["kong.runloop.balancer.targets"] = nil -- make sure module is reloaded

Expand Down Expand Up @@ -901,7 +901,7 @@ for _, algorithm in ipairs{ "consistent-hashing", "least-connections", "round-ro
describe("(SRV)", function()

local srv_name = enable_new_dns_client and "_test._tcp.srvrecord.test"
or "srvrecord.test"
or "srvrecord.test"
it("adding a host",function()
dnsSRV({
{ name = srv_name, target = "1.1.1.1", port = 9000, weight = 10 },
Expand Down Expand Up @@ -1479,7 +1479,7 @@ for _, algorithm in ipairs{ "consistent-hashing", "least-connections", "round-ro
{ name = "getkong.test", address = "1.2.3.4" },
})
local srv_name = enable_new_dns_client and "_test._tcp.konghq.test"
or "konghq.test"
or "konghq.test"
dnsSRV({
{ name = srv_name, target = "getkong.test", port = 2, weight = 3 },
})
Expand Down Expand Up @@ -1514,7 +1514,7 @@ for _, algorithm in ipairs{ "consistent-hashing", "least-connections", "round-ro
{ name = "getkong.test", address = "1.2.3.4" },
})
local srv_name = enable_new_dns_client and "_test._tcp.konghq.test"
or "konghq.test"
or "konghq.test"
dnsSRV({
{ name = srv_name, target = "getkong.test", port = 2, weight = 3 },
})
Expand All @@ -1531,7 +1531,7 @@ for _, algorithm in ipairs{ "consistent-hashing", "least-connections", "round-ro
describe("getpeer()", function()

local srv_name = enable_new_dns_client and "_test._tcp.konghq.test"
or "konghq.test"
or "konghq.test"
local b

before_each(function()
Expand Down Expand Up @@ -1735,7 +1735,7 @@ for _, algorithm in ipairs{ "consistent-hashing", "least-connections", "round-ro

describe("status:", function()
local srv_name = enable_new_dns_client and "_test._tcp.srvrecord.test"
or "srvrecord.test"
or "srvrecord.test"

local b

Expand Down
2 changes: 1 addition & 1 deletion spec/01-unit/09-balancer/02-least_connections_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe("[least-connections]" .. (enable_new_dns_client and "[new dns]" or ""),

local snapshot

setup(function()
lazy_setup(function()
_G.busted_new_dns_client = enable_new_dns_client

_G.package.loaded["kong.resty.dns.client"] = nil -- make sure module is reloaded
Expand Down
2 changes: 1 addition & 1 deletion spec/01-unit/09-balancer/03-consistent_hashing_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ describe("[consistent_hashing]" .. (enable_new_dns_client and "[new dns]" or "")
or "gelato.io"
local snapshot

setup(function()
lazy_setup(function()
_G.busted_new_dns_client = enable_new_dns_client

_G.package.loaded["kong.resty.dns.client"] = nil -- make sure module is reloaded
Expand Down
2 changes: 1 addition & 1 deletion spec/01-unit/09-balancer/04-round_robin_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ describe("[round robin balancer]", function()

local snapshot

setup(function()
lazy_setup(function()
_G.busted_new_dns_client = enable_new_dns_client

_G.package.loaded["kong.resty.dns.client"] = nil -- make sure module is reloaded
Expand Down
2 changes: 1 addition & 1 deletion spec/01-unit/09-balancer/06-latency_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe("[latency]" .. (enable_new_dns_client and "[new dns]" or ""), function(
local snapshot
local old_var = ngx.var

setup(function()
lazy_setup(function()
_G.busted_new_dns_client = enable_new_dns_client

_G.package.loaded["kong.resty.dns.client"] = nil -- make sure module is reloaded
Expand Down
4 changes: 2 additions & 2 deletions spec/01-unit/19-hybrid/03-compat_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ describe("kong.clustering.compat", function()
describe("[#" .. strategy .. "]: check compat for entities those have `updated_at` field", function()
local bp, db, entity_names

setup(function()
lazy_setup(function()
-- excludes entities not exportable: clustering_data_planes,
entity_names = {
"services",
Expand Down Expand Up @@ -394,7 +394,7 @@ describe("kong.clustering.compat", function()
end
end)

teardown(function()
lazy_teardown(function()
for _, entity_name in ipairs(entity_names) do
db[entity_name]:truncate()
end
Expand Down
8 changes: 4 additions & 4 deletions spec/01-unit/29-admin_gui/02-admin_gui_template_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("admin_gui template", function()
},
}

setup(function()
lazy_setup(function()
prefix_handler.prepare_prefixed_interface_dir("/usr/local/kong", "gui", conf)
os.execute("mkdir -p " .. mock_prefix)
assert(pl_path.isdir(mock_prefix))
Expand Down Expand Up @@ -135,7 +135,7 @@ describe("admin_gui template", function()
},
}

setup(function()
lazy_setup(function()
prefix_handler.prepare_prefixed_interface_dir("/usr/local/kong", "gui", conf)
os.execute("mkdir -p " .. mock_prefix)
assert(pl_path.isdir(mock_prefix))
Expand Down Expand Up @@ -177,15 +177,15 @@ describe("admin_gui template", function()
local usr_interface_dir = "gui2"
local usr_interface_path = usr_path .. "/" .. usr_interface_dir

setup(function()
lazy_setup(function()
conf.prefix = mock_prefix

if not pl_path.exists(usr_interface_path) then
os.execute("mkdir -p " .. usr_interface_path)
end
end)

teardown(function()
lazy_teardown(function()
if pl_path.exists(usr_interface_path) then
assert(pl_path.rmdir(usr_interface_path))
end
Expand Down
4 changes: 2 additions & 2 deletions spec/01-unit/30-new-dns-client/04-client_ipc_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end
describe("[dns-client] inter-process communication:",function()
local num_workers = 2

setup(function()
lazy_setup(function()
local bp = helpers.get_db_utils("postgres", {
"routes",
"services",
Expand All @@ -34,7 +34,7 @@ describe("[dns-client] inter-process communication:",function()
}))
end)

teardown(function()
lazy_teardown(function()
helpers.stop_kong()
end)

Expand Down
8 changes: 4 additions & 4 deletions spec/02-integration/03-db/03-plugins_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ for _, strategy in helpers.each_strategy() do
end)

describe("with bad PRIORITY fails; ", function()
setup(function()
lazy_setup(function()
local schema = {}
package.loaded["kong.plugins.NaN_priority.schema"] = schema
package.loaded["kong.plugins.NaN_priority.handler"] = { PRIORITY = 0/0, VERSION = "1.0" }
Expand All @@ -358,7 +358,7 @@ for _, strategy in helpers.each_strategy() do
package.loaded["kong.plugins.string_priority.handler"] = { PRIORITY = "abc", VERSION = "1.0" }
end)

teardown(function()
lazy_teardown(function()
package.loaded["kong.plugins.NaN_priority.schema"] = nil
package.loaded["kong.plugins.NaN_priority.handler"] = nil
package.loaded["kong.plugins.huge_negative.schema"] = nil
Expand Down Expand Up @@ -394,7 +394,7 @@ for _, strategy in helpers.each_strategy() do
end)

describe("with bad VERSION fails; ", function()
setup(function()
lazy_setup(function()
local schema = {}
package.loaded["kong.plugins.no_version.schema"] = schema
package.loaded["kong.plugins.no_version.handler"] = { PRIORITY = 1000, VERSION = nil }
Expand All @@ -404,7 +404,7 @@ for _, strategy in helpers.each_strategy() do
package.loaded["kong.plugins.number.handler"] = { PRIORITY = 1000, VERSION = 123 }
end)

teardown(function()
lazy_teardown(function()
package.loaded["kong.plugins.no_version.schema"] = nil
package.loaded["kong.plugins.no_version.handler"] = nil
package.loaded["kong.plugins.too_many.schema"] = nil
Expand Down
4 changes: 2 additions & 2 deletions spec/02-integration/03-db/09-query-semaphore_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local cjson = require "cjson"
describe("#postgres Postgres query locks", function()
local client

setup(function()
lazy_setup(function()
local bp = helpers.get_db_utils("postgres", {
"plugins",
}, {
Expand All @@ -25,7 +25,7 @@ describe("#postgres Postgres query locks", function()
client = helpers.admin_client()
end)

teardown(function()
lazy_teardown(function()
if client then
client:close()
end
Expand Down
4 changes: 2 additions & 2 deletions spec/02-integration/04-admin_api/13-plugin-endpoints_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ for _, strategy in helpers.each_strategy() do
describe("Admin API endpoints added via plugins #" .. strategy, function()
local client

setup(function()
lazy_setup(function()
local bp = helpers.get_db_utils(strategy, {
"plugins",
}, {
Expand All @@ -25,7 +25,7 @@ describe("Admin API endpoints added via plugins #" .. strategy, function()
client = helpers.admin_client()
end)

teardown(function()
lazy_teardown(function()
if client then
client:close()
end
Expand Down
2 changes: 1 addition & 1 deletion spec/02-integration/04-admin_api/20-timers_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ local client
client = helpers.admin_client()
end)

teardown(function()
lazy_teardown(function()
if client then
client:close()
end
Expand Down
2 changes: 1 addition & 1 deletion spec/02-integration/04-admin_api/23-cors_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("Admin API - CORS -", function()
client = helpers.admin_client()
end)

teardown(function()
lazy_teardown(function()
if client then
client:close()
end
Expand Down
6 changes: 3 additions & 3 deletions spec/02-integration/08-status_api/05-dns_client_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ for _, strategy in helpers.each_strategy() do
client = helpers.http_client("127.0.0.1", tcp_status_port, 20000)
end)

teardown(function()
lazy_teardown(function()
if client then
client:close()
end
Expand Down Expand Up @@ -81,7 +81,7 @@ for _, strategy in helpers.each_strategy() do
client = helpers.http_client("127.0.0.1", tcp_status_port, 20000)
end)

teardown(function()
lazy_teardown(function()
if client then
client:close()
end
Expand Down Expand Up @@ -139,7 +139,7 @@ for _, strategy in helpers.each_strategy() do
client = helpers.http_client("127.0.0.1", tcp_status_port, 20000)
end)

teardown(function()
lazy_teardown(function()
if client then
client:close()
end
Expand Down
8 changes: 4 additions & 4 deletions spec/02-integration/09-hybrid_mode/08-lazy_export_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ for _, strategy in helpers.each_strategy() do

describe("lazy_export with #".. strategy .. " inc_sync=" .. inc_sync, function()
describe("no DP", function ()
setup(function()
lazy_setup(function()
cp(strategy, rpc, inc_sync)
end)
teardown(function ()
lazy_teardown(function ()
helpers.stop_kong()
end)
it("test", function ()
Expand All @@ -80,11 +80,11 @@ describe("lazy_export with #".. strategy .. " inc_sync=" .. inc_sync, function()
end)

describe("only json DP", function()
setup(function()
lazy_setup(function()
cp(strategy, rpc, inc_sync)
json_dp(rpc, inc_sync)
end)
teardown(function ()
lazy_teardown(function ()
helpers.stop_kong("dp1")
helpers.stop_kong()
end)
Expand Down
8 changes: 4 additions & 4 deletions spec/03-plugins/06-statsd/01-log_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,7 @@ for _, strategy in helpers.each_strategy() do
describe("Plugin: statsd (log) [#" .. strategy .. "]", function()
local proxy_client

setup(function()
lazy_setup(function()
local bp = helpers.get_db_utils(strategy)

local consumer = bp.consumers:insert {
Expand Down Expand Up @@ -2157,7 +2157,7 @@ for _, strategy in helpers.each_strategy() do

end)

teardown(function()
lazy_teardown(function()
if proxy_client then
proxy_client:close()
end
Expand Down Expand Up @@ -2206,7 +2206,7 @@ for _, strategy in helpers.each_strategy() do
describe("Plugin: statsd (log) in batches [#" .. strategy .. "]", function()
local proxy_client

setup(function()
lazy_setup(function()
local bp = helpers.get_db_utils(strategy)

local consumer = bp.consumers:insert {
Expand Down Expand Up @@ -2239,7 +2239,7 @@ for _, strategy in helpers.each_strategy() do

end)

teardown(function()
lazy_teardown(function()
if proxy_client then
proxy_client:close()
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end
describe("Plugin: response-transformer", function()
local header_transformer

setup(function()
lazy_setup(function()

_G.ngx = {
headers_sent = false,
Expand Down
Loading

0 comments on commit e41a61f

Please sign in to comment.