This is an automated email from the ASF dual-hosted git repository.

membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 6cca341  test: exported ENV{APISIX_HOME}, allow user to define the 
working path by himself. (#1160)
6cca341 is described below

commit 6cca341b7f11f85d543490068caac30b703c3efb
Author: YuanSheng Wang <membp...@gmail.com>
AuthorDate: Wed Feb 26 21:26:01 2020 +0800

    test: exported ENV{APISIX_HOME}, allow user to define the working path by 
himself. (#1160)
    
    * change: enable Lua code coverage.
---
 t/APISIX.pm          | 26 +++++++++++++-------------
 t/lib/test_admin.lua | 28 ++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/t/APISIX.pm b/t/APISIX.pm
index f7887ab..f15b367 100644
--- a/t/APISIX.pm
+++ b/t/APISIX.pm
@@ -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");
@@ -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;
 
@@ -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"
 
@@ -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;
diff --git a/t/lib/test_admin.lua b/t/lib/test_admin.lua
index 38c3a3a..608124f 100644
--- a/t/lib/test_admin.lua
+++ b/t/lib/test_admin.lua
@@ -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

Reply via email to