You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by we...@apache.org on 2020/03/07 11:51:47 UTC

[incubator-apisix] branch master updated: bugfix: global ruls admin api should list resource without id (#1199)

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

wenming 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 c225038  bugfix: global ruls admin api should list resource without id (#1199)
c225038 is described below

commit c2250383f2b73a84b62d13e53a4a2d95526ce89f
Author: Vinci Xu <27...@qq.com>
AuthorDate: Sat Mar 7 19:51:40 2020 +0800

    bugfix: global ruls admin api should list resource without id (#1199)
---
 lua/apisix/admin/global_rules.lua |  5 +++-
 t/admin/global-rules.t            | 52 +++++++++++++++++++++++++++++++++++----
 2 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/lua/apisix/admin/global_rules.lua b/lua/apisix/admin/global_rules.lua
index f46ca0e..c74d773 100644
--- a/lua/apisix/admin/global_rules.lua
+++ b/lua/apisix/admin/global_rules.lua
@@ -77,7 +77,10 @@ end
 
 
 function _M.get(id)
-    local key = "/global_rules/" .. id
+    local key = "/global_rules"
+    if id then
+        key = key .. "/" .. id
+    end
     local res, err = core.etcd.get(key)
     if not res then
         core.log.error("failed to get global rule[", key, "]: ", err)
diff --git a/t/admin/global-rules.t b/t/admin/global-rules.t
index c9dd74f..a91af78 100644
--- a/t/admin/global-rules.t
+++ b/t/admin/global-rules.t
@@ -111,9 +111,51 @@ passed
 --- no_error_log
 [error]
 
+=== TEST 3: list global rules
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/global_rules',
+                ngx.HTTP_GET,
+                nil,
+                [[{
+                    "node": {
+                        "dir": true,
+                        "nodes": [
+                        {
+                            "key": "/apisix/global_rules/1",
+                            "value": {
+                            "plugins": {
+                                "limit-count": {
+                                "time_window": 60,
+                                "policy": "local",
+                                "count": 2,
+                                "key": "remote_addr",
+                                "rejected_code": 503
+                                }
+                            }
+                            }
+                        }
+                        ],
+                        "key": "/apisix/global_rules"
+                    },
+                    "action": "get"
+                }]]
+                )
 
+            ngx.status = code
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
 
-=== TEST 3: PATCH global rules
+=== TEST 4: PATCH global rules
 --- config
     location /t {
         content_by_lua_block {
@@ -159,7 +201,7 @@ passed
 
 
 
-=== TEST 4: delete global rules
+=== TEST 5: delete global rules
 --- config
     location /t {
         content_by_lua_block {
@@ -183,7 +225,7 @@ GET /t
 
 
 
-=== TEST 5: delete global rules(not_found)
+=== TEST 6: delete global rules(not_found)
 --- config
     location /t {
         content_by_lua_block {
@@ -207,7 +249,7 @@ GET /t
 
 
 
-=== TEST 6: set global rules(invalid host option)
+=== TEST 7: set global rules(invalid host option)
 --- config
     location /t {
         content_by_lua_block {
@@ -241,7 +283,7 @@ GET /t
 
 
 
-=== TEST 7: set global rules(missing plugins)
+=== TEST 8: set global rules(missing plugins)
 --- config
     location /t {
         content_by_lua_block {