t/10-minimal.t
changeset 10 4243e22505f9
parent 9 b2a26d05b063
child 14 8da9e81acf82
equal deleted inserted replaced
9:b2a26d05b063 10:4243e22505f9
     3 use strict;
     3 use strict;
     4 use warnings;
     4 use warnings;
     5 use Test::More;
     5 use Test::More;
     6 use File::Temp;
     6 use File::Temp;
     7 use Test::Exception;
     7 use Test::Exception;
       
     8 use Storable qw(freeze);
     8 
     9 
     9 my $tmp = File::Temp->new;
    10 my $tmp = File::Temp->new;
    10 $tmp->print(<<__);
    11 $tmp->print(<<__);
    11     a
    12     a
    12     b
    13     b
    19 sub dig_ns {
    20 sub dig_ns {
    20     sort map { /(\S+?)\.?$/ } `dig +short NS @_`;
    21     sort map { /(\S+?)\.?$/ } `dig +short NS @_`;
    21 }
    22 }
    22 
    23 
    23 # we require it, it's not a normal module
    24 # we require it, it's not a normal module
    24 require_ok 'blib/nagios/plugins/ius/check_dns-serial'
    25 require_ok 'blib/nagios/plugins/ius/check_dns-delegation'
    25   or BAIL_OUT q{can't require the module};
    26   or BAIL_OUT q{can't require the module};
    26 
    27 
    27 
    28 
    28 subtest 'tools' => sub {
    29 subtest 'tools' => sub {
    29     is_deeply [sort +uniq(qw(a b a c))], [qw(a b c)] => 'uniq helper';
    30     is_deeply [sort +uniq(qw(a b a c))], [qw(a b c)] => 'uniq helper';
    39 
    40 
    40     is $r1a, $r1b => 'same google';
    41     is $r1a, $r1b => 'same google';
    41     is $r2a, $r2b => 'same level3';
    42     is $r2a, $r2b => 'same level3';
    42     isnt $r1a, $r2a => 'not same google/level3';
    43     isnt $r1a, $r2a => 'not same google/level3';
    43 
    44 
    44     my @a;
    45     my (@a, @b);
    45     @a = qw[8.8.8.8];
    46     @a = qw[8.8.8.1];
    46     my $r3a = Net::DNS::Resolver->new(nameservers => \@a);
    47     my $r3a = Net::DNS::Resolver->new(nameservers => \@a);
    47     @a = qw[8.8.4.4];
    48     @a = qw[8.8.4.2];
    48     my $r3b = Net::DNS::Resolver->new(nameservers => \@a);
    49     my $r3b = Net::DNS::Resolver->new(nameservers => \@a);
       
    50     isnt $r3a, $r3b => 'same ref, but not same object';
    49 
    51 
    50     isnt $r3a, $r3b => 'same ref, but not same object';
    52     @b = @a;
       
    53     is freeze(\@a), freeze(\@b) => 'frozen lists';
       
    54     my $r3c = Net::DNS::Resolver->new(nameservers => \@b);
       
    55     is $r3b, $r3c => 'same servers, but not same ref';
    51 
    56 
    52 };
    57 };
    53 
    58 
    54 
    59 
    55 # get_domains should read a list of names, either from a file
    60 # get_domains should read a list of names, either from a file