summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorGreg Sabino Mullane2009-02-27 03:57:02 +0000
committerGreg Sabino Mullane2009-02-27 03:57:02 +0000
commit83f96c8992c110838b9f671365d37cdc98f53e95 (patch)
tree915d1595b730414343c4e4772f5b17c5aed9fe2c /t
parentcb63f1fc2d48b53b6c582126d1f2ca7cb01eb519 (diff)
Test for the 'version' action, plus some fixes revealed by same.
Diffstat (limited to 't')
-rw-r--r--t/02_version.t113
-rw-r--r--t/CP_Testing.pm38
2 files changed, 147 insertions, 4 deletions
diff --git a/t/02_version.t b/t/02_version.t
new file mode 100644
index 000000000..e5f2e1089
--- /dev/null
+++ b/t/02_version.t
@@ -0,0 +1,113 @@
+#!perl
+
+## Test the "version" action
+
+use strict;
+use warnings;
+use Data::Dumper;
+use DBI;
+use Cwd;
+use Test::More tests => 28;
+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 'version'};
+
+$t=qq{$S fails when called with an invalid option};
+like ($cp->run('version', 'foobar=12'), qr{^\s*Usage:}, $t);
+
+$t=qq{$S fails when called with MRTG but no option};
+like ($cp->run('version', '--output=mrtg'), qr{ERROR: Invalid mrtg}, $t);
+
+$t=qq{$S fails when called with MRTG and a bad argument};
+like ($cp->run('version', '--output=mrtg --mrtg=foobar'), qr{ERROR: Invalid mrtg}, $t);
+
+$t=qq{$S fails when called without warning or critical};
+like ($cp->run('version', ''), qr{Must provide}, $t);
+
+$t=qq{$S fails when called without invalid warning};
+like ($cp->run('version', '-w foo'), qr{ERROR: Invalid string}, $t);
+
+$t=qq{$S fails when called without invalid critical};
+like ($cp->run('version', '-c foo'), qr{ERROR: Invalid string}, $t);
+
+$t=qq{$S gives correct output for warning on two-part version};
+like ($cp->run('version', '-w 5.2'), qr{POSTGRES_VERSION WARNING: .+expected 5.2}, $t);
+
+$t=qq{$S gives correct output for warning on three-part version};
+like ($cp->run('version', '-w 5.2.1'), qr{POSTGRES_VERSION WARNING: .+expected 5.2.1}, $t);
+
+$t=qq{$S gives correct output for critical on two-part version};
+like ($cp->run('version', '-c 6.10'), qr{POSTGRES_VERSION CRITICAL: .+expected 6.10}, $t);
+
+$t=qq{$S gives correct output for critical on three-part version};
+like ($cp->run('version', '-c 6.10.33'), qr{POSTGRES_VERSION CRITICAL: .+expected 6.10.33}, $t);
+
+## Now to pull some trickery
+$cp->fake_version('foobar');
+
+$t=qq{$S gives correct output on invalid version() parse};
+like ($cp->run('version', '-c 8.7'), qr{POSTGRES_VERSION UNKNOWN: .+Invalid query returned}, $t);
+
+$cp->fake_version('7.8.12');
+
+$t=qq{$S gives correct output for two-part version warning};
+like ($cp->run('version', '-w 7.8'), qr{POSTGRES_VERSION OK: .+version 7.8.12}, $t);
+
+$t=qq{$S gives correct output for two-part version warning};
+like ($cp->run('version', '-w 5.8'), qr{POSTGRES_VERSION WARNING: .+version 7.8.12}, $t);
+
+$t=qq{$S gives correct output for two-part version warning};
+like ($cp->run('version', '-w 7.9'), qr{POSTGRES_VERSION WARNING: .+version 7.8.12}, $t);
+
+$t=qq{$S gives correct output for three-part version warning};
+like ($cp->run('version', '-w 7.8.12'), qr{POSTGRES_VERSION OK: .+version 7.8.12}, $t);
+
+$t=qq{$S gives correct output for three-part version warning};
+like ($cp->run('version', '-w 7.8.11'), qr{POSTGRES_VERSION WARNING: .+version 7.8.12}, $t);
+
+$t=qq{$S gives correct output for matching three-part version warning};
+like ($cp->run('version', '-w 7.8.13'), qr{POSTGRES_VERSION WARNING: .+version 7.8.12}, $t);
+
+$t=qq{$S gives correct output for matching three-part version warning};
+like ($cp->run('version', '-w 7.9.13'), qr{POSTGRES_VERSION WARNING: .+version 7.8.12}, $t);
+
+$t=qq{$S gives correct output for two-part version critical};
+like ($cp->run('version', '-c 7.8'), qr{POSTGRES_VERSION OK: .+version 7.8.12}, $t);
+
+$t=qq{$S gives correct output for two-part version critical};
+like ($cp->run('version', '-c 5.8'), qr{POSTGRES_VERSION CRITICAL: .+version 7.8.12}, $t);
+
+$t=qq{$S gives correct output for two-part version critical};
+like ($cp->run('version', '-c 7.9'), qr{POSTGRES_VERSION CRITICAL: .+version 7.8.12}, $t);
+
+$t=qq{$S gives correct output for three-part version critical};
+like ($cp->run('version', '-c 7.8.12'), qr{POSTGRES_VERSION OK: .+version 7.8.12}, $t);
+
+$t=qq{$S gives correct output for three-part version critical};
+like ($cp->run('version', '-c 7.8.11'), qr{POSTGRES_VERSION CRITICAL: .+version 7.8.12}, $t);
+
+$t=qq{$S gives correct output for matching three-part version critical};
+like ($cp->run('version', '-c 7.8.13'), qr{POSTGRES_VERSION CRITICAL: .+version 7.8.12}, $t);
+
+$t=qq{$S gives correct output for matching three-part version critical};
+like ($cp->run('version', '-c 7.9.13'), qr{POSTGRES_VERSION CRITICAL: .+version 7.8.12}, $t);
+
+$t=qq{$S gives correct output for MRTG output};
+like ($cp->run('version', '--output=MRTG --mrtg=7.9.13'), qr{^0\n0\n\n7.8.12\n}, $t);
+
+$t=qq{$S gives correct output for MRTG output};
+like ($cp->run('version', '--output=MRTG --mrtg=7.8'), qr{^1\n0\n\n7.8.12\n}, $t);
+
+$t=qq{$S gives correct output for MRTG output};
+like ($cp->run('version', '--output=MRTG --mrtg=7.8.12'), qr{^1\n0\n\n7.8.12\n}, $t);
+
+$cp->reset_path();
+
+exit;
diff --git a/t/CP_Testing.pm b/t/CP_Testing.pm
index 1bf8c4522..af1fa2f62 100644
--- a/t/CP_Testing.pm
+++ b/t/CP_Testing.pm
@@ -218,8 +218,8 @@ sub create_fake_pg_table {
## Dangerous: do not try this at home!
my $self = shift;
- my $name = shift;
- my $dbh = $self->{dbh};
+ my $name = shift || die;
+ my $dbh = $self->{dbh} || die;
my $dbuser = $self->{testuser} || die;
{
local $dbh->{Warn};
@@ -235,8 +235,8 @@ sub create_fake_pg_table {
sub remove_fake_pg_table {
my $self = shift;
- my $name = shift;
- my $dbh = $self->{dbh};
+ my $name = shift || die;
+ my $dbh = $self->{dbh} || die;
my $dbuser = $self->{testuser} || die;
{
local $dbh->{Warn};
@@ -259,4 +259,34 @@ sub table_exists {
} ## end of table_exists
+sub fake_version {
+
+ my $self = shift;
+ my $version = shift || '9.9';
+ my $dbh = $self->{dbh} || die;
+ my $dbuser = $self->{testuser} || die;
+
+ $dbh->do(qq{
+CREATE OR REPLACE FUNCTION public.version()
+RETURNS TEXT
+LANGUAGE SQL
+AS \$\$
+SELECT 'PostgreSQL $version on fakefunction for check_postgres.pl testing'::text;
+\$\$
+});
+ $dbh->do("ALTER USER $dbuser SET search_path = public, pg_catalog");
+ $dbh->commit();
+
+} ## end of fake version
+
+sub reset_path {
+
+ my $self = shift;
+ my $dbh = $self->{dbh} || die;
+ my $dbuser = $self->{testuser} || die;
+ $dbh->do("ALTER USER $dbuser SET search_path = public");
+ $dbh->commit();
+
+} ## end of reset_path
+
1;