-
Notifications
You must be signed in to change notification settings - Fork 0
/
resty_busted
executable file
·61 lines (47 loc) · 1.64 KB
/
resty_busted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env resty
-- original https://raw.githubusercontent.com/Kong/kong/master/bin/busted
local DEFAULT_RESTY_FLAGS="-c 4096 --shdict 'test_shm 1m'"
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 })