diff options
Diffstat (limited to 'plugins/t/check_swap.t')
-rw-r--r-- | plugins/t/check_swap.t | 29 |
1 files changed, 18 insertions, 11 deletions
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 | ||
8 | use strict; | 8 | use strict; |
9 | use Test; | 9 | use Test::More tests => 8; |
10 | use NPTest; | 10 | use NPTest; |
11 | 11 | ||
12 | use vars qw($tests); | ||
13 | BEGIN {$tests = 6; plan tests => $tests} | ||
14 | |||
15 | my $t; | ||
16 | |||
17 | my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; | 12 | my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; |
18 | my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; | 13 | my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; |
14 | my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; | ||
15 | |||
16 | my $result; | ||
17 | |||
18 | $result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free | ||
19 | cmp_ok( $result->return_code, "==", 0, "At least 1MB free" ); | ||
20 | like( $result->output, $successOutput, "Right output" ); | ||
21 | |||
22 | $result = NPTest->testCmd( "./check_swap -w 1% -c 1%" ); # 1% free | ||
23 | cmp_ok( $result->return_code, "==", 0, 'At least 1% free' ); | ||
24 | like( $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 | 27 | cmp_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) | 28 | like( $result->output, $failureOutput, "Right output" ); |
23 | 29 | ||
24 | exit(0) if defined($Test::Harness::VERSION); | 30 | $result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn) |
25 | exit($tests - $t); | 31 | cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); |
32 | like( $result->output, $warnOutput, "Right output" ); | ||