1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#!perl
## Test the "connection" action
use 5.008;
use strict;
use warnings;
use Data::Dumper;
use Test::More tests => 14;
use lib 't','.';
use CP_Testing;
use vars qw/$dbh $dbh2 $SQL $version $host $t $result/;
my $cp = CP_Testing->new({default_action => 'connection'});
$dbh = $cp->test_database_handle();
## Check our version number
$SQL = 'SELECT version()';
($version) = $dbh->selectall_arrayref($SQL)->[0][0] =~ /PostgreSQL (\S+)/o;
$result = $cp->run();
my $S = q{Action 'connection'};
my $label = 'POSTGRES_CONNECTION';
$t=qq{$S returned expected text and OK value};
like ($result, qr{^$label OK:}, $t);
$t=qq{$S returned correct performance data};
like ($result, qr{ \| time=\d\.\d\ds\s$}, $t);
$t=qq{$S returned correct version};
like ($result, qr{ \| time=\d\.\d\ds\s$}, $t);
$t=qq{$S fails when called with an invalid option};
like ($cp->run('foobar=12'), qr{Usage:}, $t);
$t=qq{$S fails when called with an invalid warning option};
like ($cp->run('-w felz'), qr{^ERROR: No warning}, $t);
like ($cp->run('-w " 12345"'), qr{^ERROR: No warning}, $t);
like ($cp->run('-w 23%%'), qr{^ERROR: No warning}, $t);
$t=qq{$S fails when called with an invalid critical option};
like ($cp->run('-c felz'), qr{^ERROR: No warning or critical}, $t);
like ($cp->run('-c " 12345"'), qr{^ERROR: No warning or critical}, $t);
like ($cp->run('-c 23%%'), qr{^ERROR: No warning or critical}, $t);
$t=qq{$S returns correct MRTG output when rows found};
is ($cp->run('--output=MRTG'), qq{1\n0\n\n\n}, $t);
$cp->fake_version('ABC');
$t=qq{$S fails if there's a fake version function};
like ($cp->run(), qr{^$label UNKNOWN:.*Invalid query}, $t);
$cp->fake_version_timeout();
$t=qq{$S fails on timeout};
like ($cp->run('--timeout 1'), qr{^$label CRITICAL:.*(Timed out|statement timeout)}, $t);
$cp->reset_path();
$t=qq{$S fails on nonexisting socket};
like ($cp->run('--port=1023'), qr{^$label CRITICAL:.*(could not connect to server|connection to server.*failed)}, $t);
exit;
|