Forked from
713 / Warden / Warden - archive
482 commits behind the upstream repository.
-
Tomáš Plesník authoredTomáš Plesník authored
WardenWatchdog.t 2.36 KiB
#!/usr/bin/perl
#
# WardenWatchdog.t
#
# Copyright (C) 2011-2014 Cesnet z.s.p.o
#
# Use of this source is governed by a BSD-style license, see LICENSE file.
use strict;
use warnings;
use DBI;
use DBD::mysql;
use Data::Dumper;
use Test::More tests => 8;
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, %db_conf);
%db_conf = (platform => 'mysql', name => 'a', hostname => 'a', user => 'a', passwd => 'a');
# FAILED DB CONNECTION
($retCode, $result) = WardenWatchdog::connect_to_DB(\%db_conf, \$dbh);
ok ($retCode == 0, 'Can\'t connect to the DB - wrong credentials');
#print "== WardenWatchdog::update_procedures ==\n";
# CORRECT RUN OF update_procedures
#print "== WardenWatchdog::send_query ==\n";
# RUN WITH BROKEN DB CONNECTION
# RUN WITH NO query