diff options
author | Cédric Villemain | 2011-11-09 10:56:00 +0000 |
---|---|---|
committer | Cédric Villemain | 2011-11-10 02:53:24 +0000 |
commit | 4577690b837a0c487bc316c7bb1786602ac3ae95 (patch) | |
tree | 7259f7af1631f9864e52fe9986c23f0707798a94 | |
parent | 0ff408711dab18b05de26656a945fa37e363f6aa (diff) |
Add cluster_id test
for automatic testing too.
-rw-r--r-- | MANIFEST | 1 | ||||
-rw-r--r-- | t/02_cluster_id.t | 80 |
2 files changed, 81 insertions, 0 deletions
@@ -17,6 +17,7 @@ t/02_autovac_freeze.t t/02_backends.t t/02_bloat.t t/02_checkpoint.t +t/02_cluster_id.t t/02_connection.t t/02_custom_query.t t/02_database_size.t diff --git a/t/02_cluster_id.t b/t/02_cluster_id.t new file mode 100644 index 000000000..6cab394c5 --- /dev/null +++ b/t/02_cluster_id.t @@ -0,0 +1,80 @@ +#!perl + +## Test the "checkpoint" action + +use 5.006; +use strict; +use warnings; +use Data::Dumper; +use Test::More tests => 14; +use lib 't','.'; +use CP_Testing; + +use vars qw/$dbh $result $SQL $t/; + +my $cp = CP_Testing->new( {default_action => 'cluster_id'} ); + +$dbh = $cp->test_database_handle(); + +my $S = q{Action 'cluster_id'}; +my $label = 'POSTGRES_CLUSTER_ID'; + +$t=qq{$S fails when called with an invalid option}; +like ($cp->run('foobar=12'), qr{Usage:}, $t); + +$t=qq{$S fails when called without warning or critical}; +like ($cp->run(''), qr{Must provide a 'warning' or 'critical'}, $t); + +$t=qq{$S fails when called with invalid warning option}; +like ($cp->run('-w foo'), qr{ERROR: .+'warning'.+must be an integer}, $t); + +$t=qq{$S fails when called with invalid critical option}; +like ($cp->run('-c foo'), qr{ERROR: .+'critical'.+must be an integer}, $t); + +$t=qq{$S fails when called without a datadir option and PGDATA is not set}; +delete $ENV{PGDATA}; +like ($cp->run('-c 10'), qr{^ERROR: Must supply a --datadir}, $t); + +$t=qq{$S fails when called with an invalid datadir option and PGDATA is not set}; +like ($cp->run('-c 10 --datadir=foobar'), qr{^ERROR: Invalid data_directory}, $t); + +$t = qq{$S rejects -w and -c together}; +is ($cp->run('-w 123 -c 123'), + qq{ERROR: Can only provide 'warning' OR 'critical' option\n}, $t); + +my $host = $cp->get_dbhost(); + +$t=qq{$S fails when called against a non datadir datadir}; +like ($cp->run(qq{-c 10 --datadir="$host"}), + qr{^ERROR:.+could not read the given data directory}, $t); + +$host =~ s/socket$//; + +$t = qq{$S notes mismatched cluster_id (warning)}; +like ($cp->run(qq{-w 123 --datadir="$host"}), + qr{$label WARNING: .* cluster_id:}, $t); + +$t = qq{$S notes mismatched cluster_id (critical)}; +like ($cp->run(qq{-c 123 --datadir="$host"}), + qr{$label CRITICAL: .* cluster_id:}, $t); + +$t = qq{$S self-identifies correctly}; +$result = $cp->run(qq{--critical 0 --datadir="$host"}); +like ($result, qr{^$label UNKNOWN: +cluster_id: \d+}, $t); + +my $true_cluster_id; +$true_cluster_id = $1 if $result =~ /cluster_id: (\d{19})/; + +$t = qq{$S accepts matching cluster_id}; +like ($cp->run(qq{-w $true_cluster_id --datadir="$host"}), + qr/OK.*\Qcluster_id: $true_cluster_id\E/, $t); + +$t=qq{$S returns the expected output for MRTG(failure)}; +like ($cp->run(qq{--mrtg 123 --output=MRTG --datadir="$host"}), + qr{^0\n0\n\n\d+}, $t); + +$t=qq{$S returns the expected output for MRTG(success)}; +like ($cp->run(qq{--mrtg $true_cluster_id --output=MRTG --datadir="$host"}), + qr{^1\n0\n\n\d+}, $t); + +exit; |