Skip to content

Commit

Permalink
proxy configs pagination: unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Mar 17, 2023
1 parent 238bb1b commit ae2609f
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions spec/configuration_loader/remote_v2_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ local service_generator = function(n)
return { services = services }
end

local proxy_config_generator = function(n)
local proxy_configs = {}
for i = 1,n do
proxy_configs[i] = { proxy_config = {
version = 42,
environment = 'staging',
content = { id = 2, backend_version = 2 }
}}
end

return { proxy_configs = proxy_configs }
end

describe('Configuration Remote Loader V2', function()

local test_backend
Expand Down Expand Up @@ -822,6 +835,22 @@ UwIDAQAB
assert.same({ nil, 'invalid status' }, { loader:index() })
end)

it('invalid status is handled when any page returns invalid status', function()
local PROXY_CONFIGS_PER_PAGE = 500
local page1 = proxy_config_generator(PROXY_CONFIGS_PER_PAGE)

test_backend.expect{
url = 'http://example.com/admin/api/account/proxy_configs/production.json?'..
ngx.encode_args({ version = 'latest', per_page = 500, page = 1 })}.
respond_with{ status = 200, body = cjson.encode(page1) }

test_backend.expect{ url = 'http://example.com/admin/api/account/proxy_configs/production.json?'..
ngx.encode_args({ page = 2, per_page = 500, version = "latest" })}.
respond_with{ status = 404, body = nil}

assert.same({ nil, 'invalid status' }, { loader:index() })
end)

it('returns configuration for all proxy configs with no host', function()
test_backend.expect{ url = 'http://example.com/admin/api/account/proxy_configs/production.json?'..
ngx.encode_args({ version = "latest", page = 1, per_page = 500 })}.
Expand Down Expand Up @@ -982,6 +1011,40 @@ UwIDAQAB
assert.equals(1, #result_config.oidc)
assert.same('2', result_config.oidc[1].service_id)
end)

it('retuns configurations from multiple pages', function()
-- Will serve: 3 pages
-- page 1 => PROXY_CONFIGS_PER_PAGE
-- page 2 => PROXY_CONFIGS_PER_PAGE
-- page 3 => 51
local PROXY_CONFIGS_PER_PAGE = 500
local page1 = proxy_config_generator(PROXY_CONFIGS_PER_PAGE)
local page2 = proxy_config_generator(PROXY_CONFIGS_PER_PAGE)
local page3 = proxy_config_generator(51)

test_backend.expect{
url = 'http://example.com/admin/api/account/proxy_configs/production.json?'..
ngx.encode_args({ version = 'latest', per_page = 500, page = 1 })}.
respond_with{ status = 200, body = cjson.encode(page1) }

test_backend.expect{
url = 'http://example.com/admin/api/account/proxy_configs/production.json?'..
ngx.encode_args({ version = 'latest', per_page = 500, page = 2 })}.
respond_with{ status = 200, body = cjson.encode(page2) }

test_backend.expect{
url = 'http://example.com/admin/api/account/proxy_configs/production.json?'..
ngx.encode_args({ version = 'latest', per_page = 500, page = 3 })}.
respond_with{ status = 200, body = cjson.encode(page3) }

local config = loader:index()

assert.truthy(config)
assert.equals('string', type(config))

local result_config = cjson.decode(config)
assert.equals(2*PROXY_CONFIGS_PER_PAGE + 51, #result_config.services)
end)
end)

describe(':call', function()
Expand Down

0 comments on commit ae2609f

Please sign in to comment.