BEGIN
{ use_ok(
'App::BackupPlan'
)};
my
$configFile
=
'TestData/testPlan.xml'
;
my
$logFile
=
'TestData/log4perl.conf'
;
my
@planArgs
= (
$configFile
,
$logFile
);
my
$plan
= new_ok
'App::BackupPlan'
=> \
@planArgs
;
my
$parser
= new XML::DOM::Parser;
my
$doc
=
$parser
->parsefile (
$configFile
) or
die
"Could not parse $configFile"
;
my
(
$defaultPolicy
,
%raw_policies
) = App::BackupPlan::getPolicies(
$doc
);
isa_ok(
$defaultPolicy
,
'App::BackupPlan::Policy'
);
is(3,
$defaultPolicy
->{maxFiles},
'policy default max number of files'
);
cmp_ok(
'1m'
,
'eq'
,
$defaultPolicy
->{frequency},
'policy default frequency'
);
is(1,
keys
%raw_policies
,
'expected number of policies'
);
ok(
defined
(
$raw_policies
{test}),
'policy test is present'
);
my
$time
= timelocal(0,0,0,15,9,1963);
my
$Ts
= App::BackupPlan::formatTimeSpan(
$time
);
cmp_ok(
'19631015'
,
'eq'
,
$Ts
,
'time formatting test'
);
my
$then
= App::BackupPlan::addTimeSpan(
$time
,
'7d'
);
my
$thenTs
= App::BackupPlan::formatTimeSpan(
$then
);
cmp_ok(
'19631022'
,
'eq'
,
$thenTs
,
'add seven days'
);
$then
= App::BackupPlan::addTimeSpan(
$time
,
'2m'
);
$thenTs
= App::BackupPlan::formatTimeSpan(
$then
);
cmp_ok(
'19631213'
,
'eq'
,
$thenTs
,
'add two months'
);
$then
= App::BackupPlan::addTimeSpan(
$time
,
'1y'
);
$thenTs
= App::BackupPlan::formatTimeSpan(
$then
);
cmp_ok(
'19641009'
,
'eq'
,
$thenTs
,
'add one year'
);
$then
= App::BackupPlan::subTimeSpan(
$time
,
'7d'
);
$thenTs
= App::BackupPlan::formatTimeSpan(
$then
);
cmp_ok(
'19631008'
,
'eq'
,
$thenTs
,
'subtracting seven days'
);
$then
= App::BackupPlan::subTimeSpan(
$time
,
'2m'
);
$thenTs
= App::BackupPlan::formatTimeSpan(
$then
);
cmp_ok(
'19630816'
,
'eq'
,
$thenTs
,
'subtracting two months'
);
$then
= App::BackupPlan::subTimeSpan(
$time
,
'1y'
);
$thenTs
= App::BackupPlan::formatTimeSpan(
$then
);
cmp_ok(
'19621020'
,
'eq'
,
$thenTs
,
'subtracting one year'
);
my
$policy
=
$raw_policies
{
'test'
};
my
$sd
=
$policy
->getSourceDir;
my
$pr
=
$policy
->getPrefix;
my
%files
= App::BackupPlan::getFiles(
$sd
,
$pr
);
my
$nc
=
keys
%files
;
cmp_ok(0,
'lt'
,
$nc
,
'number of files in source directory'
);
App::BackupPlan::getEnvironment();
my
$out
=
$policy
->tar(App::BackupPlan::formatTimeSpan(
time
));
unlike(
$out
,
qr/Error/
,
'tar does not produce an Error'
);
like(
$out
,
qr/system/
,
'system tar'
);
$out
=
$policy
->perlTar(App::BackupPlan::formatTimeSpan(
time
));
unlike(
$out
,
qr/Error/
,
'tar does not produce an Error'
);
like(
$out
,
qr/perl/
,
'perl tar'
);