Skip to content

Commit

Permalink
Merge pull request #326 from 3scale/test-boot-configuration-loader
Browse files Browse the repository at this point in the history
[remote_v2] test and fix lazy configuaration loader
  • Loading branch information
mikz authored Mar 21, 2017
2 parents b13a89d + dede157 commit 6b0325f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
13 changes: 8 additions & 5 deletions apicast/src/configuration_loader/remote_v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,16 @@ function _M:index(host)
end

function _M:call(environment)
if self == _M and environment then
if self == _M or not self then
local host = environment
local index = _M.new():index(host)
local m = _M.new()
local ret, err = m:index(host)

if index then return index end
elseif self == _M or not self then
return _M.new():call()
if not ret then
return m:call()
else
return ret, err
end
end

local http_client = self.http_client
Expand Down
29 changes: 28 additions & 1 deletion t/015-configuration-loading-boot-remote.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ run_tests();

__DATA__
=== TEST 1: load configuration from remote endpoint
=== TEST 1: boot load configuration from remote endpoint
should load that configuration and not fail
--- main_config
env THREESCALE_PORTAL_ENDPOINT=http://127.0.0.1:$TEST_NGINX_SERVER_PORT;
Expand All @@ -45,3 +45,30 @@ GET /t
--- response_body
{"services":{}}
--- exit_code: 200
=== TEST 2: lazy load configuration from remote endpoint
should load that configuration and not fail
--- main_config
env THREESCALE_PORTAL_ENDPOINT=http://127.0.0.1:$TEST_NGINX_SERVER_PORT;
env APICAST_CONFIGURATION_LOADER=lazy;
env THREESCALE_DEPLOYMENT_ENV=foobar;
env PATH;
--- http_config
lua_package_path "$TEST_NGINX_LUA_PATH";
--- config
location = /t {
content_by_lua_block {
local loader = require('configuration_loader.remote_v2')
ngx.say(assert(loader:call('localhost')))
}
}
location = /admin/api/services.json {
echo '{}';
}
--- request
GET /t
--- response_body
{"services":{}}
--- exit_code: 200

0 comments on commit 6b0325f

Please sign in to comment.