in t/plugin/inspect.t [25:99]
add_block_preprocessor(sub {
my ($block) = @_;
if (!defined $block->request) {
$block->set_value("request", "GET /t");
}
my $user_yaml_config = <<_EOC_;
plugin_attr:
inspect:
delay: 1
hooks_file: "/tmp/apisix_inspect_hooks.lua"
_EOC_
$block->set_value("yaml_config", $user_yaml_config);
my $extra_init_worker_by_lua = $block->extra_init_worker_by_lua // "";
$extra_init_worker_by_lua .= <<_EOC_;
local function gen_funcs_invoke(...)
local code = ""
for _, func in ipairs({...}) do
code = code .. "test." .. func .. "();"
end
return code
end
function set_test_route(...)
func = func or 'run1'
local t = require("lib.test_admin").test
local code = [[{
"methods": ["GET"],
"uri": "/inspect",
"plugins": {
"serverless-pre-function": {
"phase": "rewrite",
"functions" : ["return function() local test = require(\\"lib.test_inspect\\");]]
.. gen_funcs_invoke(...)
.. [[ngx.say(\\"ok\\"); end"]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
}
}]]
return t('/apisix/admin/routes/inspect', ngx.HTTP_PUT, code)
end
function do_request()
local http = require "resty.http"
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/inspect"
local httpc = http.new()
local res = httpc:request_uri(uri, {method = "GET"})
assert(res.body == "ok\\n")
end
function write_hooks(code, file)
local file = io.open(file or "/tmp/apisix_inspect_hooks.lua", "w")
file:write(code)
file:close()
end
_EOC_
$block->set_value("extra_init_worker_by_lua", $extra_init_worker_by_lua);
# note that it's different from APISIX.pm,
# here we enable no_error_log ignoreless of error_log.
if (!$block->no_error_log) {
$block->set_value("no_error_log", "[error]");
}
if (!$block->timeout) {
$block->set_value("timeout", "10");
}
});