|
| 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