[check_postgres] [commit] Add new test, rename and cleanup others.

check_postgres at bucardo.org check_postgres at bucardo.org
Wed Feb 25 22:13:28 UTC 2009


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

Add new test, rename and cleanup others.

---
 t/{00basic.t => 00_basic.t}                 |    0
 t/{00-signature.t => 00_signature.t}        |    0
 t/{02backends.t => 02_backends.t}           |   68 ++++++++++++++-------------
 t/02_checkpoint.t                           |   69 +++++++++++++++++++++++++++
 t/{02replicate_row.t => 02_replicate_row.t} |    0
 5 files changed, 104 insertions(+), 33 deletions(-)

diff --git a/t/00basic.t b/t/00_basic.t
similarity index 100%
rename from t/00basic.t
rename to t/00_basic.t
diff --git a/t/00-signature.t b/t/00_signature.t
similarity index 100%
rename from t/00-signature.t
rename to t/00_signature.t
diff --git a/t/02backends.t b/t/02_backends.t
similarity index 68%
rename from t/02backends.t
rename to t/02_backends.t
index 665c490..f443d4d 100644
--- a/t/02backends.t
+++ b/t/02_backends.t
@@ -29,48 +29,50 @@ $host = $cp->get_host();
 
 $result = $cp->run('backends');
 
-$t=q{Action 'backends' returned expected text and OK value};
+my $S = q{Action 'backends'};
+
+$t=qq{$S returned expected text and OK value};
 like ($result, qr{^POSTGRES_BACKENDS OK:}, $t);
 
-$t=q{Action 'backends' returned correct host name};
+$t=qq{$S returned correct host name};
 like ($result, qr{^POSTGRES_BACKENDS OK: \(host:$host\)}, $t);
 
-$t=q{Action 'backends' returned correct connection count};
+$t=qq{$S returned correct connection count};
 like ($result, qr{^POSTGRES_BACKENDS OK: \(host:$host\) 2 of 10 connections}, $t);
 
-$t=q{Action 'backends' returned correct percentage};
+$t=qq{$S returned correct percentage};
 like ($result, qr{^POSTGRES_BACKENDS OK: \(host:$host\) 2 of 10 connections \(20%\)}, $t);
 
-$t=q{Action 'backends' returned correct performance data};
-like ($result, qr{ \| time=(\d\.\d\d)  beedeebeedee=0 postgres=2 template0=0 template1=0\s$}, $t);
+$t=qq{$S returned correct performance data};
+like ($result, qr{ \| time=(\d\.\d\d)  ardala=0 beedeebeedee=0 postgres=2 template0=0 template1=0\s$}, $t);
 
-$t=q{Action 'backends' fails when called with an invalid option};
+$t=qq{$S fails when called with an invalid option};
 like ($cp->run('backends', 'foobar=12'), qr{^\s*Usage:}, $t);
 
-$t=q{Action 'backends' fails when called with an invalid warning option};
+$t=qq{$S fails when called with an invalid warning option};
 like ($cp->run('backends', '-w felz'),     qr{^ERROR: Warning}, $t);
 like ($cp->run('backends', '-w " 12345"'), qr{^ERROR: Warning}, $t);
 like ($cp->run('backends', '-w 23%%'),     qr{^ERROR: Warning}, $t);
 
-$t=q{Action 'backends' fails when called with an invalid critical option};
+$t=qq{$S fails when called with an invalid critical option};
 like ($cp->run('backends', '-c felz'),     qr{^ERROR: Critical}, $t);
 like ($cp->run('backends', '-c " 12345"'), qr{^ERROR: Critical}, $t);
 like ($cp->run('backends', '-c 23%%'),     qr{^ERROR: Critical}, $t);
 
