use
lib
"$RealBin/../lib/App"
;
my
$dir
=
"$RealBin/../lib/App"
;
SKIP: {
skip
"Unable to write to $RealBin"
unless
-w
$dir
;
if
($^O =~ m/win/i) {
my
$dudname
=
'/'
.
chr
(0);
$ipchgmon::opt_file
=
$dudname
;
throws_ok {ipchgmon::read_file()}
qr/Invalid argument/
,
'Invalid file name dies OK'
;
}
my
$fqname
=
$dir
.
'/test.txt'
;
my
$aoaref
= [
[
"11.11.11.11"
,
"Fri Aug 28 00:00:00 2022"
],
[
"101.101.101.101"
,
"Fri Aug 28 01:01:01 2022"
],
[
"B::0"
,
"Fri Aug 28 00:00:00 2022"
],
[
"B::1"
,
"Fri Aug 28 01:01:01 2022"
],
];
open
my
$fh
,
">:encoding(utf8)"
,
$fqname
or
die
"Couldn't create $fqname: $!"
;
my
$csv
= Text::CSV->new();
$csv
->
say
(
$fh
,
$_
)
for
@$aoaref
;
close
$fh
or
die
"Couldn't close $fqname: $!"
;
$ipchgmon::opt_file
=
$fqname
;
my
$aoa
= ipchgmon::read_file();
is
$$aoa
[0][0],
'11.11.11.11'
,
'first ip4 address'
;
is
$$aoa
[0][1],
'Fri Aug 28 00:00:00 2022'
,
'first ip4 timestamp'
;
is
$$aoa
[1][0],
'101.101.101.101'
,
'second ip4 address'
;
is
$$aoa
[1][1],
'Fri Aug 28 01:01:01 2022'
,
'second ip4 timestamp'
;
is
$$aoa
[2][0],
'B::0'
,
'first ip6 timestamp'
;
is
$$aoa
[2][1],
'Fri Aug 28 00:00:00 2022'
,
'first ip6 address'
;
is
$$aoa
[3][0],
'B::1'
,
'second ip6 timestamp'
;
is
$$aoa
[3][1],
'Fri Aug 28 01:01:01 2022'
,
'second ip6 address'
;
is_deeply
$aoa
,
$aoaref
,
'Aoa saves & reads correctly'
;
unlink
$fqname
or
warn
"Unable to delete $fqname at end of tests."
;
}
done_testing();