3 no warnings qw(redefine once);
8 use Test::More tests => 41;
12 require './l7directord';
15 #...............................................
20 my $checkport = undef;
21 my $got = get_ip_port($host, $checkport);
22 is $got, '', 'get_ip_port - host and checkport is undef';
25 my $host = { server => { ip => '127.0.0.1', port => undef } };
26 my $checkport = undef;
27 my $got = get_ip_port($host, $checkport);
28 is $got, '', 'get_ip_port - host port and checkport is undef';
31 my $host = { server => { ip => undef, port => undef } };
33 my $got = get_ip_port($host, $checkport);
34 is $got, '', 'get_ip_port - host ip is undef';
37 my $host = { server => { ip => '127.0.0.1', port => 80 } };
38 my $checkport = undef;
39 my $got = get_ip_port($host, $checkport);
40 is $got, '127.0.0.1:80', 'get_ip_port - get host ip and port';
43 my $host = { server => { ip => '127.0.0.1', port => 80 } };
45 my $got = get_ip_port($host, $checkport);
46 is $got, '127.0.0.1:8080', 'get_ip_port - get host ip and checkport';
49 my $host = { server => { ip => '127.0.0.1', port => 0 } };
50 my $checkport = undef;
51 my $got = get_ip_port($host, $checkport);
52 is $got, '127.0.0.1:0', 'get_ip_port - get host ip and port zero';
54 # - get_health_check_id_str
57 my $r = { server => {} };
58 my $got = get_health_check_id_str($v, $r);
59 is $got, undef, 'get_health_check_id_str - v is undef';
64 my $got = get_health_check_id_str($v, $r);
65 is $got, undef, 'get_health_check_id_str - r is undef';
70 my $got = get_health_check_id_str($v, $r);
71 is $got, undef, 'get_health_check_id_str - r->{server} is undef';
75 my $r = { server => {} };
76 my $got = get_health_check_id_str($v, $r);
77 is $got, '::::::::::::::::::', 'get_health_check_id_str - all args is ok(empty)';
81 my $r = { server => { ip => 1 } };
82 my $got = get_health_check_id_str($v, $r);
83 is $got, '1::::::::::::::::::', 'get_health_check_id_str - set real ip';
87 my $r = { server => { port => 1 } };
88 my $got = get_health_check_id_str($v, $r);
89 is $got, ':1:::::::::::::::::', 'get_health_check_id_str - set real port';
92 my $v = { checkport => 1 };
93 my $r = { server => {} };
94 my $got = get_health_check_id_str($v, $r);
95 is $got, ':1:::::::::::::::::', 'get_health_check_id_str - set checkport';
98 my $v = { checktype => 'connect' };
99 my $r = { server => {} };
100 my $got = get_health_check_id_str($v, $r);
101 is $got, '::connect::::::::::::::::', 'get_health_check_id_str - set checktype';
104 my $v = { service => 'http' };
105 my $r = { server => {} };
106 my $got = get_health_check_id_str($v, $r);
107 is $got, ':::http:::::::::::::::', 'get_health_check_id_str - set service';
110 my $v = { protocol => 'tcp' };
111 my $r = { server => {} };
112 my $got = get_health_check_id_str($v, $r);
113 is $got, '::::tcp::::::::::::::', 'get_health_check_id_str - set protocol';
116 my $v = { num_connects => 1 };
117 my $r = { server => {} };
118 my $got = get_health_check_id_str($v, $r);
119 is $got, ':::::1:::::::::::::', 'get_health_check_id_str - set num_connects';
123 my $r = { server => {}, request => '/' };
124 my $got = get_health_check_id_str($v, $r);
125 is $got, '::::::/::::::::::::', 'get_health_check_id_str - set real request';
129 my $r = { server => {}, receive => 'ok' };
130 my $got = get_health_check_id_str($v, $r);
131 is $got, ':::::::ok:::::::::::', 'get_health_check_id_str - set real receive';
134 my $v = { httpmethod => 'GET' };
135 my $r = { server => {} };
136 my $got = get_health_check_id_str($v, $r);
137 is $got, '::::::::GET::::::::::', 'get_health_check_id_str - set httpmethod';
140 my $v = { virtualhost => 'virtual' };
141 my $r = { server => {} };
142 my $got = get_health_check_id_str($v, $r);
143 is $got, ':::::::::virtual:::::::::', 'get_health_check_id_str - set virtualhost';
146 my $v = { login => 'ftp' };
147 my $r = { server => {} };
148 my $got = get_health_check_id_str($v, $r);
149 is $got, '::::::::::ftp::::::::', 'get_health_check_id_str - set login';
152 my $v = { passwd => 'ftp' };
153 my $r = { server => {} };
154 my $got = get_health_check_id_str($v, $r);
155 is $got, ':::::::::::ftp:::::::', 'get_health_check_id_str - set passwd';
158 my $v = { database => 'template' };
159 my $r = { server => {} };
160 my $got = get_health_check_id_str($v, $r);
161 is $got, '::::::::::::template::::::', 'get_health_check_id_str - set database';
164 my $v = { customcheck => '/bin/echo' };
165 my $r = { server => {} };
166 my $got = get_health_check_id_str($v, $r);
167 is $got, ':::::::::::::/bin/echo:::::', 'get_health_check_id_str - set customcheck';
170 my $v = { checkinterval => 1 };
171 my $r = { server => {} };
172 my $got = get_health_check_id_str($v, $r);
173 is $got, '::::::::::::::1::::', 'get_health_check_id_str - set checkinterval';
176 my $v = { checkcount => 1 };
177 my $r = { server => {} };
178 my $got = get_health_check_id_str($v, $r);
179 is $got, ':::::::::::::::1:::', 'get_health_check_id_str - set checkcount';
182 my $v = { checktimeout => 1 };
183 my $r = { server => {} };
184 my $got = get_health_check_id_str($v, $r);
185 is $got, '::::::::::::::::1::', 'get_health_check_id_str - set checktimeout';
188 my $v = { negotiatetimeout => 1 };
189 my $r = { server => {} };
190 my $got = get_health_check_id_str($v, $r);
191 is $got, ':::::::::::::::::1:', 'get_health_check_id_str - set negotiatetimeout';
194 my $v = { retryinterval => 1 };
195 my $r = { server => {} };
196 my $got = get_health_check_id_str($v, $r);
197 is $got, '::::::::::::::::::1', 'get_health_check_id_str - set retryinterval';
202 checktype => 'connect',
207 virtualhost => 'virtual',
210 database => 'template',
211 customcheck => '/bin/echo',
215 negotiatetimeout => 6,
219 server => { ip => 1, port => 1 },
223 my $got = get_health_check_id_str($v, $r);
224 is $got, '1:10:connect:http:tcp:2:/:ok:GET:virtual:ftp:ftp:template:/bin/echo:3:4:5:6:7',
225 'get_health_check_id_str - set all';
227 # - get_virtual_id_str
230 my $got = get_virtual_id_str($v);
231 is $got, undef, 'get_virtual_id_str - v is undef';
235 my $got = get_virtual_id_str($v);
236 is $got, undef, 'get_virtual_id_str - v->{module} is undef';
239 my $v = { module => {} };
240 my $got = get_virtual_id_str($v);
241 is $got, '::', 'get_virtual_id_str - arg is ok(empty)';
244 my $v = { module => {}, protocol => 'tcp' };
245 my $got = get_virtual_id_str($v);
246 is $got, 'tcp::', 'get_virtual_id_str - set protocol';
249 my $v = { module => {}, server => { ip => '127.0.0.1', port => 80 } };
250 my $got = get_virtual_id_str($v);
251 is $got, ':127.0.0.1:80:', 'get_virtual_id_str - set server';
254 my $v = { module => { name => 'cinsert', key => '--cookie-name monkey' } };
255 my $got = get_virtual_id_str($v);
256 is $got, '::cinsert --cookie-name monkey', 'get_virtual_id_str - set module';
260 server => { ip => '127.0.0.1', port => 80 },
261 module => { name => 'cinsert', key => '--cookie-name monkey' },
264 my $got = get_virtual_id_str($v);
265 is $got, 'tcp:127.0.0.1:80:cinsert --cookie-name monkey', 'get_virtual_id_str - set all';
269 my $got = get_forward_flag();
270 is $got, '', 'get_forward_flag - forward is undef';
273 my $got = get_forward_flag('MAsq');
274 is $got, '-m', 'get_forward_flag - forward is masq';
277 my $got = get_forward_flag('MAsqs');
278 is $got, '', 'get_forward_flag - forward is otherwise';
281 #...............................................
288 *ld_log = \&__ld_log;