-$t=q{Action 'backends' fails when the warning option is greater than the critical option};
+$t=qq{$S fails when the warning option is greater than the critical option};
 like ($cp->run('backends', '-w 20 -c 10'),   qr{^ERROR: The 'warning'.+greater}, $t);
 like ($cp->run('backends', '-w 20% -c 10%'), qr{^ERROR: The 'warning'.+greater}, $t);
 
-$t=q{Action 'backends' fails when the warning option is less than the critical option};
+$t=qq{$S fails when the warning option is less than the critical option};
 like ($cp->run('backends', '-w -10 -c -20'), qr{^ERROR: The 'warning'.+less}, $t);
 
-$t=q{Action 'backends' fails when the warning option is a negative percent};
+$t=qq{$S fails when the warning option is a negative percent};
 like ($cp->run('backends', '-w -10%'), qr{^ERROR: Cannot specify a negative percent}, $t);
 
-$t=q{Action 'backends' fails when the critical option is a negative percent};
+$t=qq{$S fails when the critical option is a negative percent};
 like ($cp->run('backends', '-c -10%'), qr{^ERROR: Cannot specify a negative percent}, $t);
 
-$t=q{Action 'backends' with the 'noidle' option returns expected result};
+$t=qq{$S with the 'noidle' option returns expected result};
 like ($cp->run('backends', '-noidle'), qr{^POSTGRES_BACKENDS OK:.+ 2 of 10 connections}, $t);
 $dbh2 = $cp->get_fresh_dbh();
 $dbh2->do('SELECT 123');
