aproxy/test.lua
2022-12-06 15:53:20 -03:00

77 lines
1.4 KiB
Lua

lu = require('luaunit')
local rex = require('rex_pcre2')
function createNgx()
local ngx = {
status = nil
}
local function mockedThing(self, property)
return function(value)
self['_'..property] = value
end
end
ngx.say = mockedThing(ngx, "say")
ngx.exit = mockedThing(ngx, "exit")
ngx.log = function (_, msg)
print(msg)
end
-- only hold data here
ngx.var = {}
-- request params api
ngx.req = {}
ngx.req.get_uri_args = function ()
return ngx._uri_args
end
ngx.req.set_uri_args = function (val)
ngx._uri_args = val
end
-- regex api
ngx.re = {}
ngx.re.match = rex.match
ngx.re.search = rex.find
return ngx
end
function resetNgx()
ngx = createNgx()
end
teardownNgx = resetNgx
function setupFakeRequest(path, options)
ngx.var.uri = path
if options.params then
ngx.req.set_uri_args(options.params)
end
end
local ctx = require('ctx')
function setupTest(module_require_path, config)
resetNgx()
local module = require(module_require_path)
state = module.init(config)
ctx.compiled_chain = {
{module, config, state}
}
return module
end
function onRequest()
ctx:setWantedScripts()
local ctx = require('ctx')
do
ctx:onRequest()
end
end
require('tests.webfinger_allowlist')
os.exit(lu.LuaUnit.run())