Skip to content

Commit

Permalink
test: exported ENV{APISIX_HOME}, allow user to define the working pat…
Browse files Browse the repository at this point in the history
…h by himself. (#1160)

* change: enable Lua code coverage.
  • Loading branch information
membphis committed Feb 26, 2020
1 parent 4eb5f74 commit 6cca341
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
26 changes: 13 additions & 13 deletions t/APISIX.pm
Expand Up @@ -26,15 +26,15 @@ no_long_string();
no_shuffle();
worker_connections(128);

my $pwd = cwd();
my $apisix_home = $ENV{APISIX_HOME} || cwd();

sub read_file($) {
my $infile = shift;
open my $in, $infile
open my $in, "$apisix_home/$infile"
or die "cannot open $infile for reading: $!";
my $cert = do { local $/; <$in> };
my $data = do { local $/; <$in> };
close $in;
$cert;
$data;
}

my $yaml_config = read_file("conf/config.yaml");
Expand All @@ -50,15 +50,15 @@ add_block_preprocessor(sub {

my $main_config = $block->main_config // <<_EOC_;
worker_rlimit_core 500M;
working_directory $pwd;
working_directory $apisix_home;
_EOC_

$block->set_value("main_config", $main_config);

my $stream_enable = $block->stream_enable;
my $stream_config = $block->stream_config // <<_EOC_;
lua_package_path "$pwd/deps/share/lua/5.1/?.lua;$pwd/lua/?.lua;$pwd/t/?.lua;/usr/share/lua/5.1/?.lua;;";
lua_package_cpath "$pwd/deps/lib/lua/5.1/?.so;$pwd/deps/lib64/lua/5.1/?.so;/usr/lib64/lua/5.1/?.so;;";
lua_package_path "$apisix_home/deps/share/lua/5.1/?.lua;$apisix_home/lua/?.lua;$apisix_home/t/?.lua;./?.lua;;";
lua_package_cpath "$apisix_home/deps/lib/lua/5.1/?.so;$apisix_home/deps/lib64/lua/5.1/?.so;./?.so;;";
lua_socket_log_errors off;
Expand All @@ -70,10 +70,10 @@ _EOC_
}
init_by_lua_block {
-- if os.getenv("APISIX_ENABLE_LUACOV") == "1" then
-- require("luacov.runner")("t/apisix.luacov")
-- jit.off()
-- end
if os.getenv("APISIX_ENABLE_LUACOV") == "1" then
require("luacov.runner")("t/apisix.luacov")
jit.off()
end
require "resty.core"
Expand Down Expand Up @@ -133,8 +133,8 @@ _EOC_

my $http_config = $block->http_config // '';
$http_config .= <<_EOC_;
lua_package_path "$pwd/deps/share/lua/5.1/?.lua;$pwd/lua/?.lua;$pwd/t/?.lua;/usr/share/lua/5.1/?.lua;;";
lua_package_cpath "$pwd/deps/lib/lua/5.1/?.so;$pwd/deps/lib64/lua/5.1/?.so;/usr/lib64/lua/5.1/?.so;;";
lua_package_path "$apisix_home/deps/share/lua/5.1/?.lua;$apisix_home/lua/?.lua;$apisix_home/t/?.lua;./?.lua;;";
lua_package_cpath "$apisix_home/deps/lib/lua/5.1/?.so;$apisix_home/deps/lib64/lua/5.1/?.so;./?.so;;";
lua_shared_dict plugin-limit-req 10m;
lua_shared_dict plugin-limit-count 10m;
Expand Down
28 changes: 28 additions & 0 deletions t/lib/test_admin.lua
Expand Up @@ -158,4 +158,32 @@ function _M.read_file(path)
end


function _M.req_self_with_http(uri, method, body, headers)
if type(body) == "table" then
body = json.encode(body)
end

if type(method) == "number" then
method = methods[method]
end
headers = headers or {}

local httpc = http.new()
-- https://github.com/ledgetech/lua-resty-http
uri = ngx.var.scheme .. "://" .. ngx.var.server_addr
.. ":" .. ngx.var.server_port .. uri
headers["Content-Type"] = "application/x-www-form-urlencoded"
local res, err = httpc:request_uri(uri,
{
method = method,
body = body,
keepalive = false,
headers = headers,
}
)

return res, err
end


return _M

0 comments on commit 6cca341

Please sign in to comment.