From 2b8d44487a3f3919a9369549c62f42f75cc9313c Mon Sep 17 00:00:00 2001 From: "Qirui(Keery) Nie" Date: Tue, 13 Dec 2022 15:38:30 +0800 Subject: [PATCH] test(integration): re-enable some tests by renaming their filename (#9906) Co-authored-by: Michael Martin --- .github/workflows/build_and_test.yml | 4 + scripts/check_spec_files_spelling.sh | 26 ++ ...egotiation.lua => 04-negotiation_spec.lua} | 0 ...gins-conf.lua => 12-plugins-conf_spec.lua} | 4 +- ...oints.lua => 13-plugin-endpoints_spec.lua} | 0 .../04-admin_api/18-worker-events.lua | 242 ------------------ ...azy_export.lua => 08-lazy_export_spec.lua} | 0 ...nce.lua => 03-config_persistence_spec.lua} | 0 ...cs.lua => 06-hybrid-mode_metrics_spec.lua} | 0 spec/on_demand_specs | 4 + 10 files changed, 36 insertions(+), 244 deletions(-) create mode 100755 scripts/check_spec_files_spelling.sh rename spec/01-unit/19-hybrid/{04-negotiation.lua => 04-negotiation_spec.lua} (100%) rename spec/02-integration/04-admin_api/{12-plugins-conf.lua => 12-plugins-conf_spec.lua} (96%) rename spec/02-integration/04-admin_api/{13-plugin-endpoints.lua => 13-plugin-endpoints_spec.lua} (100%) delete mode 100644 spec/02-integration/04-admin_api/18-worker-events.lua rename spec/02-integration/09-hybrid_mode/{08-lazy_export.lua => 08-lazy_export_spec.lua} (100%) rename spec/02-integration/11-dbless/{03-config_persistence.lua => 03-config_persistence_spec.lua} (100%) rename spec/03-plugins/26-prometheus/{06-hybrid-mode_metrics.lua => 06-hybrid-mode_metrics_spec.lua} (100%) create mode 100644 spec/on_demand_specs diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 0bfeee2f8f48..a9151c63e2f6 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -140,6 +140,10 @@ jobs: eval `luarocks path` scripts/validate-rockspec + - name: Check spec file misspelling + run: | + scripts/check_spec_files_spelling.sh + - name: Unit tests run: | eval `luarocks path` diff --git a/scripts/check_spec_files_spelling.sh b/scripts/check_spec_files_spelling.sh new file mode 100755 index 000000000000..556589c7c93e --- /dev/null +++ b/scripts/check_spec_files_spelling.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -e + +function red() { + echo -e "\033[1;31m$*\033[0m" +} + +readarray -t FOUND < \ +<( + git ls-files 'spec/[0-9]**.lua' \ + | grep -vE \ + -e '_spec.lua$' \ + -f spec/on_demand_specs +) + +if (( ${#FOUND[@]} > 0 )); then + echo + red "----------------------------------------------------------------" + echo "Found some files in spec directory that do not have the _spec suffix, please check if you're misspelling them. If there is an exception, please add the coressponding files(or their path regexes) into the whitelist spec/on_demand_specs." + echo + echo "Possible misspelling file list:" + echo + printf "%s\n" "${FOUND[@]}" + red "----------------------------------------------------------------" + exit 1 +fi diff --git a/spec/01-unit/19-hybrid/04-negotiation.lua b/spec/01-unit/19-hybrid/04-negotiation_spec.lua similarity index 100% rename from spec/01-unit/19-hybrid/04-negotiation.lua rename to spec/01-unit/19-hybrid/04-negotiation_spec.lua diff --git a/spec/02-integration/04-admin_api/12-plugins-conf.lua b/spec/02-integration/04-admin_api/12-plugins-conf_spec.lua similarity index 96% rename from spec/02-integration/04-admin_api/12-plugins-conf.lua rename to spec/02-integration/04-admin_api/12-plugins-conf_spec.lua index 12f4e5c290c5..77c3797bd388 100644 --- a/spec/02-integration/04-admin_api/12-plugins-conf.lua +++ b/spec/02-integration/04-admin_api/12-plugins-conf_spec.lua @@ -105,8 +105,8 @@ describe("Plugins conf property" , function() local body = assert.res_status(200 , res) local json = assert(cjson.decode(body)) assert.equal(2, tablex.size(json.plugins.available_on_server)) - assert.True(json.plugins.available_on_server["key-auth"]) - assert.True(json.plugins.available_on_server["basic-auth"]) + assert.truthy(json.plugins.available_on_server["key-auth"]) + assert.truthy(json.plugins.available_on_server["basic-auth"]) end) end) diff --git a/spec/02-integration/04-admin_api/13-plugin-endpoints.lua b/spec/02-integration/04-admin_api/13-plugin-endpoints_spec.lua similarity index 100% rename from spec/02-integration/04-admin_api/13-plugin-endpoints.lua rename to spec/02-integration/04-admin_api/13-plugin-endpoints_spec.lua diff --git a/spec/02-integration/04-admin_api/18-worker-events.lua b/spec/02-integration/04-admin_api/18-worker-events.lua deleted file mode 100644 index ce1a2d5e52f5..000000000000 --- a/spec/02-integration/04-admin_api/18-worker-events.lua +++ /dev/null @@ -1,242 +0,0 @@ -local helpers = require "spec.helpers" -local cjson = require "cjson" - - -local pairs = pairs -local type = type -local null = ngx.null - - -local function remove_nulls(tbl) - for k,v in pairs(tbl) do - if v == null then - tbl[k] = nil - elseif type(v) == "table" then - tbl[k] = remove_nulls(v) - end - end - return tbl -end - - -local headers = { - ["Content-Type"] = "application/json" -} - - -for _, strategy in helpers.each_strategy() do - describe("Admin API #" .. strategy, function() - local admin_client - local proxy_client - - lazy_setup(function() - local bp = helpers.get_db_utils(strategy, { - "routes", - "services", - "plugins", - }, { - "worker-events", - }) - - bp.plugins:insert({ - name = "worker-events", - }) - - bp.routes:insert({ - paths = { "/" } - }) - - assert(helpers.start_kong { - database = strategy, - db_update_frequency = 0.1, - nginx_conf = "spec/fixtures/custom_nginx.template", - plugins = "worker-events", - }) - end) - - lazy_teardown(function() - helpers.stop_kong(nil, true) - end) - - before_each(function() - admin_client = helpers.admin_client() - proxy_client = helpers.proxy_client() - end) - - after_each(function() - if admin_client then - admin_client:close() - end - - if proxy_client then - proxy_client:close() - end - end) - - describe("worker events", function() - it("triggers create event on creation", function() - local res = admin_client:post("/routes", { - headers = headers, - body = { - hosts = { - "example.test", - }, - }, - }) - - local body = assert.res_status(201, res) - local entity = remove_nulls(cjson.decode(body)) - - res = proxy_client:get("/") - body = assert.res_status(200, res) - local json = cjson.decode(body) - - assert.same({ - operation = "create", - entity = entity, - }, json) - end) - - it("triggers update event with old entity on update", function() - local res = admin_client:put("/routes/test-update", { - headers = headers, - body = { - hosts = { - "example.test", - }, - }, - }) - - -- TODO: it should really be 201, but Kong's PUT has always been 200, - -- we can change it later (as we now know the difference). - local body = assert.res_status(200, res) - local entity = remove_nulls(cjson.decode(body)) - - res = proxy_client:get("/") - body = assert.res_status(200, res) - local json = cjson.decode(body) - - assert.same({ - operation = "create", - entity = entity, - }, json) - - local old_entity = entity - - res = admin_client:patch("/routes/test-update", { - headers = headers, - body = { - hosts = { - "example2.test", - }, - }, - }) - - body = assert.res_status(200, res) - entity = remove_nulls(cjson.decode(body)) - - res = proxy_client:get("/") - body = assert.res_status(200, res) - - local json = cjson.decode(body) - - assert.same({ - operation = "update", - entity = entity, - old_entity = old_entity, - }, json) - end) - - it("triggers update event with old entity on upsert", function() - local res = admin_client:put("/routes/test-upsert", { - headers = headers, - body = { - hosts = { - "example.test", - }, - }, - }) - - -- TODO: it should really be 201, but Kong's PUT has always been 200, - -- we can change it later (as we now know the difference). - local body = assert.res_status(200, res) - local entity = remove_nulls(cjson.decode(body)) - - res = proxy_client:get("/") - body = assert.res_status(200, res) - local json = cjson.decode(body) - - assert.same({ - operation = "create", - entity = entity, - }, json) - - local old_entity = entity - - res = admin_client:put("/routes/test-upsert", { - headers = headers, - body = { - hosts = { - "example2.test", - }, - }, - }) - - body = assert.res_status(200, res) - entity = remove_nulls(cjson.decode(body)) - - res = proxy_client:get("/") - body = assert.res_status(200, res) - - local json = cjson.decode(body) - - assert.same({ - operation = "update", - entity = entity, - old_entity = old_entity, - }, json) - end) - - it("triggers delete event on delete", function() - local res = admin_client:put("/routes/test-delete", { - headers = headers, - body = { - hosts = { - "example.test", - }, - }, - }) - - -- TODO: it should really be 201, but Kong's PUT has always been 200, - -- we can change it later (as we now know the difference). - local body = assert.res_status(200, res) - local entity = remove_nulls(cjson.decode(body)) - - res = proxy_client:get("/") - body = assert.res_status(200, res) - local json = cjson.decode(body) - - assert.same({ - operation = "create", - entity = entity, - }, json) - - res = admin_client:delete("/routes/test-delete", { - headers = headers, - }) - - assert.res_status(204, res) - - res = proxy_client:get("/") - body = assert.res_status(200, res) - - local json = cjson.decode(body) - - assert.same({ - operation = "delete", - entity = entity, - }, json) - end) - end) - end) -end diff --git a/spec/02-integration/09-hybrid_mode/08-lazy_export.lua b/spec/02-integration/09-hybrid_mode/08-lazy_export_spec.lua similarity index 100% rename from spec/02-integration/09-hybrid_mode/08-lazy_export.lua rename to spec/02-integration/09-hybrid_mode/08-lazy_export_spec.lua diff --git a/spec/02-integration/11-dbless/03-config_persistence.lua b/spec/02-integration/11-dbless/03-config_persistence_spec.lua similarity index 100% rename from spec/02-integration/11-dbless/03-config_persistence.lua rename to spec/02-integration/11-dbless/03-config_persistence_spec.lua diff --git a/spec/03-plugins/26-prometheus/06-hybrid-mode_metrics.lua b/spec/03-plugins/26-prometheus/06-hybrid-mode_metrics_spec.lua similarity index 100% rename from spec/03-plugins/26-prometheus/06-hybrid-mode_metrics.lua rename to spec/03-plugins/26-prometheus/06-hybrid-mode_metrics_spec.lua diff --git a/spec/on_demand_specs b/spec/on_demand_specs new file mode 100644 index 000000000000..dc02f0051f66 --- /dev/null +++ b/spec/on_demand_specs @@ -0,0 +1,4 @@ +# Whitelist regexes representing file paths that will not be tested during running busted CI +spec/02-integration/05-proxy/10-balancer/05-stress.lua +spec/03-plugins/16-jwt/fixtures.lua +spec/04-perf/.*