From: Greg Sabino Mullane Date: Thu, 23 Apr 2009 19:30:34 +0000 (-0400) Subject: Fixed for new_version_pg, plus a test for it. X-Git-Tag: 2.9.0~91 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=7651d8150336f55c467a959d079f6d3c54b56ffd;p=check_postgres.git Fixed for new_version_pg, plus a test for it. --- diff --git a/check_postgres.pl b/check_postgres.pl index 235f42113..173ddad24 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 000000000..0199bd905 --- /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;