[check_postgres] [commit] Add tests for dbstats; fixed invalid error in check_postgres.pl;
check_postgres at bucardo.org
check_postgres at bucardo.org
Mon Apr 27 20:02:37 UTC 2009
Committed by Jeff Boes <jeff at endpoint.com>
Add tests for dbstats; fixed invalid error in check_postgres.pl;
extended CP_Testing::run method to allow no dbname runs.
---
check_postgres.pl | 5 +++--
t/02_dbstats.t | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
t/CP_Testing.pm | 4 +++-
3 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/check_postgres.pl b/check_postgres.pl
index 0fad690..85c5539 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -175,7 +175,7 @@ our %msg = (
'range-badsize' => q{Invalid size for '$1' option},
'range-badtype' => q{validate_range called with unknown type '$1'},
'range-badversion' => q{Invalid string for '$1' option: $2},
- 'range-cactionly' => q{This action is for cacti use only and takes not warning or critical arguments},
+ 'range-cactionly' => q{This action is for cacti use only and takes no warning or critical arguments},
'range-int' => q{Invalid argument for '$1' option: must be an integer},
'range-int-pos' => q{Invalid argument for '$1' option: must be a positive integer},
'range-neg-percent' => q{Cannot specify a negative percent!},
@@ -2045,7 +2045,7 @@ sub validate_range {
}
elsif ('cacti' eq $type) { ## Takes no args, just dumps data
if (length $warning or length $critical) {
- ndie msg('range-cacti-only');
+ ndie msg('range-cactionly');
}
}
else {
@@ -4655,6 +4655,7 @@ sub show_dbstats {
for $db (@{$info->{db}}) {
SLURP: for my $row (split /\n/ => $db->{slurp}) {
my @stats = split /\s*\|\s*/ => $row;
+ ((defined($_) and length($_)) or $_ = 0) for @stats;
(my $dbname = shift @stats) =~ s/^\s*//;
next SLURP if skip_item($dbname);
## If dbnames were specififed, use those for filtering as well
diff --git a/t/02_dbstats.t b/t/02_dbstats.t
new file mode 100644
index 0000000..24910cb
--- /dev/null
+++ b/t/02_dbstats.t
@@ -0,0 +1,50 @@
+#!perl
+
+## Test the "dbstats" action
+
+use strict;
+use warnings;
+use Data::Dumper;
+use DBI;
+use Test::More tests => 42;
+use lib 't','.';
+use CP_Testing;
+
+use vars qw/$dbh $result $t $host $dbname/;
+
+my $cp = CP_Testing->new( {default_action => 'dbstats'} );
+
+$dbh = $cp->test_database_handle();
+$dbh->{AutoCommit} = 1;
+$dbname = $cp->get_dbname;
+$host = $cp->get_host();
+
+my $S = q{Action 'dbstats'};
+
+$t = qq{$S rejects -w};
+is($cp->run('-w 0'), "ERROR: This action is for cacti use only and takes no warning or critical arguments\n", $t);
+
+$t = qq{$S rejects -c};
+is($cp->run('-c 0'), "ERROR: This action is for cacti use only and takes no warning or critical arguments\n", $t);
+
+$t = qq{$S identifies database};
+$result = $cp->run("--dbname $dbname");
+like ($result, qr{\bdbname:$dbname}, $t);
+
+$t = qq{$S finds stats for database };
+$result = $cp->run('--nodbname');
+study $result;
+
+for (qw(template0 template1 postgres ardala beedeebeedee)) {
+ like($result, qr[dbname:$_], $t . $_);
+}
+$t = qq{$S retrieves stats for };
+my $t1 = qq{$S returns integer for };
+study $result;
+
+for (qw(backends commits rollbacks read hit idxscan idxtupread idxtupfetch idxblksread
+ idxblkshit seqscan seqtupread ret fetch ins upd del)) {
+ like($result, qr:\b$_\b:, $t . $_);
+ like($result, qr{\b$_:\d+\b}, $t1 . $_);
+}
+
diff --git a/t/CP_Testing.pm b/t/CP_Testing.pm
index 20cbb24..f052816 100644
--- a/t/CP_Testing.pm
+++ b/t/CP_Testing.pm
@@ -240,7 +240,9 @@ sub run {
my $dbuser = $self->{testuser} || die "No testuser?";
my $dbname = $self->{dbname} || die "No dbname?";
my $com = qq{perl check_postgres.pl --action=$action --dbhost="$dbhost" --dbuser=$dbuser};
- if ($extra !~ /dbname=/) {
+ if ($extra =~ s/--nodbname//) {
+ }
+ elsif ($extra !~ /dbname=/) {
$com .= " --dbname=$dbname";
}
--
1.6.0.5
More information about the Check_postgres
mailing list