diff options
author | Greg Sabino Mullane | 2009-03-24 16:19:45 +0000 |
---|---|---|
committer | Greg Sabino Mullane | 2009-03-24 16:19:45 +0000 |
commit | 4495f1f480a89219ec068143bc29f18f953a08ea (patch) | |
tree | eca49a8bbe7d07b25e0bd4c0b951890a2f067121 | |
parent | 78d84c861fb44ef48a55103f16c9f5ce4cfc7dc0 (diff) |
Add test for locks.
-rwxr-xr-x | check_postgres.pl | 1 | ||||
-rw-r--r-- | t/02_locks.t | 77 |
2 files changed, 78 insertions, 0 deletions
diff --git a/check_postgres.pl b/check_postgres.pl index 882b1760a..6ac0c8689 100755 --- a/check_postgres.pl +++ b/check_postgres.pl @@ -3185,6 +3185,7 @@ sub check_locks { if (!$gotone) { add_unknown msg('no-match-db'); + next; } ## If not specific errors, just use the total diff --git a/t/02_locks.t b/t/02_locks.t new file mode 100644 index 000000000..594fd1f4c --- /dev/null +++ b/t/02_locks.t @@ -0,0 +1,77 @@ +#!perl + +## Test the "locks" action + +use strict; +use warnings; +use Data::Dumper; +use DBI; +use Cwd; +use Test::More tests => 14; +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 'locks'}; + +$t=qq{$S fails when called with an invalid option}; +like ($cp->run('locks', 'foobar=12'), qr{^\s*Usage:}, $t); + +$t=qq{$S fails when invalid database used}; +like ($cp->run('locks', '--dbname=foo'), qr{database "foo" does not exist}, $t); + +$t=qq{$S fails when no matching databases found}; +like ($cp->run('locks', '--include=foo'), qr{No matching databases found}, $t); + +$cp->create_fake_pg_table('pg_locks'); +$SQL = q{SELECT oid FROM pg_database WHERE datname = 'postgres'}; +my $dboid = $dbh->selectall_arrayref($SQL)->[0][0]; +$SQL = 'INSERT INTO public.pg_locks(database,mode,granted) VALUES (?,?,?)'; +my $fakelock_sth = $dbh->prepare($SQL); +$fakelock_sth->execute($dboid,'Exclusive','t'); +$dbh->commit(); + +$t=qq{$S returns correct OK message}; +like ($cp->run('locks', '--critical=100'), qr{POSTGRES_LOCKS OK.*total=1 }, $t); + +$t=qq{$S returns correct warning message}; +like ($cp->run('locks', '--warning=1'), qr{POSTGRES_LOCKS WARNING.*total locks: 1 }, $t); + +$t=qq{$S returns correct critical message}; +like ($cp->run('locks', '--critical=1'), qr{POSTGRES_LOCKS CRITICAL.*total locks: 1 }, $t); + +$t=qq{$S returns correct OK message for specific lock type check}; +like ($cp->run('locks', '--critical="total=10;exclusive=3"'), qr{POSTGRES_LOCKS OK.*total=1 }, $t); + +$t=qq{$S returns correct OK message for specific lock type check}; +like ($cp->run('locks', '--critical="total=10;foobar=3"'), qr{POSTGRES_LOCKS OK.*total=1 }, $t); + +$t=qq{$S returns correct warning message for specific lock type check}; +like ($cp->run('locks', '--warning="total=10;exclusive=1"'), qr{POSTGRES_LOCKS WARNING.*total "exclusive" locks: 1 }, $t); + +$t=qq{$S returns correct critical message for specific lock type check}; +like ($cp->run('locks', '--critical="total=10;exclusive=1"'), qr{POSTGRES_LOCKS CRITICAL.*total "exclusive" locks: 1 }, $t); + +$t=qq{$S returns correct MRTG output}; +is ($cp->run('locks', '--output=MRTG'), qq{1\n0\n\nDB: postgres\n}, $t); + +$t=qq{$S returns correct OK message for 'waiting' option}; +like ($cp->run('locks', '--warning="waiting=1"'), qr{POSTGRES_LOCKS OK.*total=1 }, $t); + +$t=qq{$S returns correct warning message for 'waiting' option}; +$fakelock_sth->execute($dboid,'Exclusive','f'); +$dbh->commit(); +like ($cp->run('locks', '--warning="waiting=1"'), qr{POSTGRES_LOCKS WARNING.*total "waiting" locks: 1 }, $t); + +$t=qq{$S returns correct multiple item output}; +like ($cp->run('locks', '--warning="waiting=1;exclusive=2"'), + qr{POSTGRES_LOCKS WARNING.*total "waiting" locks: 1 \* total "exclusive" locks: 2 }, $t); + +$cp->remove_fake_pg_table('pg_locks'); + +exit; |