diff options
Diffstat (limited to 'plugins/t/check_swap.t')
-rw-r--r-- | plugins/t/check_swap.t | 58 |
1 files changed, 33 insertions, 25 deletions
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t index eaa81083..68946f6d 100644 --- a/plugins/t/check_swap.t +++ b/plugins/t/check_swap.t | |||
@@ -5,39 +5,47 @@ | |||
5 | # | 5 | # |
6 | 6 | ||
7 | use strict; | 7 | use strict; |
8 | use Test::More tests => 14; | 8 | use warnings; |
9 | use Test::More tests => 21; | ||
9 | use NPTest; | 10 | use NPTest; |
10 | 11 | use JSON; | |
11 | my $successOutput = '/^SWAP 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 $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; | ||
14 | 12 | ||
15 | my $result; | 13 | my $result; |
14 | my $outputFormat = '--output-format mp-test-json'; | ||
15 | my $output; | ||
16 | my $message = '/^[0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; | ||
16 | 17 | ||
17 | $result = NPTest->testCmd( "./check_swap" ); # Always OK | 18 | $result = NPTest->testCmd( "./check_swap $outputFormat" ); # Always OK |
18 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); | 19 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
19 | like( $result->output, $successOutput, "Right output" ); | 20 | is($result->{'mp_test_result'}->{'state'}, "OK", "State was correct"); |
21 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
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, "Always OK" ); |
23 | like( $result->output, $successOutput, "Right output" ); | 25 | is($result->{'mp_test_result'}->{'state'}, "OK", "State was correct"); |
26 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
24 | 27 | ||
25 | $result = NPTest->testCmd( "./check_swap -w 1% -c 1%" ); # 1% free | 28 | $result = NPTest->testCmd( "./check_swap -w 1% -c 1% $outputFormat" ); # 1% free |
26 | cmp_ok( $result->return_code, "==", 0, 'At least 1% free' ); | 29 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
27 | like( $result->output, $successOutput, "Right output" ); | 30 | is($result->{'mp_test_result'}->{'state'}, "OK", "State was correct"); |
31 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
28 | 32 | ||
29 | $result = NPTest->testCmd( "./check_swap -w 100% -c 100%" ); # 100% (always critical) | 33 | $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' ); | 34 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
31 | like( $result->output, $failureOutput, "Right output" ); | 35 | is($result->{'mp_test_result'}->{'state'}, "CRITICAL", "State was correct"); |
36 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
32 | 37 | ||
33 | $result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn) | 38 | $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' ); | 39 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
35 | like( $result->output, $warnOutput, "Right output" ); | 40 | is($result->{'mp_test_result'}->{'state'}, "WARNING", "State was correct"); |
41 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
36 | 42 | ||
37 | $result = NPTest->testCmd( "./check_swap -w 100%" ); # 100% (single threshold, always warn) | 43 | $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' ); | 44 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
39 | like( $result->output, $warnOutput, "Right output" ); | 45 | is($result->{'mp_test_result'}->{'state'}, "WARNING", "State was correct"); |
46 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
40 | 47 | ||
41 | $result = NPTest->testCmd( "./check_swap -c 100%" ); # 100% (single threshold, always critical) | 48 | $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' ); | 49 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
43 | like( $result->output, $failureOutput, "Right output" ); | 50 | is($result->{'mp_test_result'}->{'state'}, "CRITICAL", "State was correct"); |
51 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||