From 541487a6814e186b96a9526fbe1591e69ae56e6b Mon Sep 17 00:00:00 2001 From: ms2008 Date: Wed, 15 Nov 2023 21:49:54 +0800 Subject: [PATCH] tests(*): fix failed tests --- .../04-admin_api/25-max_safe_integer_spec.lua | 110 ++++++++++++++++++ .../05-proxy/02-router_spec.lua | 16 --- 2 files changed, 110 insertions(+), 16 deletions(-) create mode 100644 spec/02-integration/04-admin_api/25-max_safe_integer_spec.lua diff --git a/spec/02-integration/04-admin_api/25-max_safe_integer_spec.lua b/spec/02-integration/04-admin_api/25-max_safe_integer_spec.lua new file mode 100644 index 000000000000..a54ff9452258 --- /dev/null +++ b/spec/02-integration/04-admin_api/25-max_safe_integer_spec.lua @@ -0,0 +1,110 @@ +local helpers = require "spec.helpers" + +local LMDB_MAP_SIZE = "10m" + +for _, strategy in helpers.each_strategy() do + if strategy ~= "off" then + describe("Admin API #" .. strategy, function() + local bp + local client, route + + lazy_setup(function() + bp = helpers.get_db_utils(strategy, { + "routes", + "services", + }) + + route = bp.routes:insert({ + paths = { "/route_with_max_safe_integer_priority"}, + regex_priority = 9007199254740992, + }) + + assert(helpers.start_kong({ + database = strategy, + })) + end) + + lazy_teardown(function() + helpers.stop_kong(nil, true) + end) + + before_each(function() + client = assert(helpers.admin_client()) + end) + + after_each(function() + if client then + client:close() + end + end) + + it("the maximum safe integer can be accurately represented as a decimal number", function() + local res = assert(client:send { + method = "GET", + path = "/routes/" .. route.id + }) + assert.res_status(200, res) + assert.match_re(res:read_body(), "9007199254740992") + end) + end) + end + + if strategy == "off" then + describe("Admin API #off", function() + local client + + lazy_setup(function() + assert(helpers.start_kong({ + database = "off", + lmdb_map_size = LMDB_MAP_SIZE, + stream_listen = "127.0.0.1:9011", + nginx_conf = "spec/fixtures/custom_nginx.template", + })) + end) + + lazy_teardown(function() + helpers.stop_kong(nil, true) + end) + + before_each(function() + client = assert(helpers.admin_client()) + end) + + after_each(function() + if client then + client:close() + end + end) + + it("the maximum safe integer can be accurately represented as a decimal number", function() + local res = assert(client:send { + method = "POST", + path = "/config", + body = { + config = [[ + _format_version: "1.1" + services: + - name: my-service + id: 0855b320-0dd2-547d-891d-601e9b38647f + url: https://localhost + routes: + - name: my-route + id: 481a9539-f49c-51b6-b2e2-fe99ee68866c + paths: + - / + regex_priority: 9007199254740992 + ]], + }, + headers = { + ["Content-Type"] = "application/json" + } + }) + + assert.response(res).has.status(201) + local res = client:get("/routes/481a9539-f49c-51b6-b2e2-fe99ee68866c") + assert.res_status(200, res) + assert.match_re(res:read_body(), "9007199254740992") + end) + end) + end +end diff --git a/spec/02-integration/05-proxy/02-router_spec.lua b/spec/02-integration/05-proxy/02-router_spec.lua index bcd4a008ce87..26ba41a46176 100644 --- a/spec/02-integration/05-proxy/02-router_spec.lua +++ b/spec/02-integration/05-proxy/02-router_spec.lua @@ -2486,7 +2486,6 @@ do for _, strategy in helpers.each_strategy() do describe("Router [#" .. strategy .. ", flavor = " .. flavor .. "]", function() local proxy_client - local route_with_max_safe_integer_priority reload_router(flavor) @@ -2521,13 +2520,6 @@ do service = service, } - route_with_max_safe_integer_priority = bp.routes:insert { - protocols = { "http" }, - expression = [[http.path == "/max"]], - priority = 9007199254740992, - service = service, - } - assert(helpers.start_kong({ router_flavor = flavor, database = strategy, @@ -2604,14 +2596,6 @@ do assert.res_status(404, res) end) - it("the maximum safe integer can be accurately represented as a decimal number", function() - local admin_client = helpers.admin_client() - - local res = admin_client:get("/routes/" .. route_with_max_safe_integer_priority.id) - assert.res_status(200, res) - assert.match_re(res:read_body(), "9007199254740992") - end) - end) end -- strategy