diff --git a/src/warden-server/bin/wardenWatchdog.t b/src/warden-server/bin/wardenWatchdog.t new file mode 100644 index 0000000000000000000000000000000000000000..3ab8d875e8a9a4b02dc6c66bbff7d93dfad9390e --- /dev/null +++ b/src/warden-server/bin/wardenWatchdog.t @@ -0,0 +1,71 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use DBI; +use DBD::mysql; +use Data::Dumper; + +use Test::More tests => 7; +use Test::MockModule; +use Test::Exception; + +use lib '..'; +use wardenWatchdog; + + +my (%input, $retCode, $result); + +print "== wardenWatchdog::send_report ==\n"; + +*wardenWatchdog::sendmail_wrapper = sub {print "sendmailWrapper is set to broken!\nSending of emails will fail\n"; return 0;}; + +%input = (contact => 'test@test.receiver.cz', domain => 'test.domain.cz', text => 'TEST MSG!'); +($retCode, $result) = wardenWatchdog::send_report(\%input); +ok ($retCode == 0, 'Broken sendmail'); + +*wardenWatchdog::sendmail_wrapper = sub {print "sendmailWrapper is OFF!\nSending of emails is blocked\n"; return 1;}; + +%input = (contact => '', domain => 'test.domain.cz', text => 'TEST MSG!'); +($retCode, $result) = wardenWatchdog::send_report(\%input); +ok ($retCode == 0, 'No contact'); + +%input = (contact => 'test@test.receiver.cz', domain => '', text => 'TEST MSG!'); +($retCode, $result) = wardenWatchdog::send_report(\%input); +ok ($retCode == 0, 'No domain'); + +%input = (contact => '', domain => 'test.domain.cz', text => ''); +($retCode, $result) = wardenWatchdog::send_report(\%input); +ok ($retCode == 0, 'No text'); + +%input = (contact => 'test@test.receiver.cz', domain => 'test.domain.cz', text => 'TEST MSG!'); +($retCode, $result) = wardenWatchdog::send_report(\%input); +ok ($retCode == 1, 'All OK'); + +print "== wardenWatchdog::connect_to_DB ==\n"; +my $dbh; +($retCode, $result) = connect_to_DB(\$dbh); +ok ($retCode == 1, 'Connected to the DB'); + +# FAILED DB CONNECTION + +print "== wardenWatchdog::update_procedures ==\n"; + +# CORRECT RUN OF update_procedures + +print "== wardenWatchdog::send_query ==\n"; + +# RUN WITH BROKEN DB CONNECTION + +# RUN WITH NO query + +# CORRECT RUN OF send_query + +print "== wardenWatchdog::run ==\n"; + +# RUN WITHOUT domain + +# RUN WITHOUT period + +# CORRECT RUN OF send_query