in t/plugin/ai4.t [25:122]
add_block_preprocessor(sub {
my ($block) = @_;
if (!defined $block->extra_init_by_lua) {
my $extra_init_by_lua = <<_EOC_;
add_eligible_route = function(id, uri)
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/' .. id,
ngx.HTTP_PUT,
[[{
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "]] .. uri .. [["
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
end
add_ineligible_route = function(id, uri)
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/' .. id,
ngx.HTTP_PUT,
[[{
"upstream": {
"nodes": {
"127.0.0.1:1980": 1,
"127.0.0.1:1981": 1
},
"type": "roundrobin"
},
"uri": "]] .. uri .. [["
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
end
update_route_to_ineligible = function(id)
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/' .. id .. '/upstream/nodes',
ngx.HTTP_PATCH,
[[{
"127.0.0.1:1980": 1,
"127.0.0.1:1981": 1
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
end
update_route_to_eligible = function(id)
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/' .. id .. '/upstream/nodes',
ngx.HTTP_PATCH,
[[{
"127.0.0.1:1980": 1
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
end
clear_route = function(id)
local t = require("lib.test_admin").test
local code = t('/apisix/admin/routes/' .. id, ngx.HTTP_DELETE)
return code
end
_EOC_
$block->set_value("extra_init_by_lua", $extra_init_by_lua);
}
if ((!defined $block->error_log) && (!defined $block->no_error_log)) {
$block->set_value("no_error_log", "[error]");
}
if (!defined $block->request) {
$block->set_value("request", "GET /t");
}
});