Skip to content

Commit

Permalink
use bp.*:insert to insert routes
Browse files Browse the repository at this point in the history
  • Loading branch information
chobits committed Nov 26, 2024
1 parent 24521c4 commit 7026271
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 43 deletions.
74 changes: 34 additions & 40 deletions spec/02-integration/11-dbless/04-pagination_spec.lua
Original file line number Diff line number Diff line change
@@ -1,70 +1,64 @@
local fmt = string.format
local helpers = require "spec.helpers"


local SERVICE_YML = [[
- name: my-service-%d
url: https://example%d.dev
plugins:
- name: dbless-pagination-test
routes:
- name: my-route-%d
paths:
- /%d
]]
local strategy = "off"


describe("dbless pagination #off", function()
local client
describe("dbless pagination #" .. strategy, function()
local client, admin_client

lazy_setup(function()
local bp = helpers.get_db_utils(strategy, {
"routes",
"services",
"plugins",
})

bp.plugins:insert {
name = "dbless-pagination-test",
config = { },
}

for i = 1, 1001 do
local service = assert(bp.services:insert {
url = "https://example1.dev",
name = "my-serivce-" .. i,
})

assert(bp.routes:insert({
paths = { "/" .. i },
service = service,
name = "my-route-" .. i,
}))
end

assert(helpers.start_kong({
nginx_conf = "spec/fixtures/custom_nginx.template",
database = "off",
database = strategy,
plugins = "bundled,dbless-pagination-test",
}))
print("helpers.start_kong")

client = assert(helpers.proxy_client())
admin_client = assert(helpers.admin_client())
end)

lazy_teardown(function()
admin_client:close()
client:close()
helpers.stop_kong()
end)

it("Routes", function()
local buffer = {"_format_version: '3.0'", "services:"}
for i = 1, 1001 do
buffer[#buffer + 1] = fmt(SERVICE_YML, i, i, i, i)
end
local config = table.concat(buffer, "\n")

local admin_client = assert(helpers.admin_client())
local res = admin_client:post("/config",{
body = { config = config },
headers = {
["Content-Type"] = "application/json",
}
})
assert.res_status(201, res)
admin_client:close()

local res = admin_client:get("/routes/my-route-1")
print(res:read_body())
print("-------")

-- check routes number with :page() API
--local res, err = client:get("/1", {})
assert.res_status(200, res)

local res = assert(client:send {
method = "GET",
path = "/1",
})
--print(require("inspect")(res))
local resbody = res:read_body()
print"--------"
print(resbody)
--assert.response(res).has.header("X-rows-number", "test")
assert.res_status(200, res)
assert.same(res.headers["X-Rows-Number"], "512")
assert.same(res.headers["X-Max-Page-Size"], "2048")
end)
end)
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ function LmdbPaginationTestHandler:init_worker()
end

function LmdbPaginationTestHandler:access(conf)
ngx.log(ngx.INFO, "xxxxxxxxxxxxxx")
local rows, err, err_t, offset = kong.db.routes:page()
local rows, _, _, offset = kong.db.routes:page()
ngx.header["X-Rows-Number"] = #rows
ngx.header["X-rows-offset"] = tostring(offset)

ngx.header["X-rows-number"] = #rows
ngx.header["X-Max-Page-Size"] = kong.db.routes.pagination.max_page_size

ngx.exit(200)
end


Expand Down

0 comments on commit 7026271

Please sign in to comment.