summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/t/check_imap.t35
-rw-r--r--plugins/t/check_swap.t29
2 files changed, 38 insertions, 26 deletions
diff --git a/plugins/t/check_imap.t b/plugins/t/check_imap.t
index 32b4136..fa957d1 100644
--- a/plugins/t/check_imap.t
+++ b/plugins/t/check_imap.t
@@ -6,12 +6,9 @@
6# 6#
7 7
8use strict; 8use strict;
9use Test; 9use Test::More tests => 7;
10use NPTest; 10use NPTest;
11 11
12use vars qw($tests);
13BEGIN {$tests = 7; plan tests => $tests}
14
15my $host_tcp_smtp = getTestParameter( "host_tcp_smtp", "NP_HOST_TCP_SMTP", "mailhost", 12my $host_tcp_smtp = getTestParameter( "host_tcp_smtp", "NP_HOST_TCP_SMTP", "mailhost",
16 "A host providing an STMP Service (a mail server)"); 13 "A host providing an STMP Service (a mail server)");
17 14
@@ -24,18 +21,26 @@ my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRES
24my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", 21my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
25 "An invalid (not known to DNS) hostname" ); 22 "An invalid (not known to DNS) hostname" );
26 23
27my %exceptions = ( 2 => "No IMAP Server present?" );
28
29my $t; 24my $t;
30 25
31$t += checkCmd( "./check_imap $host_tcp_imap", 0, undef, %exceptions ); 26$t = NPTest->testCmd( "./check_imap $host_tcp_imap" );
32$t += checkCmd( "./check_imap -H $host_tcp_imap -p 143 -w 9 -c 9 -t 10 -e '* OK'", 0, undef, %exceptions ); 27cmp_ok( $t->return_code, '==', 0, "Contacted imap" );
33$t += checkCmd( "./check_imap $host_tcp_imap -p 143 -wt 9 -ct 9 -to 10 -e '* OK'", 0, undef, %exceptions ); 28
34$t += checkCmd( "./check_imap $host_nonresponsive", 2 ); 29$t = NPTest->testCmd( "./check_imap -H $host_tcp_imap -p 143 -w 9 -c 9 -to 10 -e '* OK'" );
35$t += checkCmd( "./check_imap $hostname_invalid", 2 ); 30cmp_ok( $t->return_code, '==', 0, "Got right response" );
36$t += checkCmd( "./check_imap -H $host_tcp_imap -e unlikely_string", 1); 31
37$t += checkCmd( "./check_imap -H $host_tcp_imap -e unlikely_string -M crit", 2); 32$t = NPTest->testCmd( "./check_imap $host_tcp_imap -p 143 -wt 9 -ct 9 -to 10 -e '* OK'" );
33cmp_ok( $t->return_code, '==', 0, "Check old parameter options" );
34
35$t = NPTest->testCmd( "./check_imap $host_nonresponsive" );
36cmp_ok( $t->return_code, '==', 2, "Get error with non reponsive host" );
37
38$t = NPTest->testCmd( "./check_imap $hostname_invalid" );
39cmp_ok( $t->return_code, '==', 2, "Invalid hostname" );
40
41$t = NPTest->testCmd( "./check_imap -H $host_tcp_imap -e unlikely_string");
42cmp_ok( $t->return_code, '==', 1, "Got warning with bad response" );
38 43
44$t = NPTest->testCmd( "./check_imap -H $host_tcp_imap -e unlikely_string -M crit");
45cmp_ok( $t->return_code, '==', 2, "Got critical error with bad response" );
39 46
40exit(0) if defined($Test::Harness::VERSION);
41exit($tests - $t);
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t
index 348010d..435730f 100644
--- a/plugins/t/check_swap.t
+++ b/plugins/t/check_swap.t
@@ -6,20 +6,27 @@
6# 6#
7 7
8use strict; 8use strict;
9use Test; 9use Test::More tests => 8;
10use NPTest; 10use NPTest;
11 11
12use vars qw($tests);
13BEGIN {$tests = 6; plan tests => $tests}
14
15my $t;
16
17my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; 12my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/';
18my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; 13my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/';
14my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/';
15
16my $result;
17
18$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free
19cmp_ok( $result->return_code, "==", 0, "At least 1MB free" );
20like( $result->output, $successOutput, "Right output" );
21
22$result = NPTest->testCmd( "./check_swap -w 1% -c 1%" ); # 1% free
23cmp_ok( $result->return_code, "==", 0, 'At least 1% free' );
24like( $result->output, $successOutput, "Right output" );
19 25
20$t += checkCmd( "./check_swap -w 1048576 -c 1048576", 0, $successOutput ); # 1MB free 26$result = NPTest->testCmd( "./check_swap -w 100% -c 100%" ); # 100% (always critical)
21$t += checkCmd( "./check_swap -w 1\% -c 1\%", 0, $successOutput ); # 1% free 27cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' );
22$t += checkCmd( "./check_swap -w 100\% -c 100\%", 2, $failureOutput ); # 100% free (always fails) 28like( $result->output, $failureOutput, "Right output" );
23 29
24exit(0) if defined($Test::Harness::VERSION); 30$result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn)
25exit($tests - $t); 31cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' );
32like( $result->output, $warnOutput, "Right output" );