my ($host, $checkport) = @_;
my $server = defined $host && defined $host->{server} && defined $host->{server}{ip}
? $host->{server}{ip } : q{};
+ if (is_ip6($server)) {
+ $server = sprintf "[%s]" , $server;
+ }
my $port = defined $checkport ? $checkport
: defined $host && defined $host->{server} && defined $host->{server}{port}
? $host->{server}{port} : q{};
use subs qw(print);
use Cwd;
use L7lib;
-use Test::More tests => 41;
+use Test::More tests => 46;
L7lib::chdir();
L7lib::comment_out();
my $got = get_ip_port($host, $checkport);
is $got, '127.0.0.1:0', 'get_ip_port - get host ip and port zero';
}
+####### IPv6
+{
+ my $host = { server => { ip => '[::]', port => undef } };
+ my $checkport = undef;
+ my $got = get_ip_port($host, $checkport);
+ is $got, '', 'get_ip_port - host port and checkport is undef';
+}
+{
+ my $host = { server => { ip => '[::1]', port => 80 } };
+ my $checkport = undef;
+ my $got = get_ip_port($host, $checkport);
+ is $got, '[::1]:80', 'get_ip_port - get host ip6 and port';
+}
+{
+ my $host = { server => { ip => '[::1]', port => 80 } };
+ my $checkport = 8080;
+ my $got = get_ip_port($host, $checkport);
+ is $got, '[::1]:8080', 'get_ip_port - get host ip6 and checkport';
+}
+{
+ my $host = { server => { ip => '[::1]', port => 0 } };
+ my $checkport = undef;
+ my $got = get_ip_port($host, $checkport);
+ is $got, '127.0.0.1:0', 'get_ip_port - get host ip6 and port zero';
+}
+{
+ my $host = { server => { ip => '[fe80::200:1aff:fe19:5534%eth0]', port => 0 } };
+ my $checkport = undef;
+ my $got = get_ip_port($host, $checkport);
+ is $got, '[fe80::200:1aff:fe19:5534%eth0]:0', 'get_ip_port - get host ip6(LinkLocal) and port zero';
+}
# - get_health_check_id_str
{
my $v = undef;