diff --git a/spec/busted-ci-helper.lua b/spec/busted-ci-helper.lua index be9e84ea145b..dc2875883b03 100644 --- a/spec/busted-ci-helper.lua +++ b/spec/busted-ci-helper.lua @@ -1,10 +1,37 @@ -- busted-ci-helper.lua +local busted = require("busted") -local busted = require 'busted' -local cjson = require 'cjson' -local socket_unix = require 'socket.unix' +local function cleanup() + local prefix = assert(require("kong.conf_loader")(os.getenv("KONG_SPEC_TEST_CONF_PATH") or "spec/kong_tests.conf")).prefix + os.remove(prefix .. "/worker_events.sock") + os.remove(prefix .. "/stream_worker_events.sock") + local pl_path = require "pl.path" + local pl_dir = require "pl.dir" + if pl_path.exists(prefix) and not pl_path.islink(prefix) then + for root, _, files in pl_dir.walk(prefix, true) do + if pl_path.islink(root) then + os.remove(root) + else + for _, f in ipairs(files) do + f = pl_path.join(root,f) + os.remove(f) + end + pl_path.rmdir(root) + end + end + end + return nil, true --continue +end + +busted.subscribe({ "file", "start" }, cleanup) local busted_event_path = os.getenv("BUSTED_EVENT_PATH") +if not busted_event_path then + return +end + +local cjson = require("cjson") +local socket_unix = require("socket.unix") -- Function to recursively copy a table, skipping keys associated with functions local function copyTable(original, copied, cache, max_depth, current_depth) @@ -31,37 +58,35 @@ local function copyTable(original, copied, cache, max_depth, current_depth) return copied end -if busted_event_path then - local sock = assert(socket_unix()) - assert(sock:connect(busted_event_path)) +local sock = assert(socket_unix()) +assert(sock:connect(busted_event_path)) - local events = {{ 'suite', 'reset' }, - { 'suite', 'start' }, - { 'suite', 'end' }, - { 'file', 'start' }, - { 'file', 'end' }, - { 'test', 'start' }, - { 'test', 'end' }, - { 'pending' }, - { 'failure', 'it' }, - { 'error', 'it' }, - { 'failure' }, - { 'error' }} - for _, event in ipairs(events) do - busted.subscribe(event, function (...) - local args = {} - for i, original in ipairs{...} do - if type(original) == "table" then - args[i] = copyTable(original) - elseif type(original) == "userdata" then - args[i] = tostring(original) - elseif type(original) ~= "function" then - args[i] = original - end +local events = {{ "suite", "reset" }, + { "suite", "start" }, + { "suite", "end" }, + { "file", "start" }, + { "file", "end" }, + { "test", "start" }, + { "test", "end" }, + { "pending" }, + { "failure", "it" }, + { "error", "it" }, + { "failure" }, + { "error" }} +for _, event in ipairs(events) do + busted.subscribe(event, function (...) + local args = {} + for i, original in ipairs{...} do + if type(original) == "table" then + args[i] = copyTable(original) + elseif type(original) == "userdata" then + args[i] = tostring(original) + elseif type(original) ~= "function" then + args[i] = original end + end - sock:send(cjson.encode({ event = event[1] .. (event[2] and ":" .. event[2] or ""), args = args }) .. "\n") - return nil, true --continue - end) - end + sock:send(cjson.encode({ event = event[1] .. (event[2] and ":" .. event[2] or ""), args = args }) .. "\n") + return nil, true --continue + end) end