Repository navigation
Expand file tree
/
Copy pathbusted
More file actions
executable file
·70 lines (56 loc) · 1.69 KB
/
Copy pathbusted
File metadata and controls
executable file
·70 lines (56 loc) · 1.69 KB
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
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env resty
local DEFAULT_RESTY_FLAGS="-c 4096"
do
local lines = getmetatable(io.output()).lines
getmetatable(io.output()).lines = function(self, ...)
local iter = lines(self, ...)
return function()
local ok, ret = pcall(iter)
if ok then
return ret
end
end
end
end
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_[^=]*)")
if var 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
pcall(require, "luarocks.loader")
require("kong.globalpatches")({
cli = true,
rbusted = true
})
-- Busted command-line runner
require 'busted.runner'({ standalone = false })