diff options
author | Jeff Boes | 2009-04-23 20:37:58 +0000 |
---|---|---|
committer | Jeff Boes | 2009-04-23 22:03:06 +0000 |
commit | 2b0cca8250536ac21c411bbf17648d9ede062b69 (patch) | |
tree | dadb09a26d04cf5193af654ec410294ffef8b074 | |
parent | 19acfdcd940028c4052f6d84dd33cd4d36c9597e (diff) |
Initial cut, 'disabled_triggers' tests
-rwxr-xr-x | check_postgres.pl | 8 | ||||
-rw-r--r-- | t/02_disabled_triggers.t | 75 | ||||
-rw-r--r-- | t/CP_Testing.pm | 1 |
3 files changed, 84 insertions, 0 deletions
diff --git a/check_postgres.pl b/check_postgres.pl index 99c406c9b..c01aa3383 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 000000000..1056a409c --- /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 a0bc04e28..bf8b1a631 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; |