Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 591904c

Browse files
committed
tests: Add some tests for use=cmd, usev4=cmdv4, usev6=cmdv6
1 parent 7ec5038 commit 591904c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ handwritten_tests = \
7777
t/skip.pl \
7878
t/ssl-validate.pl \
7979
t/update_nics.pl \
80+
t/use_cmd.pl \
8081
t/use_web.pl \
8182
t/variable_defaults.pl \
8283
t/write_recap.pl

t/use_cmd.pl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use Test::More;
2+
BEGIN { SKIP: { eval { require Test::Warnings; 1; } or skip($@, 1); } }
3+
BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); }
4+
5+
local $ddclient::globals{debug} = 1;
6+
local $ddclient::globals{verbose} = 1;
7+
8+
my @test_cases;
9+
for my $ipv ('4', '6') {
10+
my $ip = $ipv eq '4' ? '192.0.2.1' : '2001:db8::1';
11+
for my $use ('use', "usev$ipv") {
12+
my @cmds = ();
13+
push(@cmds, 'cmd') if $use eq 'use' || $ipv eq '6';
14+
push(@cmds, "cmdv$ipv") if $use ne 'use';
15+
for my $cmd (@cmds) {
16+
my $cmdarg = "echo '$ip'";
17+
push(
18+
@test_cases,
19+
{
20+
desc => "$use=$cmd $cmd=\"$cmdarg\"",
21+
cfg => {$use => $cmd, $cmd => $cmdarg},
22+
want => $ip,
23+
},
24+
);
25+
}
26+
}
27+
}
28+
29+
for my $tc (@test_cases) {
30+
local $ddclient::_l = ddclient::pushlogctx($tc->{desc});
31+
my $h = 'test-host';
32+
local $ddclient::config{$h} = $tc->{cfg};
33+
is(ddclient::get_ip(ddclient::strategy_inputs('use', $h)), $tc->{want}, $tc->{desc})
34+
if $tc->{cfg}{use};
35+
is(ddclient::get_ipv4(ddclient::strategy_inputs('usev4', $h)), $tc->{want}, $tc->{desc})
36+
if $tc->{cfg}{usev4};
37+
is(ddclient::get_ipv6(ddclient::strategy_inputs('usev6', $h)), $tc->{want}, $tc->{desc})
38+
if $tc->{cfg}{usev6};
39+
}
40+
41+
done_testing();

0 commit comments

Comments
 (0)