[Nagiosplug-checkins] nagiosplug/plugins/t check_swap.t,1.2,1.3 check_imap.t,1.3,1.4

Ton Voon tonvoon at users.sourceforge.net
Wed Nov 9 08:44:17 CET 2005


Update of /cvsroot/nagiosplug/nagiosplug/plugins/t
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25303/plugins/t

Modified Files:
	check_swap.t check_imap.t 
Log Message:
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


Index: check_swap.t
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/t/check_swap.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- check_swap.t	25 Jul 2005 01:47:15 -0000	1.2
+++ check_swap.t	9 Nov 2005 16:40:12 -0000	1.3
@@ -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\)/';
 
-$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)
+my $result;
 
-exit(0) if defined($Test::Harness::VERSION);
-exit($tests - $t);
+$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" );
+
+$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" );
+
+$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" );

Index: check_imap.t
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/t/check_imap.t,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- check_imap.t	4 Nov 2005 09:38:24 -0000	1.3
+++ check_imap.t	9 Nov 2005 16:40:12 -0000	1.4
@@ -6,12 +6,9 @@
 #
 
 use strict;
-use Test;
+use Test::More tests => 7;
 use NPTest;
 
-use vars qw($tests);
-BEGIN {$tests = 7; plan tests => $tests}
-
 my $host_tcp_smtp      = getTestParameter( "host_tcp_smtp",      "NP_HOST_TCP_SMTP",      "mailhost",
 					   "A host providing an STMP Service (a mail server)");
 
@@ -24,18 +21,26 @@
 my $hostname_invalid   = getTestParameter( "hostname_invalid",   "NP_HOSTNAME_INVALID",   "nosuchhost",
                                            "An invalid (not known to DNS) hostname" );
 
-my %exceptions = ( 2 => "No IMAP Server present?" );
-
 my $t;
 
-$t += checkCmd( "./check_imap    $host_tcp_imap",                                     0, undef, %exceptions );
-$t += checkCmd( "./check_imap -H $host_tcp_imap -p 143 -w  9 -c  9 -t  10 -e '* OK'", 0, undef, %exceptions );
-$t += checkCmd( "./check_imap    $host_tcp_imap -p 143 -wt 9 -ct 9 -to 10 -e '* OK'", 0, undef, %exceptions );
-$t += checkCmd( "./check_imap    $host_nonresponsive", 2 );
-$t += checkCmd( "./check_imap    $hostname_invalid",   2 );
-$t += checkCmd( "./check_imap -H $host_tcp_imap -e unlikely_string",                  1);
-$t += checkCmd( "./check_imap -H $host_tcp_imap -e unlikely_string -M crit",          2);
+$t = NPTest->testCmd( "./check_imap $host_tcp_imap" );
+cmp_ok( $t->return_code, '==', 0, "Contacted imap" );
 
+$t = NPTest->testCmd( "./check_imap -H $host_tcp_imap -p 143 -w 9 -c 9 -to 10 -e '* OK'" );
+cmp_ok( $t->return_code, '==', 0, "Got right response" );
+
+$t = NPTest->testCmd( "./check_imap $host_tcp_imap -p 143 -wt 9 -ct 9 -to 10 -e '* OK'" );
+cmp_ok( $t->return_code, '==', 0, "Check old parameter options" );
+
+$t = NPTest->testCmd( "./check_imap $host_nonresponsive" );
+cmp_ok( $t->return_code, '==', 2, "Get error with non reponsive host" );
+
+$t = NPTest->testCmd( "./check_imap $hostname_invalid" );
+cmp_ok( $t->return_code, '==', 2, "Invalid hostname" );
+
+$t = NPTest->testCmd( "./check_imap -H $host_tcp_imap -e unlikely_string");
+cmp_ok( $t->return_code, '==', 1, "Got warning with bad response" );
+
+$t = NPTest->testCmd( "./check_imap -H $host_tcp_imap -e unlikely_string -M crit");
+cmp_ok( $t->return_code, '==', 2, "Got critical error with bad response" );
 
-exit(0) if defined($Test::Harness::VERSION);
-exit($tests - $t);





More information about the Commits mailing list