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

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


The following commit(s) were added to refs/heads/master by this push:
     new 6dba053  update server-info.t (#3143)
6dba053 is described below

commit 6dba053c089ddaaa74aecb967139e49dfb7e30ec
Author: dabue <[email protected]>
AuthorDate: Mon Dec 28 20:51:56 2020 +0800

    update server-info.t (#3143)
    
    related #3095
---
 t/plugin/server-info.t | 52 +++++++-------------------------------------------
 1 file changed, 7 insertions(+), 45 deletions(-)

diff --git a/t/plugin/server-info.t b/t/plugin/server-info.t
index 7ee7eb0..1f7518b 100644
--- a/t/plugin/server-info.t
+++ b/t/plugin/server-info.t
@@ -61,29 +61,15 @@ location /t {
             return
         end
 
-        local keys = {}
         local value = res.body.node.value
-        for k in pairs(value) do
-            keys[#keys + 1] = k
-        end
-
-        table.sort(keys)
-        for i = 1, #keys do
-            ngx.say(keys[i], ": ", value[keys[i]])
-        end
+        local json = require("toolkit.json")
+        ngx.say(json.encode(value))
     }
 }
 --- request
 GET /t
 --- response_body eval
-qr{^boot_time: \d+
-etcd_version: [\d\.]+
-hostname: [a-zA-Z\-0-9\.]+
-id: [a-zA-Z\-0-9]+
-last_report_time: \d+
-up_time: \d+
-version: [\d\.]+
-$}
+qr/^{"boot_time":\d+,"etcd_version":"[\d\.]+","hostname":"[a-zA-Z\-0-9\.]+","id":[a-zA-Z\-0-9]+,"last_report_time":\d+,"up_time":\d+,"version":"[\d\.]+"}$/
 --- no_error_log
 [error]
 --- error_log
@@ -112,12 +98,7 @@ location /t {
             return
         end
 
-        local keys = {}
         local value = res.body.node.value
-        for k in pairs(value) do
-            keys[#keys + 1] = k
-        end
-
         if value.up_time >= 2 then
             ngx.say("integral")
         else
@@ -145,39 +126,20 @@ plugins:
 --- config
 location /t {
     content_by_lua_block {
-        local json_decode = require("apisix.core").json.decode
+        local json = require("toolkit.json")
         local t = require("lib.test_admin").test
         local code, _, body = t("/v1/server_info")
         if code >= 300 then
             ngx.status = code
         end
 
-        local keys = {}
-        local value, err = json_decode(body)
-        if not value then
-            ngx.say(err)
-            return
-        end
-        for k in pairs(value) do
-            keys[#keys + 1] = k
-        end
-
-        table.sort(keys)
-        for i = 1, #keys do
-            ngx.say(keys[i], ": ", value[keys[i]])
-        end
+        body = json.decode(body)
+        ngx.say(json.encode(body))
     }
 }
 --- request
 GET /t
 --- response_body eval
-qr{^boot_time: \d+
-etcd_version: [\d\.]+
-hostname: [a-zA-Z\-0-9\.]+
-id: [a-zA-Z\-0-9]+
-last_report_time: \d+
-up_time: \d+
-version: [\d\.]+
-$}
+qr/^{"boot_time":\d+,"etcd_version":"[\d\.]+","hostname":"[a-zA-Z\-0-9\.]+","id":[a-zA-Z\-0-9]+,"last_report_time":\d+,"up_time":\d+,"version":"[\d\.]+"}$/
 --- no_error_log
 [error]

Reply via email to