--- a/t/10-dnsvi.t Thu Sep 04 17:04:03 2014 +0200
+++ b/t/10-dnsvi.t Thu Nov 13 22:23:04 2014 +0100
@@ -1,8 +1,10 @@
#! perl
+use 5.010;
use Test::More;
use strict;
use warnings;
+use File::Basename;
use_ok 'DNS::Vi' or BAIL_OUT 'DNS::Vi not found!';
can_ok 'DNS::Vi', qw(ttl2h h2ttl parse nice delta edit update show);
@@ -11,37 +13,63 @@
is ttl2h(86400), '1d', '-> 1d';
is h2ttl('1d'), 86400, '<- 1d';
-my $data1 = do {
- local $/ = undef;
- local @ARGV = 't/samples/kugelbus-axfr';
- <>;
+sub slurp {
+ local $/ = undef;
+ open(my $x, '<', shift);
+ return <$x>;
+}
+
+# the results must match the t/samples/? files
+my %result = (
+ axfr => {
+ RRSETS => 64,
+ SOA => 1,
+ NS => 2,
+ A => 6,
+ TXT => 3,
+ AAAA => 1,
+ },
+ a => {
+ RRSETS => 32,
+ SOA => 1,
+ NS => 16,
+ A => 9,
+ TXT => 4,
+ AAAA => 0,
+ },
+ b => {
+ RRSETS => 7,
+ SOA => 1,
+ NS => 2,
+ A => 1,
+ TXT => 3,
+ AAAA => 0,
+ },
+);
+
+# uniq list of rrtypes we want to test
+my @sets = do {
+ my %h;
+ @h{ map { keys %{$_} } values %result } = ();
+ grep { $_ ne 'RRSETS' } sort keys %h;
};
-# check parser with and without skip list
-is parse($data1), 64 => '64 rrsets';
-my @zone1 =
- parse($data1, { -skip => [qw(RRSIG NSEC3 NSEC3PARAM NSEC DNSKEY TSIG)] });
-is @zone1, 18 => '18 rrsets';
+foreach my $sample (keys %result) {
+ my $file = "t/samples/$sample";
-subtest 'parsed data' => sub {
- my ($soa) =
- map { $_->{rrset} } grep { $_->{rrset}{rrtype} eq 'SOA' } @zone1;
- is ref $soa, 'HASH' => 'got result hash';
- is $soa->{rrtype}, 'SOA' => 'is SOA';
- is $soa->{data},
- 'pu.schlittermann.de. '
- . 'hostmaster.net.schlittermann.de. '
- . '18 86400 7200 604800 86400' => 'has expected data';
+ subtest "sample $file" => sub {
+ my %result = %{ $result{$sample} };
+ my @zone = parse(slurp $file);
+ is @zone, $result{RRSETS} => "$sample: $result{RRSETS} RRSETS";
+ foreach my $type (@sets) {
+ is grep({ $_->{rrset}{rrtype} eq $type } @zone),
+ $result{$type} => "$sample: $result{$type} $type";
+ }
- my @txt = map { $_->{rrset} } grep { $_->{rrset}{rrtype} eq 'TXT' } @zone1;
- is @txt, 3 => 'got 3 txt records';
-};
-
-# delta should find noting
-subtest 'delta' => sub {
- my ($add, $del) = delta(\@zone1, \@zone1);
- is @$add, 0 => 'nothing added';
- is @$del, 0 => 'nothing deleted';
-};
+ my ($added, $deleted) = delta(\@zone, \@zone);
+ is @$added, 0 => 'nothing added';
+ is @$deleted, 0 => 'nothing deleted';
+ }
+}
done_testing();