Add variable default value tests
This commit is contained in:
parent
eab72ef6d7
commit
49f5551764
3 changed files with 35 additions and 2 deletions
|
@ -77,6 +77,7 @@ handwritten_tests = \
|
|||
t/parse_assignments.pl \
|
||||
t/skip.pl \
|
||||
t/ssl-validate.pl \
|
||||
t/variable_defaults.pl \
|
||||
t/write_recap.pl
|
||||
generated_tests = \
|
||||
t/version.pl
|
||||
|
|
|
@ -556,7 +556,7 @@ sub setv {
|
|||
'minimum' => shift,
|
||||
};
|
||||
}
|
||||
my %variables = (
|
||||
our %variables = (
|
||||
'global-defaults' => {
|
||||
'daemon' => setv(T_DELAY, 0, 0, $daemon_default, interval('60s')),
|
||||
'foreground' => setv(T_BOOL, 0, 0, 0, undef),
|
||||
|
@ -706,7 +706,7 @@ my %variables = (
|
|||
'wildcard' => setv(T_BOOL, 0, 1, 0, undef),
|
||||
},
|
||||
);
|
||||
my %protocols = (
|
||||
our %protocols = (
|
||||
'1984' => {
|
||||
'force_update' => undef,
|
||||
'update' => \&nic_1984_update,
|
||||
|
|
32
t/variable_defaults.pl
Normal file
32
t/variable_defaults.pl
Normal file
|
@ -0,0 +1,32 @@
|
|||
use Test::More;
|
||||
SKIP: { eval { require Test::Warnings; } or skip($@, 1); }
|
||||
eval { require 'ddclient'; } or BAIL_OUT($@);
|
||||
|
||||
my %variable_collections = (
|
||||
map({ ($_ => $ddclient::variables{$_}) } grep($_ ne 'merged', keys(%ddclient::variables))),
|
||||
map({ ("protocol=$_" => $ddclient::protocols{$_}{variables}); } keys(%ddclient::protocols)),
|
||||
);
|
||||
my %seen;
|
||||
my @test_cases = (
|
||||
map({
|
||||
my $vcn = $_;
|
||||
my $vc = $variable_collections{$_};
|
||||
map({
|
||||
my $def = $vc->{$_};
|
||||
my $seen = exists($seen{$def});
|
||||
$seen{$def} = undef;
|
||||
({desc => "$vcn $_", def => $vc->{$_}}) x !$seen;
|
||||
} sort(keys(%$vc)));
|
||||
} sort(keys(%variable_collections))),
|
||||
);
|
||||
for my $tc (@test_cases) {
|
||||
if ($tc->{def}{required}) {
|
||||
is($tc->{def}{default}, undef, "'$tc->{desc}' (required) has no default");
|
||||
} else {
|
||||
my $norm;
|
||||
my $valid = eval { $norm = ddclient::check_value($tc->{def}{default}, $tc->{def}); 1; };
|
||||
ok($valid, "'$tc->{desc}' (optional) has a valid default");
|
||||
is($norm, $tc->{def}{default}, "'$tc->{desc}' default normalizes to itself") if $valid;
|
||||
}
|
||||
}
|
||||
done_testing();
|
Loading…
Reference in a new issue