t/10-minimal.t
changeset 15 bb7b3ae76cc8
parent 14 8da9e81acf82
child 17 07827090c4fc
equal deleted inserted replaced
14:8da9e81acf82 15:bb7b3ae76cc8
    10 my $tmp = File::Temp->new;
    10 my $tmp = File::Temp->new;
    11 $tmp->print(<<__);
    11 $tmp->print(<<__);
    12 # kommentar
    12 # kommentar
    13     a # more comment
    13     a # more comment
    14     b
    14     b
    15     c
    15     c ns1 ns2 # comment
       
    16     d
    16 __
    17 __
    17 $tmp->flush;
    18 $tmp->flush;
       
    19 
    18 
    20 
    19 sub dig_serial { (split " ", `dig +short SOA @_`)[2] }
    21 sub dig_serial { (split " ", `dig +short SOA @_`)[2] }
    20 
    22 
    21 sub dig_ns {
    23 sub dig_ns {
    22     sort map { /(\S+?)\.?$/ } `dig +short NS @_`;
    24     sort map { /(\S+?)\.?$/ } `dig +short NS @_`;
    27   or BAIL_OUT q{can't require the module};
    29   or BAIL_OUT q{can't require the module};
    28 
    30 
    29 
    31 
    30 subtest 'tools' => sub {
    32 subtest 'tools' => sub {
    31     is_deeply [sort +uniq(qw(a b a c))], [qw(a b c)] => 'uniq helper';
    33     is_deeply [sort +uniq(qw(a b a c))], [qw(a b c)] => 'uniq helper';
       
    34 
       
    35     # get_domains should read a list of names, either from a file
       
    36     # or from the arguments, or from a combination of both
       
    37     is_deeply [get_domains(qw(a b c))], [qw(a b c)] => 'domains from list';
       
    38     is_deeply [get_domains("$tmp")],    [qw(a b c d)] => 'domains from file';
       
    39     is_deeply [get_domains('a', "$tmp", 'z')],
       
    40       [qw(a a b c d z)] => 'domains from args and file';
       
    41 
       
    42     is_deeply {read_override("$tmp")}, { c => ['ns1', 'ns2'] }, 'override file';
    32 
    43 
    33     my %google = ( nameservers => [qw/8.8.8.8 8.8.4.4/]);
    44     my %google = ( nameservers => [qw/8.8.8.8 8.8.4.4/]);
    34     my %level3 = ( nameservers => [qw/209.244.0.3 209.244.0.4/]);
    45     my %level3 = ( nameservers => [qw/209.244.0.3 209.244.0.4/]);
    35 
    46 
    36     my $r1a = Net::DNS::Resolver->new(%google);
    47     my $r1a = Net::DNS::Resolver->new(%google);
    56     is $r3b, $r3c => 'same servers, but not same ref';
    67     is $r3b, $r3c => 'same servers, but not same ref';
    57 
    68 
    58 };
    69 };
    59 
    70 
    60 
    71 
    61 # get_domains should read a list of names, either from a file
    72 my %override = (
    62 # or from the arguments, or from a combination of both
    73     'example.com' => [qw(ns1.foobar.de ns2.foobar.com)],
    63 is_deeply [get_domains(qw(a b c))], [qw(a b c)] => 'domains from list';
    74 );
    64 is_deeply [get_domains("$tmp")],    [qw(a b c)] => 'domains from file';
    75 
    65 is_deeply [get_domains('a', "$tmp", 'z')],
    76 is_deeply [ns('example.com', nameservers => [qw/127.0.0.1/], override => \%override)],
    66   [qw(a a b c z)] => 'domains from args and file';
    77     $override{'example.com'} => 'override';
    67 
    78 
    68 for (qw(heise.de schlittermann.de google.com debian.org example.org)) {
    79 for (qw(heise.de schlittermann.de google.com debian.org example.org)) {
    69 
    80 
    70     subtest $_ => sub {
    81     subtest $_ => sub {
    71 
    82