forked from 3scale/APIcast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolver.t
129 lines (117 loc) · 3.24 KB
/
resolver.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use lib 't';
use Test::APIcast '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";
master_on();
log_level('warn');
run_tests();
__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
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 {
content_by_lua_block {
local nameservers = require('resty.resolver').nameservers()
ngx.say('nameservers: ', #nameservers, ' ', nameservers[1], ' ', nameservers[2], ' ', nameservers[3])
}
}
--- request
GET /t
--- response_body
nameservers: 3 127.0.1.15353 1.2.3.453 4.5.6.753
--- user_files
>>> resolv.conf
# nameserver updated in comentary
#nameserver updated in comentary
#comentary nameserver 1.2.3.4
#comentary nameserver
# search updated.example.com in comentary
#search updated in comentary
#search nameserver 1.2.3.4
#search nameserver
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";
upstream some_name {
server 1.2.3.4:5678;
server 2.3.4.5:6789;
}
--- config
location = /t {
content_by_lua_block {
local resolver = require('resty.resolver'):instance()
local servers = resolver:get_servers('some_name')
ngx.say('servers: ', #servers)
for i=1, #servers do
ngx.say(servers[i].address, ':', servers[i].port)
end
}
}
--- request
GET /t
--- response_body
servers: 2
1.2.3.4:5678
2.3.4.5:6789
--- 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
location = /t {
content_by_lua_block {
local nameservers = require('resty.resolver').nameservers()
ngx.say('nameservers: ', #nameservers, ' ', tostring(nameservers[1]))
}
}
--- request
GET /t
--- response_body
nameservers: 1 [dead::beef]:5353
--- user_files
>>> resolv.conf
=== 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
location = /t {
content_by_lua_block {
local nameservers = require('resty.resolver').nameservers()
ngx.say('nameservers: ', #nameservers, ' ', nameservers[1], ' ', nameservers[2])
}
}
--- request
GET /t
--- response_body
nameservers: 2 127.0.1.153 1.2.3.453
--- user_files
>>> resolv.conf
nameserver 127.0.1.1
nameserver 1.2.3.4