#!/usr/bin/env resty local DEFAULT_RESTY_FLAGS="-c 4096" if not os.getenv("KONG_BUSTED_RESPAWNED") then -- initial run, so go update the environment local script = {} for line in io.popen("set"):lines() do local ktvar, val = line:match("^KONG_TEST_([^=]*)=(.*)") if ktvar then -- reinserted KONG_TEST_xxx as KONG_xxx; append table.insert(script, "export KONG_" .. ktvar .. "=" ..val) end local var = line:match("^(KONG_[^=]*)") local var_for_spec = line:match("^(KONG_SPEC_[^=]*)") if var and not var_for_spec then -- remove existing KONG_xxx and KONG_TEST_xxx variables; prepend table.insert(script, 1, "unset " .. var) end end -- add cli recursion detection table.insert(script, "export KONG_BUSTED_RESPAWNED=1") -- rebuild the invoked commandline, while inserting extra resty-flags local resty_flags = DEFAULT_RESTY_FLAGS local cmd = { "exec" } for i = -1, #arg do if arg[i]:sub(1, 12) == "RESTY_FLAGS=" then resty_flags = arg[i]:sub(13, -1) else table.insert(cmd, "'" .. arg[i] .. "'") end end if resty_flags then table.insert(cmd, 3, resty_flags) end table.insert(script, table.concat(cmd, " ")) -- recurse cli command, with proper variables (un)set for clean testing local _, _, rc = os.execute(table.concat(script, "; ")) os.exit(rc) end setmetatable(_G, nil) pcall(require, "luarocks.loader") require("kong.globalpatches")({ cli = true, rbusted = true }) -- Busted command-line runner require 'busted.runner'({ standalone = false })