[check_postgres] [commit] Fixed for new_version_pg, plus a test for it.

check_postgres at bucardo.org check_postgres at bucardo.org
Thu Apr 23 19:30:46 UTC 2009


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

Fixed for new_version_pg, plus a test for it.

---
 check_postgres.pl     |   18 ++++++++++--------
 t/02_new_version_pg.t |   42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 8 deletions(-)

diff --git a/check_postgres.pl b/check_postgres.pl
index 235f421..173ddad 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -147,8 +147,8 @@ our %msg = (
 	'new-pg-badver'      => q{Could not determine the Postgres revision (version was $1)},
 	'new-pg-badver2'     => q{Could not find revision information for Postgres version $1},
 	'new-pg-big'         => q{Please upgrade to version $1 of Postgres. You are running $2},
-	'new-pg-small'       => q{The latest version of Postgres is $1, but you are runnning $2?},
-	'new-pg-match'       => q{Postgres is at the latest revsion ($1)},
+	'new-pg-small'       => q{The latest version of Postgres is $1, but you are running $2?},
+	'new-pg-match'       => q{Postgres is at the latest revision ($1)},
 	'no-match-db'        => q{No matching databases found due to exclusion/inclusion options},
 	'no-match-fs'        => q{No matching file systems found due to exclusion/inclusion options},
 	'no-match-rel'       => q{No matching relations found due to exclusion/inclusion options},
@@ -4488,14 +4488,16 @@ sub check_new_version_pg {
 		}
 		my $newrev = $newver{$ver};
 		if ($newrev > $rev) {
-			printf "WARNING: %s\n", msg('new-pg-big', "$ver.$newrev", $currver);
-			exit 1;
+			my $msg = sprintf "WARNING: %s\n", msg('new-pg-big', "$ver.$newrev", $currver);
+			add_warning $msg;
+		}
+		elsif ($newrev < $rev) {
+			my $msg = sprintf "WARNING: %s\n", msg('new-pg-small', "$ver.$newrev", $currver);
+			add_critical $msg;
 		}
-		if ($newrev < $rev) {
-			printf "WARNING: %s\n", msg('new-pg-small', "$ver.$newrev", $currver);
-			exit 1;
+		else {
+			add_ok msg('new-pg-match', $currver);
 		}
-		add_ok msg('new-pg-match', $currver);
 	}
 
 	return;
diff --git a/t/02_new_version_pg.t b/t/02_new_version_pg.t
new file mode 100644
index 0000000..0199bd9
--- /dev/null
+++ b/t/02_new_version_pg.t
@@ -0,0 +1,42 @@
+#!perl
+
+## Test the "new_version_pg" action
+
+use strict;
+use warnings;
+use Data::Dumper;
+use Test::More tests => 5;
+use lib 't','.';
+use CP_Testing;
+
+use vars qw/$dbh $SQL $t/;
+
+my $cp = CP_Testing->new( {default_action => 'new_version_pg'} );
+
+$dbh = $cp->test_database_handle();
+
+my $S = q{Action 'version'};
+my $label = 'POSTGRES_NEW_VERSION_PG';
+
+$t=qq{$S fails when called with an invalid option};
+like ($cp->run('foobar=12'), qr{^\s*Usage:}, $t);
+
+$t=qq{$S returns unknown for bizarre Postgres version};
+$cp->fake_version('7.8.12');
+like ($cp->run(''), qr{$label UNKNOWN:.+Could not find revision information for Postgres version 7.8}, $t);
+
+$t=qq{$S returns warning for outdated Postgres revision};
+$cp->fake_version('8.3.0');
+like ($cp->run(''), qr{$label WARNING:.+Please upgrade to version 8.3.\d+ of Postgres}, $t);
+
+$t=qq{$S returns warning for non-existent future version of Postgres};
+$cp->fake_version('8.2.999');
+like ($cp->run(''), qr{$label CRITICAL:.+The latest version of Postgres is 8.2.\d+, but you are running}, $t);
+
+$t=qq{$S returns okay for matching version};
+$cp->run('') =~ /Postgres is (\S+)/ or BAIL_OUT "Could not determine version!\n";
+my $currver = $1;
+$cp->fake_version($currver);
+like ($cp->run(''), qr{$label OK:.+Postgres is at the latest revision}, $t);
+
+exit;
-- 
1.6.0.5



More information about the Check_postgres mailing list