[check_postgres] [commit] Initial cut, 'disabled_triggers' tests

check_postgres at bucardo.org check_postgres at bucardo.org
Fri Apr 24 16:19:58 UTC 2009


Committed by Jeff Boes <jeff at endpoint.com>

Initial cut, 'disabled_triggers' tests

---
 check_postgres.pl        |    8 +++++
 t/02_disabled_triggers.t |   75 ++++++++++++++++++++++++++++++++++++++++++++++
 t/CP_Testing.pm          |    1 +
 3 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/check_postgres.pl b/check_postgres.pl
index 99c406c..c01aa33 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -1928,10 +1928,18 @@ sub validate_range {
 		if (length $warning and $warning !~ /^\d+$/) {
 			ndie $type =~ /positive/ ? msg('range-int-pos', 'warning') : msg('range-int', 'warning');
 		}
+        elsif (length $warning && $type =~ /positive/ && $warning <= 0) {
+            ndie msg('range-int-pos', 'warning');
+        }
+
 		$critical =~ s/_//g;
 		if (length $critical and $critical !~ /^\d+$/) {
 			ndie $type =~ /positive/ ? msg('range-int-pos', 'critical') : msg('range-int', 'critical');
 		}
+        elsif (length $critical && $type =~ /positive/ && $critical <= 0) {
+            ndie msg('range-int-pos', 'critical');
+        }
+
 		if (length $warning and length $critical and $warning > $critical) {
 			return if $opt{reverse};
 			ndie msg('range-warnbig');
diff --git a/t/02_disabled_triggers.t b/t/02_disabled_triggers.t
new file mode 100644
index 0000000..1056a40
--- /dev/null
+++ b/t/02_disabled_triggers.t
@@ -0,0 +1,75 @@
+#!perl
+
+## Test the "disabled_triggers" action
+
+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 lib 't','.';
+use CP_Testing;
+
+use vars qw/$dbh $result $t $host $dbname $testtbl $testtrig_prefix/;
+
+$testtbl = 'test_disabled_triggers';
+$testtrig_prefix = 'test_disabled_triggers_';
+
+my $cp = CP_Testing->new( {default_action => 'disabled_triggers'} );
+
+$dbh = $cp->test_database_handle();
+$dbname = $cp->get_dbname;
+$host = $cp->get_host();
+my $label = 'POSTGRES_DISABLED_TRIGGERS';
+
+my $S = q{Action 'disabled_triggers'};
+
+$t = qq{$S self-identifies correctly};
+$result = $cp->run();
+like ($result, qr{^$label}, $t);
+
+$t = qq{$S identifies database};
+like ($result, qr{DB "$dbname"}, $t);
+
+$t = qq{$S identifies host};
+like ($result, qr{host:$host}, $t);
+
+$t = qq{$S accepts valid -w input};
+like ($cp->run(qq{-w 1}), qr/$label OK/, $t);
+
+$t = qq{$S flags invalid -w input};
+for (-1, 0, 'a') {
+    like ($cp->run(qq{-w $_}), qr/ERROR: Invalid argument.*must be a positive integer/, $t . " ($_)");
+}
+
+$t = qq{$S accepts valid -c input};
+like ($cp->run(qq{-c 1}), qr/$label OK/, $t);
+
+$t = qq{$S flags invalid -c input};
+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 {
+    $dbh->rollback;
+    $dbh->do(qq{DROP TABLE IF EXISTS "$testtbl"});
+    $dbh->do(qq{DROP FUNCTION IF EXISTS "${testtrig_prefix}func"()});
+    $dbh->commit;
+}
+
+$dbh->do(qq{CREATE FUNCTION "${testtrig_prefix}func"() RETURNS TRIGGER AS 'BEGIN return null; END' LANGUAGE plpgsql});
+
+$dbh->do(qq{CREATE TRIGGER "${testtrig_prefix}1" BEFORE INSERT ON "$testtbl" EXECUTE PROCEDURE ${testtrig_prefix}func()});
+
+$dbh->do(qq{CREATE TRIGGER "${testtrig_prefix}2" BEFORE INSERT ON "$testtbl" EXECUTE PROCEDURE ${testtrig_prefix}func()});
+
+$dbh->commit;
+
+$t = qq{$S counts disabled triggers};
+$dbh->do(qq{ALTER TABLE "$testtbl" DISABLE TRIGGER "${testtrig_prefix}1"});
+$dbh->do(qq{ALTER TABLE "$testtbl" DISABLE TRIGGER "${testtrig_prefix}2"});
+$dbh->commit;
+like ($cp->run(qq{-c 2}), qr/$label CRITICAL:.*?Disabled triggers: 2 /, $t);
diff --git a/t/CP_Testing.pm b/t/CP_Testing.pm
index a0bc04e..bf8b1a6 100644
--- a/t/CP_Testing.pm
+++ b/t/CP_Testing.pm
@@ -166,6 +166,7 @@ sub test_database_handle {
 	$dbh->do("ALTER USER readonly SET default_transaction_read_only = 1");
 	$dbh->do("CREATE DATABASE beedeebeedee");
 	$dbh->do("CREATE DATABASE ardala");
+    $dbh->do("CREATE LANGUAGE plpgsql");
 	$dbh->{AutoCommit} = 0;
 	$dbh->{RaiseError} = 1;
 
-- 
1.6.0.5



More information about the Check_postgres mailing list