t/10-dnsvi.t
changeset 32 0c0b4424d666
parent 29 fef56276dc8e
child 33 7d0fac2ec585
equal deleted inserted replaced
31:fbaff8f2b9bb 32:0c0b4424d666
     1 #! perl
     1 #! perl
     2 
     2 
       
     3 use 5.010;
     3 use Test::More;
     4 use Test::More;
     4 use strict;
     5 use strict;
     5 use warnings;
     6 use warnings;
       
     7 use File::Basename;
     6 
     8 
     7 use_ok 'DNS::Vi' or BAIL_OUT 'DNS::Vi not found!';
     9 use_ok 'DNS::Vi' or BAIL_OUT 'DNS::Vi not found!';
     8 can_ok 'DNS::Vi', qw(ttl2h h2ttl parse nice delta edit update show);
    10 can_ok 'DNS::Vi', qw(ttl2h h2ttl parse nice delta edit update show);
     9 
    11 
    10 # TODO: more tests!
    12 # TODO: more tests!
    11 is ttl2h(86400), '1d',  '-> 1d';
    13 is ttl2h(86400), '1d',  '-> 1d';
    12 is h2ttl('1d'),  86400, '<- 1d';
    14 is h2ttl('1d'),  86400, '<- 1d';
    13 
    15 
    14 my $data1 = do {
    16 sub slurp {
    15     local $/    = undef;
    17     local $/ = undef;
    16     local @ARGV = 't/samples/kugelbus-axfr';
    18     open(my $x, '<', shift);
    17     <>;
    19     return <$x>;
       
    20 }
       
    21 
       
    22 # the results must match the t/samples/? files
       
    23 my %result = (
       
    24     axfr => {
       
    25         RRSETS => 64,
       
    26         SOA    => 1,
       
    27         NS     => 2,
       
    28         A      => 6,
       
    29         TXT    => 3,
       
    30         AAAA   => 1,
       
    31     },
       
    32     a => {
       
    33         RRSETS => 32,
       
    34         SOA    => 1,
       
    35         NS     => 16,
       
    36         A      => 9,
       
    37         TXT    => 4,
       
    38         AAAA   => 0,
       
    39     },
       
    40     b => {
       
    41         RRSETS => 7,
       
    42         SOA    => 1,
       
    43         NS     => 2,
       
    44         A      => 1,
       
    45         TXT    => 3,
       
    46         AAAA   => 0,
       
    47     },
       
    48 );
       
    49 
       
    50 # uniq list of rrtypes we want to test
       
    51 my @sets = do {
       
    52     my %h;
       
    53     @h{ map { keys %{$_} } values %result } = ();
       
    54     grep { $_ ne 'RRSETS' } sort keys %h;
    18 };
    55 };
    19 
    56 
    20 # check parser with and without skip list
    57 foreach my $sample (keys %result) {
    21 is parse($data1), 64 => '64 rrsets';
    58     my $file = "t/samples/$sample";
    22 my @zone1 =
       
    23   parse($data1, { -skip => [qw(RRSIG NSEC3 NSEC3PARAM NSEC DNSKEY TSIG)] });
       
    24 is @zone1, 18 => '18 rrsets';
       
    25 
    59 
    26 subtest 'parsed data' => sub {
    60     subtest "sample $file" => sub {
    27     my ($soa) =
    61         my %result = %{ $result{$sample} };
    28       map { $_->{rrset} } grep { $_->{rrset}{rrtype} eq 'SOA' } @zone1;
    62         my @zone   = parse(slurp $file);
    29     is ref $soa, 'HASH' => 'got result hash';
    63         is @zone, $result{RRSETS} => "$sample: $result{RRSETS} RRSETS";
    30     is $soa->{rrtype}, 'SOA' => 'is SOA';
    64         foreach my $type (@sets) {
    31     is $soa->{data},
    65             is grep({ $_->{rrset}{rrtype} eq $type } @zone),
    32         'pu.schlittermann.de. '
    66               $result{$type} => "$sample: $result{$type} $type";
    33       . 'hostmaster.net.schlittermann.de. '
    67         }
    34       . '18 86400 7200 604800 86400' => 'has expected data';
       
    35 
    68 
    36     my @txt = map { $_->{rrset} } grep { $_->{rrset}{rrtype} eq 'TXT' } @zone1;
    69         my ($added, $deleted) = delta(\@zone, \@zone);
    37     is @txt, 3 => 'got 3 txt records';
    70         is @$added,   0 => 'nothing added';
    38 };
    71         is @$deleted, 0 => 'nothing deleted';
    39 
    72       }
    40 # delta should find noting
    73 }
    41 subtest 'delta' => sub { 
       
    42     my ($add, $del) = delta(\@zone1, \@zone1);
       
    43     is @$add, 0 => 'nothing added';
       
    44     is @$del, 0 => 'nothing deleted';
       
    45 };
       
    46 
    74 
    47 done_testing();
    75 done_testing();