t/10-minimal.t
changeset 1 cff9b7e57f19
child 5 2e27cfdf85ea
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/t/10-minimal.t	Tue Dec 30 00:37:59 2014 +0100
@@ -0,0 +1,54 @@
+use 5.014;
+use strict;
+use warnings;
+use Test::More;
+use File::Temp;
+use Test::Exception;
+
+my $tmp = File::Temp->new;
+$tmp->print(<<__);
+    a
+    b
+    c
+__
+$tmp->flush;
+
+sub dig_serial { (split " ", `dig +short SOA @_`)[2] }
+sub dig_ns { sort map { /(\S+?)\.?$/ } `dig +short NS @_` }
+
+# we require it, it's not a normal module
+require_ok 'blib/nagios/plugins/ius/check_dns-serial'
+  or BAIL_OUT q{can't require the module};
+
+is_deeply [sort +uniq(qw(a b a c))], [qw(a b c)] => 'uniq helper';
+
+# get_domains should read a list of names, either from a file
+# or from the arguments, or from a combination of both
+is_deeply [get_domains(qw(a b c))], [qw(a b c)] => 'domains from list';
+is_deeply [get_domains("$tmp")],    [qw(a b c)] => 'domains from file';
+is_deeply [get_domains('a', "$tmp", 'z')],
+  [qw(a a b c z)] => 'domains from args and file';
+
+for (qw(heise.de schlittermann.de google.com debian.org example.org)) {
+
+        subtest $_ => sub {
+
+            # get_ns should return the NS from public dns servers
+            is_deeply [get_ns($_)], [dig_ns($_)] => "ns \@default";
+            is_deeply [get_ns('@8.8.4.4', $_)], [dig_ns('@8.8.4.4', $_)] => "ns \@8.8.4.4";
+            is get_serial('@8.8.8.8', $_), dig_serial('@8.8.8.8', $_) => 'serial';
+        };
+
+}
+
+# ns for some domain we're not the master for, should be refused
+throws_ok { get_ns('@212.80.235.130', 'heise.de') } qr/^REFUSED/ => 'throws on refused query';
+throws_ok { get_ns('safasdfasdfrandomadsfefvddeas') } qr/^NXDOMAIN/ => 'throws on nx domain';
+
+ok ns_ok('@212.80.235.130', 'schlittermann.de') => 'ns for schlittermann.de';
+throws_ok { ns_ok('@212.80.235.130', 'heise.de') } qr/differ/ => 'ns for heise.de';
+
+
+# serial
+
+done_testing();