@@ -78,77 +80,77 @@ like ($cp->run('backends', '-noidle'), qr{^POSTGRES_BACKENDS OK:.+ 3 of 10 conne
 $dbh2->commit();
 like ($cp->run('backends', '-noidle'), qr{^POSTGRES_BACKENDS OK:.+ 2 of 10 connections}, $t);
 
-$t=q{Action 'backends' has critical option trump the warning option};
+$t=qq{$S has critical option trump the warning option};
 like ($cp->run('backends', '-w 1 -c 1'), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
 like ($cp->run('backends', '--critical=1 --warning=0'), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
 
-$t=q{Action 'backends' works with warning option as an absolute number};
+$t=qq{$S works with warning option as an absolute number};
 like ($cp->run('backends', '-w 2'), qr{^POSTGRES_BACKENDS WARNING}, $t);
 like ($cp->run('backends', '-w 3'), qr{^POSTGRES_BACKENDS WARNING}, $t);
 like ($cp->run('backends', '-w 4'), qr{^POSTGRES_BACKENDS OK}, $t);
 
-$t=q{Action 'backends' works with warning option as an percentage};
+$t=qq{$S works with warning option as an percentage};
 like ($cp->run('backends', '-w 20%'), qr{^POSTGRES_BACKENDS WARNING}, $t);
 like ($cp->run('backends', '-w 30%'), qr{^POSTGRES_BACKENDS WARNING}, $t);
 like ($cp->run('backends', '-w 40%'), qr{^POSTGRES_BACKENDS OK}, $t);
 
-$t=q{Action 'backends' works with warning option as a negative number};
+$t=qq{$S works with warning option as a negative number};
 like ($cp->run('backends', '-w -6'), qr{^POSTGRES_BACKENDS WARNING}, $t);
 like ($cp->run('backends', '-w -7'), qr{^POSTGRES_BACKENDS WARNING}, $t);
 like ($cp->run('backends', '-w -8'), qr{^POSTGRES_BACKENDS OK}, $t);
 
-$t=q{Action 'backends' works with critical option as an absolute number};
+$t=qq{$S works with critical option as an absolute number};
 like ($cp->run('backends', '-c 2'), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
 like ($cp->run('backends', '-c 3'), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
 like ($cp->run('backends', '-c 4'), qr{^POSTGRES_BACKENDS OK}, $t);
 
-$t=q{Action 'backends' works with critical option as an percentage};
+$t=qq{$S works with critical option as an percentage};
 like ($cp->run('backends', '-c 20%'), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
 like ($cp->run('backends', '-c 30%'), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
 like ($cp->run('backends', '-c 40%'), qr{^POSTGRES_BACKENDS OK}, $t);
 
-$t=q{Action 'backends' works with critical option as a negative number};
+$t=qq{$S works with critical option as a negative number};
 like ($cp->run('backends', '-c -6'), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
 like ($cp->run('backends', '-c -7'), qr{^POSTGRES_BACKENDS CRITICAL}, $t);
 like ($cp->run('backends', '-c -8'), qr{^POSTGRES_BACKENDS OK}, $t);
 
-$t=q{Action 'backends' works when no items caught by pg_stat_activity};
+$t=qq{$S works when no items caught by pg_stat_activity};
 ## This is tricky to test properly.
 $cp->create_fake_pg_table('pg_stat_activity');
 like ($cp->run('backends'), qr{^POSTGRES_BACKENDS OK: .+No connections}, $t);
 
-$t=q{Action 'backends' returns correct MRTG output when no rows};
+$t=qq{$S returns correct MRTG output when no rows};
 is ($cp->run('backends', '--output=MRTG'), qq{0\n0\n\nDB=postgres Max connections=10\n}, $t);
 
 $cp->remove_fake_pg_table('pg_stat_activity');
 
-$t=q{Action 'backends' fails as expected when max_connections cannot be determined};
+$t=qq{$S fails as expected when max_connections cannot be determined};
 $cp->create_fake_pg_table('pg_settings');
 like ($cp->run('backends'), qr{^POSTGRES_BACKENDS UNKNOWN: .+max_connections}, $t);
 $cp->remove_fake_pg_table('pg_settings');
 
-$t=q{Action 'backends' returns correct MRTG output when rows found};
+$t=qq{$S returns correct MRTG output when rows found};
 is ($cp->run('backends', '--output=MRTG'), qq{3\n0\n\nDB=postgres Max connections=10\n}, $t);
 
-$t=q{Action 'backends' works when include forces no matches};
+$t=qq{$S works when include forces no matches};
 like ($cp->run('backends', '--include=foobar'), qr{POSTGRES_BACKENDS OK: .+No connections}, $t);
 
-$t=q{Action 'backends' works when include has valid database};
+$t=qq{$S works when include has valid database};
 like ($cp->run('backends', '--include=postgres'), qr{POSTGRES_BACKENDS OK: .+3 of 10}, $t);
 
-$t=q{Action 'backends' works when exclude forces no matches};
+$t=qq{$S works when exclude forces no matches};
 like ($cp->run('backends', '--exclude=postgres'), qr{POSTGRES_BACKENDS OK: .+No connections}, $t);
 
-$t=q{Action 'backends' works when exclude excludes nothing};
+$t=qq{$S works when exclude excludes nothing};
 like ($cp->run('backends', '--exclude=foobar'), qr{POSTGRES_BACKENDS OK: .+3 of 10}, $t);
 
-$t=q{Action 'backends' works when include and exclude make a match};
+$t=qq{$S works when include and exclude make a match};
 like ($cp->run('backends', '--exclude=postgres --include=postgres'), qr{POSTGRES_BACKENDS OK: .+3 of 10}, $t);
 
-$t=q{Action 'backends' works when include and exclude make a match};
+$t=qq{$S works when include and exclude make a match};
 like ($cp->run('backends', '--include=postgres --exclude=postgres'), qr{POSTGRES_BACKENDS OK: .+3 of 10}, $t);
 
-$t=q{Action 'backends' returned correct performance data with include};
-like ($cp->run('backends', '--include=postgres'), qr{ \| time=(\d\.\d\d)  beedeebeedee=0 postgres=3}, $t);
+$t=qq{$S returned correct performance data with include};
+like ($cp->run('backends', '--include=postgres'), qr{ \| time=(\d\.\d\d)  ardala=0 beedeebeedee=0 postgres=3}, $t);
 
 exit;
diff --git a/t/02_checkpoint.t b/t/02_checkpoint.t
new file mode 100644
index 0000000..b40fd56
--- /dev/null
+++ b/t/02_checkpoint.t
@@ -0,0 +1,69 @@
+#!perl
+
+## Test the "checkpoint" action
+
+use strict;
+use warnings;
+use Data::Dumper;
+use DBI;
+use Cwd;
+use Test::More tests => 13;
+use lib 't','.';
+use CP_Testing;
+
+use vars qw/$dbh $dbh2 $SQL $count $host $t $result $info/;
+
+my $cp = CP_Testing->new();
+
+$dbh = $cp->test_database_handle();
+
+my $S = q{Action 'checkpoint'};
+
+$t=qq{$S fails when called with an invalid option};
+like ($cp->run('checkpoint', 'foobar=12'), qr{^\s*Usage:}, $t);
+
+$t=qq{$S fails when called without warning or critical};
+like ($cp->run('checkpoint', ''), qr{Must provide a warning and/or critical}, $t);
+
+$t=qq{$S fails when called with invalid warning option};
+like ($cp->run('checkpoint', '-w foo'), qr{ERROR: .+'warning'.+valid time}, $t);
+
+$t=qq{$S fails when called with invalid critical option};
+like ($cp->run('checkpoint', '-c foo'), qr{ERROR: .+'critical'.+valid time}, $t);
+
+$t=qq{$S fails when called without a datadir option and PGDATA is not set};
+delete $ENV{PGDATA};
+like ($cp->run('checkpoint', '-c 10'), qr{ERROR: Must supply a --datadir}, $t);
+
+$t=qq{$S fails when called with an invalid datadir option and PGDATA is not set};
+like ($cp->run('checkpoint', '-c 10 --datadir=foobar'), qr{ERROR: Invalid data_directory}, $t);
+
+my $host = $cp->get_host();
+$t=qq{$S fails when called against a non datadir datadir};
+like ($cp->run('checkpoint', "-c 10 --datadir=$host"), qr{ERROR: Call to pg_controldata}, $t);
+
+$t=qq{$S works when called for a recent checkpoint};
+my $dbh = $cp->get_dbh();
+$dbh->do('CHECKPOINT');
+$dbh->commit();
+$host =~ s/socket$//;
+like ($cp->run('checkpoint', "-w 20 --datadir=$host"), qr{POSTGRES_CHECKPOINT OK}, $t);
+
+$t=qq{$S returns a warning when checkpoint older than warning option};
+diag "Sleeping for a bit to age the checkpoint time...\n";
+sleep 2;
+like ($cp->run('checkpoint', "-w 1 --datadir=$host"), qr{WARNING:}, $t);
+
+$t=qq{$S returns a critical when checkpoint older than critical option};
+like ($cp->run('checkpoint', "-c 1 --datadir=$host"), qr{CRITICAL:}, $t);
+
+$t=qq{$S returns the correct number of seconds};
+like ($cp->run('checkpoint', "-c 1 --datadir=$host"), qr{was \d seconds ago}, $t);
+
+$t=qq{$S returns the expected output for MRTG};
+like ($cp->run('checkpoint', "-c 1 --output=MRTG --datadir=$host"), qr{^\d\n0\n\nLast checkpoint was \d seconds ago}, $t);
+
+$t=qq{$S returns the expected output for MRTG};
+like ($cp->run('checkpoint', "-c 199 --output=MRTG --datadir=$host"), qr{^\d\n0\n\nLast checkpoint was \d seconds ago}, $t);
+
+exit;
diff --git a/t/02replicate_row.t b/t/02_replicate_row.t
similarity index 100%
rename from t/02replicate_row.t
rename to t/02_replicate_row.t
-- 
1.6.0.5



More information about the Check_postgres mailing list