[check_postgres] [commit] Many test cleanups and changes.

check_postgres at bucardo.org check_postgres at bucardo.org
Mon Apr 27 23:30:42 UTC 2009


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

Many test cleanups and changes.

---
 check_postgres.pl        |    4 ++--
 check_postgres.pl.asc    |    6 +++---
 t/02_checkpoint.t        |    2 +-
 t/02_database_size.t     |    2 ++
 t/02_disabled_triggers.t |   11 +++++++----
 t/02_disk_space.t        |    3 +--
 t/02_fsm_pages.t         |    1 +
 t/02_fsm_relations.t     |    1 +
 t/02_relation_size.t     |    6 +-----
 t/02_sequence.t          |    2 +-
 t/02_txn_wraparound.t    |    3 +--
 t/02_version.t           |    2 +-
 t/99_spellcheck.t        |    1 +
 t/CP_Testing.pm          |   13 +++++++++++++
 14 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/check_postgres.pl b/check_postgres.pl
index 06a934d..737fe4b 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -4356,7 +4356,7 @@ sub check_checkpoint {
 	$db->{host} = '<none>';
 
 	## Run pg_controldata, grab the time
-	my $pgc 
+	my $pgc
 		= $ENV{PGCONTROLDATA} ? $ENV{PGCONTROLDATA}
 		: $ENV{PGBINDIR}      ? "$ENV{PGBINDIR}/pg_controldata"
 		:                       'pg_controldata';
@@ -5112,7 +5112,7 @@ the C<--datadir> argument. It returns the number of seconds since the last check
 was run, as determined by parsing the call to C<pg_controldata>. Because of this, the 
 pg_controldata executable must be available in the current path. Alternatively, you can 
 set the environment variable C<PGCONTROLDATA> to the exact location of the pg_controldata 
-excutable, or you can specify C<PGBINDIR> as the directory that it lives in.
+executable, or you can specify C<PGBINDIR> as the directory that it lives in.
 
 At least one warning or critical argument must be set.
 
diff --git a/check_postgres.pl.asc b/check_postgres.pl.asc
index 4579e89..9ebb368 100644
--- a/check_postgres.pl.asc
+++ b/check_postgres.pl.asc
@@ -1,6 +1,6 @@
 -----BEGIN PGP SIGNATURE-----
 
-iEYEABEDAAYFAkmjWs8ACgkQvJuQZxSWSsiRPwCfZc7WWECYzxNCM2TvCEVUWMkA
-ZZQAoL+0pEfXuu4MCkNJWm+dq7g6eAYU
-=L1hr
+iEYEABEDAAYFAkn2POAACgkQvJuQZxSWSsjFFwCeNLfR1C0kd4f2YKTnlvaapm3e
+6IsAoJQmPHbo18rsn8fkXSMz5wfMTHla
+=ZZQS
 -----END PGP SIGNATURE-----
diff --git a/t/02_checkpoint.t b/t/02_checkpoint.t
index 7021a20..b345178 100644
--- a/t/02_checkpoint.t
+++ b/t/02_checkpoint.t
@@ -39,7 +39,7 @@ like ($cp->run('-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("-c 10 --datadir=$host"), qr{ERROR: Call to pg_controldata}, $t);
+like ($cp->run("-c 10 --datadir=$host"), qr{ERROR:.+could not read the given data directory}, $t);
 
 $t=qq{$S works when called for a recent checkpoint};
 my $dbh = $cp->get_dbh();
diff --git a/t/02_database_size.t b/t/02_database_size.t
index f13b16e..f84de05 100644
--- a/t/02_database_size.t
+++ b/t/02_database_size.t
@@ -20,6 +20,8 @@ my $S = q{Action 'database_size'};
 $t=qq{$S returned expected text when no warning/critical size is provided};
 like ($cp->run(''), qr{^ERROR: Must provide a warning and/or critical size}, $t);
 
+$cp->drop_all_tables();
+
 for my $type (qw/b bs k kb kbs m mb mbs g gb gbs t tb tbs p pb pbs e eb ebs z zb zbs/) {
 	my $opt = "-w 9999999$type";
 	$t=qq{$S returned expected text when warning level is specified in $type};
diff --git a/t/02_disabled_triggers.t b/t/02_disabled_triggers.t
index 23507e2..5ed391b 100644
--- a/t/02_disabled_triggers.t
+++ b/t/02_disabled_triggers.t
@@ -50,14 +50,17 @@ for (-1, 0, 'a') {
     like ($cp->run(qq{-c $_}), qr/ERROR: Invalid argument.*must be a positive integer/, $t . " ($_)");
 }
 
-# Set up a test table with two triggers.
-$dbh->do(qq{CREATE TABLE "$testtbl" (a integer)});
-END {
+sub cleanup {
     $dbh->rollback;
-    $dbh->do(qq{DROP TABLE IF EXISTS "$testtbl"});
+	local $dbh->{Warn} = 0;
+	$dbh->do(qq{DROP TABLE IF EXISTS "$testtbl"});
     $dbh->do(qq{DROP FUNCTION IF EXISTS "${testtrig_prefix}func"()});
     $dbh->commit;
 }
+END { cleanup(); }
+# Set up a test table with two triggers.
+cleanup();
+$dbh->do(qq{CREATE TABLE "$testtbl" (a integer)});
 
 $dbh->do(qq{CREATE FUNCTION "${testtrig_prefix}func"() RETURNS TRIGGER AS 'BEGIN return null; END' LANGUAGE plpgsql});
 
diff --git a/t/02_disk_space.t b/t/02_disk_space.t
index 6eeff2c..40dbd60 100644
--- a/t/02_disk_space.t
+++ b/t/02_disk_space.t
@@ -6,8 +6,7 @@ use strict;
 use warnings;
 use Data::Dumper;
 use DBI;
-use Test::More qw(no_plan);
-END { diag "Don't forget to make a plan!" }
+use Test::More tests => 7;
 use lib 't','.';
 use CP_Testing;
 
diff --git a/t/02_fsm_pages.t b/t/02_fsm_pages.t
index 8ad70ca..105be21 100644
--- a/t/02_fsm_pages.t
+++ b/t/02_fsm_pages.t
@@ -34,6 +34,7 @@ my $schema = $cp->get_fake_schema();
 	local $dbh->{Warn};
 	$dbh->do("DROP TABLE IF EXISTS $schema.pg_freespacemap_pages");
 	$dbh->do("DROP TABLE IF EXISTS $schema.pg_freespacemap_relations");
+	$dbh->do('DROP FUNCTION IF EXISTS public.version()');
 }
 $dbh->do(qq{
 CREATE TABLE $schema.pg_freespacemap_pages (
diff --git a/t/02_fsm_relations.t b/t/02_fsm_relations.t
index c0afe37..9f0e66a 100644
--- a/t/02_fsm_relations.t
+++ b/t/02_fsm_relations.t
@@ -34,6 +34,7 @@ my $schema = $cp->get_fake_schema();
 	local $dbh->{Warn};
 	$dbh->do("DROP TABLE IF EXISTS $schema.pg_freespacemap_pages");
 	$dbh->do("DROP TABLE IF EXISTS $schema.pg_freespacemap_relations");
+	$dbh->do('DROP FUNCTION IF EXISTS public.version()');
 }
 $dbh->do(qq{
 CREATE TABLE $schema.pg_freespacemap_pages (
diff --git a/t/02_relation_size.t b/t/02_relation_size.t
index acc3c10..f4289e4 100644
--- a/t/02_relation_size.t
+++ b/t/02_relation_size.t
@@ -53,11 +53,7 @@ $t = qq{$S detects no matching tables due to unknown user};
 like ($cp->run(q{-w 1 --includeuser foo}), qr{$label OK:.*No matching entries found due to user exclusion/inclusion options}, $t);
 
 ## We need to remove all tables to make this work correctly
-local $dbh->{Warn} = 0;
-my @info = $dbh->tables('','public','','TABLE');
-for my $tab (@info) {
-	$dbh->do("DROP TABLE $tab CASCADE");
-}
+$cp->drop_all_tables();
 $dbh->do(qq{CREATE TABLE $testtbl (a integer)});
 
 $dbh->commit;
diff --git a/t/02_sequence.t b/t/02_sequence.t
index 2517e3f..a67e095 100644
--- a/t/02_sequence.t
+++ b/t/02_sequence.t
@@ -41,7 +41,7 @@ $dbh->do("CREATE TEMP SEQUENCE ${seqname}2");
 $dbh->commit();
 
 $t=qq{$S fails when sequence not readable};
-like ($cp->run(''), qr{ERROR: Could not determine}, $t);
+like ($cp->run(''), qr{ERROR:\s*(?:Could not determine|cannot access temporary)}, $t);
 
 $dbh->do("CREATE SEQUENCE $seqname");
 $dbh->commit();
diff --git a/t/02_txn_wraparound.t b/t/02_txn_wraparound.t
index a93c786..130dd5a 100644
--- a/t/02_txn_wraparound.t
+++ b/t/02_txn_wraparound.t
@@ -54,7 +54,7 @@ for (-1, 0, 'a') {
 }
 
 $t = qq{$S sees impending wrap-around};
-like ($cp->run('-c ' . ($txn_measure / 2)), qr/$label CRITICAL/, $t);
+like ($cp->run('-c ' . int ($txn_measure / 2)), qr/$label CRITICAL/, $t);
 
 $t = qq{$S sees no impending wrap-around};
 like ($cp->run('-v -c ' . ($txn_measure * 2)), qr/$label OK/, $t);
@@ -62,4 +62,3 @@ like ($cp->run('-v -c ' . ($txn_measure * 2)), qr/$label OK/, $t);
 $t .= ' (mrtg)';
 like ($cp->run('-c 100000 --output=mrtg'), qr{\d+\n0\n\nDB: ardala}, $t);
 
-
diff --git a/t/02_version.t b/t/02_version.t
index 143cf90..e37408b 100644
--- a/t/02_version.t
+++ b/t/02_version.t
@@ -108,7 +108,7 @@ is ($cp->run('--output=MRTG --mrtg=7.8.12'), qq{1\n0\n\n7.8.12\n}, $t);
 
 local $dbh->{Warn} = 0;
 $dbh->do('DROP SCHEMA cptest CASCADE');
-$dbh->do('DROP FUNCTION public.version()');
+$dbh->do('DROP FUNCTION IF EXISTS public.version()');
 $cp->reset_path();
 
 exit;
diff --git a/t/99_spellcheck.t b/t/99_spellcheck.t
index a66a5e0..147e848 100644
--- a/t/99_spellcheck.t
+++ b/t/99_spellcheck.t
@@ -140,6 +140,7 @@ bucardo
 checksum
 cp
 dbh
+dbstats
 DBI
 DSN
 fsm
diff --git a/t/CP_Testing.pm b/t/CP_Testing.pm
index f052816..c76df0f 100644
--- a/t/CP_Testing.pm
+++ b/t/CP_Testing.pm
@@ -491,4 +491,17 @@ sub reset_path {
 
 } ## end of reset_path
 
+sub drop_all_tables {
+
+	my $self = shift;
+	my $dbh = $self->{dbh} || die;
+	local $dbh->{Warn} = 0;
+	my @info = $dbh->tables('','public','','TABLE');
+	for my $tab (@info) {
+		$dbh->do("DROP TABLE $tab CASCADE");
+	}
+	$dbh->commit();
+
+} ## end of drop_all_tables
+
 1;
-- 
1.6.0.5



More information about the Check_postgres mailing list