[check_postgres] [commit] New 'listen' test from Jeff Boes.

check_postgres at bucardo.org check_postgres at bucardo.org
Fri Apr 10 16:15:17 UTC 2009


Committed by Greg Sabino Mullane <greg at endpoint.com>

New 'listen' test from Jeff Boes.
Add new get_dbname method to CP_Testing.pm

---
 t/02_listener.t |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 t/CP_Testing.pm |    5 +++++
 2 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/t/02_listener.t b/t/02_listener.t
new file mode 100644
index 0000000..0edeb3a
--- /dev/null
+++ b/t/02_listener.t
@@ -0,0 +1,53 @@
+#!perl
+
+## Test the "listener" action
+
+use strict;
+use warnings;
+use Data::Dumper;
+use DBI;
+use Test::More tests => 8;
+use lib 't','.';
+use CP_Testing;
+
+use vars qw/$dbh $result $t $host $dbname/;
+
+my $cp = CP_Testing->new( {default_action => 'listener'} );
+
+$dbh = $cp->test_database_handle();
+
+$host = $cp->get_host();
+$dbname = $cp->get_dbname();
+
+my $S = q{Action 'listener'};
+
+$result = $cp->run('-w foo');
+
+$t = qq{$S returned expected text and warning};
+like ($result, qr{^POSTGRES_LISTENER WARNING:}, $t);
+
+$t = qq{$S returned correct host name};
+like ($result, qr{\(host:$host\)}, $t);
+
+$t = qq{$S returned correct database name};
+like ($result, qr{DB "$dbname"}, $t);
+
+$t = qq{$S returned zero listeners};
+like ($result, qr{listeners found: 0\b}, $t);
+
+$dbh->do(q{LISTEN "FOO"}) or die $dbh->errstr;
+$dbh->commit;
+
+$t = qq{$S returned critical as expected<};
+like ($cp->run('-c nomatch'), qr{^POSTGRES_LISTENER CRITICAL}, $t);
+
+$t = qq{$S found one listener via explicit name};
+like ($cp->run('-w FOO'), qr{listeners found: 1\b}, $t);
+
+$t = qq{$S found one listener via regex};
+like ($cp->run('-w ~FO'), qr{listeners found: 1\b}, $t);
+
+$t = qq{$S returned correct information for MRTG output};
+is ($cp->run('-w ~FO --output=MRTG'), qq{1\n0\n\n\n}, $t);
+
+exit;
diff --git a/t/CP_Testing.pm b/t/CP_Testing.pm
index ff0be5a..6600437 100644
--- a/t/CP_Testing.pm
+++ b/t/CP_Testing.pm
@@ -205,6 +205,11 @@ sub get_host {
 	return $self->{dbhost};
 }
 
+sub get_dbname {
+	my $self = shift;
+	return $self->{dbname};
+}
+
 sub get_dbh {
 	my $self = shift;
 	return $self->{dbh} || die;
-- 
1.6.0.5



More information about the Check_postgres mailing list