From e14541d2a6aef243c306d4decbbcd42cbd5386d4 Mon Sep 17 00:00:00 2001 From: Jeff Boes Date: Mon, 27 Apr 2009 17:09:49 -0400 Subject: [PATCH] Add tests for disk_space; added missing msg name. --- check_postgres.pl | 6 +++--- t/02_disk_space.t | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 t/02_disk_space.t diff --git a/check_postgres.pl b/check_postgres.pl index 85c553967..c49b965ae 100755 --- a/check_postgres.pl +++ b/check_postgres.pl @@ -2663,7 +2663,7 @@ sub check_disk_space { my %seenfs; for $db (@{$info->{db}}) { my %i; - while ($db->{slurp} =~ /([ST])\s+\| (\w+)\s+\| (\S*)\s*/g) { + while ($db->{slurp} =~ /([ST])\s+\| (\w+)\s+\| (.*?)\n/g) { my ($st,$name,$val) = ($1,$2,$3); $i{$st}{$name} = $val; } @@ -2717,7 +2717,7 @@ sub check_disk_space { $dir{$dir} = 1; - $COM = "/bin/df -kP $dir 2>&1"; + $COM = qq{/bin/df -kP "$dir" 2>&1}; $res = qx{$COM}; if ($res !~ /^.+\n(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\%\s+(\S+)/) { @@ -2741,7 +2741,7 @@ sub check_disk_space { my $prettyused = pretty_size($used); my $prettytotal = pretty_size($total); - my $msg = msg('', $fs, $mount, $prettyused, $prettytotal, $percent); + my $msg = msg('diskspace-msg', $fs, $mount, $prettyused, $prettytotal, $percent); $db->{perf} = "$fs=$used"; diff --git a/t/02_disk_space.t b/t/02_disk_space.t new file mode 100644 index 000000000..6eeff2c20 --- /dev/null +++ b/t/02_disk_space.t @@ -0,0 +1,46 @@ +#!perl + +## Test the "disk_space" 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/; + +my $cp = CP_Testing->new( {default_action => 'disk_space'} ); + +$dbh = $cp->test_database_handle(); +$dbh->{AutoCommit} = 1; +$dbname = $cp->get_dbname; +$host = $cp->get_host(); +my $label = q{POSTGRES_DISK_SPACE}; + +my $S = q{Action 'disk_space'}; + +$t = qq{$S identifies self}; +$result = $cp->run('-w 999z'); +like($result, qr{$label}, $t); + +$t = qq{$S identifies host}; +like ($result, qr{host:$host}, $t); + +$t = qq{$S reports file system}; +like ($result, qr{FS /.*? mounted on /.*? is using }, $t); + +$t = qq{$S reports usage}; +like ($result, qr{ is using \d*\.\d+ [A-Z]B of \d*\.\d+ [A-Z]B}, $t); + +$t = qq{$S notes plenty of available space}; +like ($result, qr{$label OK}, $t); + +$t = qq{$S flags insufficient space}; +like ($cp->run('-w 1b'), qr{$label WARNING:}, $t); + +$t = qq{$S reports MRTG output}; +like ($cp->run('--output=mrtg'), qr{\A\d+\n0\n\n/.*\n}, $t); -- 2.30.2