Add t/00-basic.t
authorHeiko Schlittermann <hs@schlittermann.de>
Wed, 01 Jun 2016 00:16:29 +0200
changeset 19 7c5787eaccb5
parent 18 936efccc64e6
child 20 2c6f22539c7f
Add t/00-basic.t
lib/Nagios/Check/DNS/check_tlsa_record.pm
t/00-basic.t
--- a/lib/Nagios/Check/DNS/check_tlsa_record.pm	Tue May 31 23:45:16 2016 +0200
+++ b/lib/Nagios/Check/DNS/check_tlsa_record.pm	Wed Jun 01 00:16:29 2016 +0200
@@ -3,7 +3,6 @@
 use strict;
 use warnings;
 use feature qw(say switch);
-use base 'Exporter';
 use if $ENV{DEBUG} => 'Smart::Comments';
 use Carp;
 
@@ -12,7 +11,6 @@
 use File::Temp;
 
 our $VERSION = '0.1';
-our @EXPORT_OK = qw(dig_tlsa);
 
 #@TODO use only fh of tempfile instead of filename
 my $tempfile = File::Temp->new(
@@ -31,7 +29,7 @@
 
 sub dig_tlsa {
   #@TODO
-  #dig tlsa _443._tcp.torproject.org +short 
+  #dig tlsa _443._tcp.torproject.org +short
   #wildcard.torproject.org.
   #3 1 1 578582E6B4569A4627AEF5DFE876EEC0539388E605DB170217838B10 D2A58DA5
   # until it's fixed test 7 returns ok on test on crit tlsa status
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/t/00-basic.t	Wed Jun 01 00:16:29 2016 +0200
@@ -0,0 +1,24 @@
+use Test::More qw(no_plan);
+use Test::Exception;
+
+use_ok 'Nagios::Check::DNS::check_tlsa_record';
+can_ok 'Nagios::Check::DNS::check_tlsa_record', qw(dig_tlsa);
+
+# The above package doesn't use the Exporter currently, for shortcut
+# reasons we import the relevant subs into *this* module
+*dig_tlsa = \&Nagios::Check::DNS::check_tlsa_record::dig_tlsa;
+
+# API conformance
+subtest 'API' => sub {
+    can_ok 'Nagios::Check::DNS::check_tlsa_record', qw(dig_tlsa);
+    dies_ok { dig_tlsa('example.org') } 'API: dig_tlsa() missing port';
+};
+
+# get and compare the TLSA records via dig_tlsa with `dig …`
+subtest 'Data' => sub {
+    foreach (['ssl.schlittermann.de' => 443], ['mx1.mailbox.org.de' => 25],) {
+        my ($domain, $port) = @$_;
+        is dig_tlsa($domain, $port),
+          `dig +short tlsa _$port._tcp.$domain` => "TLSA $domain:$port";
+    }
+};