New 'listen' test from Jeff Boes.
authorGreg Sabino Mullane <[email protected]>
Fri, 10 Apr 2009 16:14:44 +0000 (12:14 -0400)
committerGreg Sabino Mullane <[email protected]>
Fri, 10 Apr 2009 16:14:44 +0000 (12:14 -0400)
Add new get_dbname method to CP_Testing.pm

t/02_listener.t [new file with mode: 0644]
t/CP_Testing.pm

diff --git a/t/02_listener.t b/t/02_listener.t
new file mode 100644 (file)
index 0000000..0edeb3a
--- /dev/null
@@ -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;
index ff0be5ad071992a3e78f2f665072dbcc6f4a295f..66004378b87d5277aa641e85f7880c8a8be3e115 100644 (file)
@@ -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;