tests: Add some tests for use=cmd
, usev4=cmdv4
, usev6=cmdv6
This commit is contained in:
parent
1c178d4c09
commit
6fd9a6f106
2 changed files with 42 additions and 0 deletions
|
@ -77,6 +77,7 @@ handwritten_tests = \
|
|||
t/skip.pl \
|
||||
t/ssl-validate.pl \
|
||||
t/update_nics.pl \
|
||||
t/use_cmd.pl \
|
||||
t/use_web.pl \
|
||||
t/variable_defaults.pl \
|
||||
t/write_recap.pl
|
||||
|
|
41
t/use_cmd.pl
Normal file
41
t/use_cmd.pl
Normal file
|
@ -0,0 +1,41 @@
|
|||
use Test::More;
|
||||
BEGIN { SKIP: { eval { require Test::Warnings; 1; } or skip($@, 1); } }
|
||||
BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); }
|
||||
|
||||
local $ddclient::globals{debug} = 1;
|
||||
local $ddclient::globals{verbose} = 1;
|
||||
|
||||
my @test_cases;
|
||||
for my $ipv ('4', '6') {
|
||||
my $ip = $ipv eq '4' ? '192.0.2.1' : '2001:db8::1';
|
||||
for my $use ('use', "usev$ipv") {
|
||||
my @cmds = ();
|
||||
push(@cmds, 'cmd') if $use eq 'use' || $ipv eq '6';
|
||||
push(@cmds, "cmdv$ipv") if $use ne 'use';
|
||||
for my $cmd (@cmds) {
|
||||
my $cmdarg = "echo '$ip'";
|
||||
push(
|
||||
@test_cases,
|
||||
{
|
||||
desc => "$use=$cmd $cmd=\"$cmdarg\"",
|
||||
cfg => {$use => $cmd, $cmd => $cmdarg},
|
||||
want => $ip,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for my $tc (@test_cases) {
|
||||
local $ddclient::_l = ddclient::pushlogctx($tc->{desc});
|
||||
my $h = 'test-host';
|
||||
local $ddclient::config{$h} = $tc->{cfg};
|
||||
is(ddclient::get_ip(ddclient::strategy_inputs('use', $h)), $tc->{want}, $tc->{desc})
|
||||
if $tc->{cfg}{use};
|
||||
is(ddclient::get_ipv4(ddclient::strategy_inputs('usev4', $h)), $tc->{want}, $tc->{desc})
|
||||
if $tc->{cfg}{usev4};
|
||||
is(ddclient::get_ipv6(ddclient::strategy_inputs('usev6', $h)), $tc->{want}, $tc->{desc})
|
||||
if $tc->{cfg}{usev6};
|
||||
}
|
||||
|
||||
done_testing();
|
Loading…
Reference in a new issue