You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2020/02/18 13:47:06 UTC

[incubator-apisix] branch master updated: bugfix: missing `clear` table before to reuse table. (#1134)

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 2870b79  bugfix: missing `clear` table before to reuse table. (#1134)
2870b79 is described below

commit 2870b798339a12364e5a7a3094f7a6eb8cb9df0d
Author: YuanSheng Wang <me...@gmail.com>
AuthorDate: Tue Feb 18 21:46:56 2020 +0800

    bugfix: missing `clear` table before to reuse table. (#1134)
    
    * test: avoid to use regex for matching output.
---
 lua/apisix/core/response.lua  | 10 ++++++----
 t/admin/routes.t              | 31 +++++++++++++++++++------------
 utils/check-lua-code-style.sh |  1 -
 3 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/lua/apisix/core/response.lua b/lua/apisix/core/response.lua
index 385f9fe..ed0ed00 100644
--- a/lua/apisix/core/response.lua
+++ b/lua/apisix/core/response.lua
@@ -22,10 +22,10 @@ local error = error
 local select = select
 local type = type
 local ngx_exit = ngx.exit
-local insert_tab = table.insert
 local concat_tab = table.concat
 local str_sub = string.sub
 local tonumber = tonumber
+local clear_tab = require("table.clear")
 local pairs = pairs
 
 local _M = {version = 0.1}
@@ -37,10 +37,12 @@ do
     local idx = 1
 
 function resp_exit(code, ...)
+    clear_tab(t)
     idx = 0
 
     if code and type(code) ~= "number" then
-        insert_tab(t, code)
+        idx = idx + 1
+        t[idx] = code
         code = nil
     end
 
@@ -56,12 +58,12 @@ function resp_exit(code, ...)
                 error("failed to encode data: " .. err, -2)
             else
                 idx = idx + 1
-                insert_tab(t, idx, body .. "\n")
+                t[idx] = body .. "\n"
             end
 
         elseif v ~= nil then
             idx = idx + 1
-            insert_tab(t, idx, v)
+            t[idx] = v
         end
     end
 
diff --git a/t/admin/routes.t b/t/admin/routes.t
index 4db05f4..4c54c4f 100644
--- a/t/admin/routes.t
+++ b/t/admin/routes.t
@@ -1369,6 +1369,7 @@ passed
 location /t {
     content_by_lua_block {
         local t = require("lib.test_admin").test
+        local core = require("apisix.core")
         -- set
         local code, body, res = t('/apisix/admin/routes/1?ttl=1',
             ngx.HTTP_PUT,
@@ -1383,7 +1384,7 @@ location /t {
             }]]
             )
 
-        if code >= 300 then ngx.print("code: ", code, " ") end
+        ngx.say("code: ", code)
         ngx.say(body)
 
         -- get
@@ -1400,7 +1401,7 @@ location /t {
             }]]
         )
 
-        if code >= 300 then ngx.print("code: ", code, " ") end
+        ngx.say("code: ", code)
         ngx.say(body)
 
         ngx.sleep(2)
@@ -1408,16 +1409,19 @@ location /t {
         -- get again
         code, body, res = t('/apisix/admin/routes/1', ngx.HTTP_GET)
 
-        if code >= 300 then ngx.print("code: ", code, " ") end
-        ngx.print(body)
+        ngx.say("code: ", code)
+        ngx.say("message: ", core.json.decode(body).message)
     }
 }
 --- request
 GET /t
---- response_body_like eval
-qr$passed
+--- response_body
+code: 200
+passed
+code: 200
 passed
-code: 404 {"cause":"\\/apisix\\/routes\\/1","index":\d+,"errorCode":100,"message":"Key not found"}$
+code: 404
+message: Key not found
 --- no_error_log
 [error]
 --- timeout: 5
@@ -1429,6 +1433,8 @@ code: 404 {"cause":"\\/apisix\\/routes\\/1","index":\d+,"errorCode":100,"message
 location /t {
     content_by_lua_block {
         local t = require("lib.test_admin").test
+        local core = require("apisix.core")
+
         local code, body, res = t('/apisix/admin/routes?ttl=1',
             ngx.HTTP_POST,
             [[{
@@ -1456,15 +1462,16 @@ location /t {
         local id = string.sub(res.node.key, #"/apisix/routes/" + 1)
         code, body = t('/apisix/admin/routes/' .. id, ngx.HTTP_GET)
 
-        if code >= 300 then ngx.print("code: ", code, " ") end
-        ngx.print(body)
+        ngx.say("code: ", code)
+        ngx.say("message: ", core.json.decode(body).message)
     }
 }
 --- request
 GET /t
---- response_body_like eval
-qr$succ: passed
-code: 404 {"cause":"\\/apisix\\/routes\\/\d+","index":\d+,"errorCode":100,"message":"Key not found"}$
+--- response_body
+[push] succ: passed
+code: 404
+message: Key not found
 --- no_error_log
 [error]
 --- timeout: 5
diff --git a/utils/check-lua-code-style.sh b/utils/check-lua-code-style.sh
index f8f0265..7e67a83 100755
--- a/utils/check-lua-code-style.sh
+++ b/utils/check-lua-code-style.sh
@@ -32,7 +32,6 @@ luacheck -q lua
     lua/apisix/plugins/limit-count/*.lua > \
     /tmp/check.log 2>&1 || (cat /tmp/check.log && exit 1)
 
-sed -i 's/.*newproxy.*//g' /tmp/check.log
 count=`grep -E ".lua:[0-9]+:" /tmp/check.log -c || true`
 
 if [ $count -ne 0 ]