Separate recap variables from configuration variables
This commit is contained in:
parent
76afbb6673
commit
695c3c4be8
3 changed files with 409 additions and 358 deletions
729
ddclient.in
729
ddclient.in
File diff suppressed because it is too large
Load diff
|
@ -7,21 +7,23 @@ local $ddclient::globals{debug} = 1;
|
|||
local $ddclient::globals{verbose} = 1;
|
||||
local %ddclient::protocols = (
|
||||
protocol_a => ddclient::Protocol->new(
|
||||
variables => {
|
||||
host => {type => ddclient::T_STRING(), recap => 1},
|
||||
var_a => {type => ddclient::T_BOOL(), recap => 1},
|
||||
recapvars => {
|
||||
host => ddclient::T_STRING(),
|
||||
var_a => ddclient::T_BOOL(),
|
||||
},
|
||||
),
|
||||
protocol_b => ddclient::Protocol->new(
|
||||
variables => {
|
||||
host => {type => ddclient::T_STRING(), recap => 1},
|
||||
var_b => {type => ddclient::T_NUMBER(), recap => 1},
|
||||
recapvars => {
|
||||
host => ddclient::T_STRING(),
|
||||
var_b => ddclient::T_NUMBER(),
|
||||
},
|
||||
cfgvars => {
|
||||
var_b_non_recap => {type => ddclient::T_ANY()},
|
||||
},
|
||||
),
|
||||
);
|
||||
local %ddclient::variables =
|
||||
(merged => {map({ %{$ddclient::protocols{$_}{variables}}; } sort(keys(%ddclient::protocols)))});
|
||||
local %ddclient::cfgvars = (merged => {map({ %{$ddclient::protocols{$_}{cfgvars} // {}}; }
|
||||
sort(keys(%ddclient::protocols)))});
|
||||
|
||||
my @test_cases = (
|
||||
{
|
||||
|
|
|
@ -4,8 +4,8 @@ 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)),
|
||||
map({ ($_ => $ddclient::cfgvars{$_}) } grep($_ ne 'merged', keys(%ddclient::cfgvars))),
|
||||
map({ ("protocol=$_" => $ddclient::protocols{$_}{cfgvars}); } keys(%ddclient::protocols)),
|
||||
);
|
||||
my %seen;
|
||||
my @test_cases = (
|
||||
|
@ -24,10 +24,10 @@ for my $tc (@test_cases) {
|
|||
if ($tc->{def}{required}) {
|
||||
is($tc->{def}{default}, undef, "'$tc->{desc}' (required) has no default");
|
||||
} else {
|
||||
# Preserve all existing variables in $variables{merged} so that variables with dynamic
|
||||
# Preserve all existing variables in $cfgvars{merged} so that variables with dynamic
|
||||
# defaults can reference them.
|
||||
local %ddclient::variables = (merged => {
|
||||
%{$ddclient::variables{merged}},
|
||||
local %ddclient::cfgvars = (merged => {
|
||||
%{$ddclient::cfgvars{merged}},
|
||||
'var for test' => $tc->{def},
|
||||
});
|
||||
# Variables with dynamic defaults will need their own unit tests, but we can still check the
|
||||
|
@ -78,11 +78,11 @@ my @use_test_cases = (
|
|||
for my $tc (@use_test_cases) {
|
||||
my $desc = "'use' dynamic default: $tc->{desc}";
|
||||
local %ddclient::protocols = (protocol => ddclient::Protocol->new());
|
||||
local %ddclient::variables = (merged => {
|
||||
'protocol' => $ddclient::variables{'merged'}{'protocol'},
|
||||
'use' => $ddclient::variables{'protocol-common-defaults'}{'use'},
|
||||
'usev4' => $ddclient::variables{'merged'}{'usev4'},
|
||||
'usev6' => $ddclient::variables{'merged'}{'usev6'},
|
||||
local %ddclient::cfgvars = (merged => {
|
||||
'protocol' => $ddclient::cfgvars{'merged'}{'protocol'},
|
||||
'use' => $ddclient::cfgvars{'protocol-common-defaults'}{'use'},
|
||||
'usev4' => $ddclient::cfgvars{'merged'}{'usev4'},
|
||||
'usev6' => $ddclient::cfgvars{'merged'}{'usev6'},
|
||||
});
|
||||
local %ddclient::config = (host => {protocol => 'protocol', %{$tc->{cfg} // {}}});
|
||||
local %ddclient::opt;
|
||||
|
|
Loading…
Reference in a new issue