Fixed for new_version_pg, plus a test for it.
authorGreg Sabino Mullane <[email protected]>
Thu, 23 Apr 2009 19:30:34 +0000 (15:30 -0400)
committerGreg Sabino Mullane <[email protected]>
Thu, 23 Apr 2009 19:30:34 +0000 (15:30 -0400)
check_postgres.pl
t/02_new_version_pg.t [new file with mode: 0644]

index 235f42113f7e292e74e006f278c54fcf6b8797e0..173ddad24d939aefd7c2f8cc72990908a33c87aa 100755 (executable)
@@ -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 (file)
index 0000000..0199bd9
--- /dev/null
@@ -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;