Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolver.t conversion to APIcast::Blackbox #1432

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gateway/http.d/init.conf
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ init_by_lua_block {
end
end

require('resty.resolver').init()
-- require('resty.resolver').init()

require('apicast.loader')

Expand Down
2 changes: 1 addition & 1 deletion gateway/src/apicast/cli/environment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ local function parse_nameservers()
local resolver = require('resty.resolver')
local nameservers = {}

for _,nameserver in ipairs(resolver.init_nameservers()) do
for _,nameserver in ipairs(resolver.init_nameservers(resty_env.value('TEST_NGINX_RESOLV_CONF'))) do
-- resty.resolver returns nameservers as tables with __tostring metamethod
-- unfortunately those objects can't be joined with table.concat
-- and have to be converted to strings first
Expand Down
78 changes: 44 additions & 34 deletions t/resolver.t
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use lib 't';
use Test::APIcast 'no_plan';
use Test::APIcast::Blackbox 'no_plan';

$ENV{TEST_NGINX_HTTP_CONFIG} = "$Test::APIcast::path/http.d/*.conf";
$ENV{TEST_NGINX_RESOLVER} = '127.0.1.1:5353';

$ENV{TEST_NGINX_RESOLV_CONF} = "$Test::Nginx::Util::HtmlDir/resolv.conf";
repeat_each(1);

master_on();
log_level('warn');
Expand All @@ -14,22 +13,26 @@ __DATA__

=== TEST 1: uses all resolvers
both RESOLVER env variable and resolvers in resolv.conf should be used.
checking if commented 'nameserver' and 'search' keywords impact on the
checking if commented 'nameserver' and 'search' keywords impact on the
resolv.conf file parsing.
--- main_config
env RESOLVER=$TEST_NGINX_RESOLVER;
--- http_config
lua_package_path "$TEST_NGINX_LUA_PATH";
init_worker_by_lua_block {
require('resty.resolver').init('$TEST_NGINX_RESOLV_CONF')
}
--- config
location = /t {
--- env eval
('RESOLVER' => '127.0.1.1:5353',
'TEST_NGINX_RESOLV_CONF' => "$Test::Nginx::Util::HtmlDir/resolv.conf")
--- nameservers
nameservers = false,
--- configuration
{}
--- upstream
location /t {
content_by_lua_block {
local nameservers = require('resty.resolver').nameservers()
ngx.say('nameservers: ', #nameservers, ' ', nameservers[1], ' ', nameservers[2], ' ', nameservers[3])
}
}
--- upstream_name
t
--- more_headers
Host: t
--- request
GET /t
--- response_body
Expand All @@ -48,16 +51,16 @@ search localdomain.example.com local #search nameserver
nameserver 1.2.3.4 #search nameserver
nameserver 4.5.6.7 #nameserver search


=== TEST 2: uses upstream peers
When upstream is defined with the same name use its peers.
--- http_config
lua_package_path "$TEST_NGINX_LUA_PATH";
--- configuration
{}
--- sites_d
upstream some_name {
server 1.2.3.4:5678;
server 2.3.4.5:6789;
}
--- config
--- upstream
location = /t {
content_by_lua_block {
local resolver = require('resty.resolver'):instance()
Expand All @@ -69,6 +72,10 @@ upstream some_name {
end
}
}
--- upstream_name
t
--- more_headers
Host: t
--- request
GET /t
--- response_body
Expand All @@ -78,23 +85,24 @@ servers: 2
--- no_error_log
[error]


=== TEST 3: can have ipv6 RESOLVER
RESOLVER env variable can be IPv6 address
--- main_config
env RESOLVER=[dead::beef]:5353;
--- http_config
lua_package_path "$TEST_NGINX_LUA_PATH";
init_worker_by_lua_block {
require('resty.resolver').init('$TEST_NGINX_RESOLV_CONF')
}
--- config
--- env eval
('RESOLVER' => '[dead::beef]:5353',
'TEST_NGINX_RESOLV_CONF' => "$Test::Nginx::Util::HtmlDir/resolv.conf")
--- configuration
{}
--- upstream_name
t
--- upstream
location = /t {
content_by_lua_block {
local nameservers = require('resty.resolver').nameservers()
ngx.say('nameservers: ', #nameservers, ' ', tostring(nameservers[1]))
}
}
--- more_headers
Host: t
--- request
GET /t
--- response_body
Expand All @@ -105,20 +113,22 @@ nameservers: 1 [dead::beef]:5353

=== TEST 4: do not duplicate nameserver from RESOLVER
nameservers should not repeat if already configured
--- main_config
env RESOLVER='127.0.1.1:53';
--- http_config
lua_package_path "$TEST_NGINX_LUA_PATH";
init_worker_by_lua_block {
require('resty.resolver').init('$TEST_NGINX_RESOLV_CONF')
}
--- config
--- env eval
('RESOLVER' => '127.0.1.1:53',
'TEST_NGINX_RESOLV_CONF' => "$Test::Nginx::Util::HtmlDir/resolv.conf")
--- configuration
{}
--- upstream
location = /t {
content_by_lua_block {
local nameservers = require('resty.resolver').nameservers()
ngx.say('nameservers: ', #nameservers, ' ', nameservers[1], ' ', nameservers[2])
}
}
--- upstream_name
t
--- more_headers
Host: t
--- request
GET /t
--- response_body
Expand Down