diff options
| -rw-r--r-- | plugins/t/check_swap.t | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t index eaa81083..6ef2323d 100644 --- a/plugins/t/check_swap.t +++ b/plugins/t/check_swap.t | |||
| @@ -5,39 +5,41 @@ | |||
| 5 | # | 5 | # |
| 6 | 6 | ||
| 7 | use strict; | 7 | use strict; |
| 8 | use warnings; | ||
| 8 | use Test::More tests => 14; | 9 | use Test::More tests => 14; |
| 9 | use NPTest; | 10 | use NPTest; |
| 10 | 11 | ||
| 11 | my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; | 12 | my $successOutput = '/^OK.* - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; |
| 12 | my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; | 13 | my $failureOutput = '/^CRITICAL: .*- [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; |
| 13 | my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; | 14 | my $warnOutput = '/^WARNING: .*- [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; |
| 14 | 15 | ||
| 16 | my $outputFormat = '--output-format one-line'; | ||
| 15 | my $result; | 17 | my $result; |
| 16 | 18 | ||
| 17 | $result = NPTest->testCmd( "./check_swap" ); # Always OK | 19 | $result = NPTest->testCmd( "./check_swap $outputFormat" ); # Always OK |
| 18 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); | 20 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
| 19 | like( $result->output, $successOutput, "Right output" ); | 21 | like( $result->output, $successOutput, "Right output" ); |
| 20 | 22 | ||
| 21 | $result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free | 23 | $result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576 $outputFormat" ); # 1 MB free |
| 22 | cmp_ok( $result->return_code, "==", 0, "At least 1MB free" ); | 24 | cmp_ok( $result->return_code, "==", 0, "At least 1MB free" ); |
| 23 | like( $result->output, $successOutput, "Right output" ); | 25 | like( $result->output, $successOutput, "Right output" ); |
| 24 | 26 | ||
| 25 | $result = NPTest->testCmd( "./check_swap -w 1% -c 1%" ); # 1% free | 27 | $result = NPTest->testCmd( "./check_swap -w 1% -c 1% $outputFormat" ); # 1% free |
| 26 | cmp_ok( $result->return_code, "==", 0, 'At least 1% free' ); | 28 | cmp_ok( $result->return_code, "==", 0, 'At least 1% free' ); |
| 27 | like( $result->output, $successOutput, "Right output" ); | 29 | like( $result->output, $successOutput, "Right output" ); |
| 28 | 30 | ||
| 29 | $result = NPTest->testCmd( "./check_swap -w 100% -c 100%" ); # 100% (always critical) | 31 | $result = NPTest->testCmd( "./check_swap -w 100% -c 100% $outputFormat" ); # 100% (always critical) |
| 30 | cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' ); | 32 | cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' ); |
| 31 | like( $result->output, $failureOutput, "Right output" ); | 33 | like( $result->output, $failureOutput, "Right output" ); |
| 32 | 34 | ||
| 33 | $result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn) | 35 | $result = NPTest->testCmd( "./check_swap -w 100% -c 1% $outputFormat" ); # 100% (always warn) |
| 34 | cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); | 36 | cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); |
| 35 | like( $result->output, $warnOutput, "Right output" ); | 37 | like( $result->output, $warnOutput, "Right output" ); |
| 36 | 38 | ||
| 37 | $result = NPTest->testCmd( "./check_swap -w 100%" ); # 100% (single threshold, always warn) | 39 | $result = NPTest->testCmd( "./check_swap -w 100% $outputFormat" ); # 100% (single threshold, always warn) |
| 38 | cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); | 40 | cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); |
| 39 | like( $result->output, $warnOutput, "Right output" ); | 41 | like( $result->output, $warnOutput, "Right output" ); |
| 40 | 42 | ||
| 41 | $result = NPTest->testCmd( "./check_swap -c 100%" ); # 100% (single threshold, always critical) | 43 | $result = NPTest->testCmd( "./check_swap -c 100% $outputFormat" ); # 100% (single threshold, always critical) |
| 42 | cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' ); | 44 | cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' ); |
| 43 | like( $result->output, $failureOutput, "Right output" ); | 45 | like( $result->output, $failureOutput, "Right output" ); |
