From 6224ec31587dc70b21b487a57d59cb863c2cd3a8 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Wed, 9 Nov 2005 16:40:12 +0000 Subject: Added new NPTest->testCmd which returns objects back for testing at the test script level. Updated check_swap and check_imap to this new format git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1279 f882894a-f735-0410-b71e-b25c423dba1c --- plugins/t/check_swap.t | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'plugins/t/check_swap.t') diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t index 348010de..435730fc 100644 --- a/plugins/t/check_swap.t +++ b/plugins/t/check_swap.t @@ -6,20 +6,27 @@ # use strict; -use Test; +use Test::More tests => 8; use NPTest; -use vars qw($tests); -BEGIN {$tests = 6; plan tests => $tests} - -my $t; - my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; +my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; + +my $result; + +$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free +cmp_ok( $result->return_code, "==", 0, "At least 1MB free" ); +like( $result->output, $successOutput, "Right output" ); + +$result = NPTest->testCmd( "./check_swap -w 1% -c 1%" ); # 1% free +cmp_ok( $result->return_code, "==", 0, 'At least 1% free' ); +like( $result->output, $successOutput, "Right output" ); -$t += checkCmd( "./check_swap -w 1048576 -c 1048576", 0, $successOutput ); # 1MB free -$t += checkCmd( "./check_swap -w 1\% -c 1\%", 0, $successOutput ); # 1% free -$t += checkCmd( "./check_swap -w 100\% -c 100\%", 2, $failureOutput ); # 100% free (always fails) +$result = NPTest->testCmd( "./check_swap -w 100% -c 100%" ); # 100% (always critical) +cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' ); +like( $result->output, $failureOutput, "Right output" ); -exit(0) if defined($Test::Harness::VERSION); -exit($tests - $t); +$result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn) +cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); +like( $result->output, $warnOutput, "Right output" ); -- cgit v1.2.3