diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-03-07 18:18:29 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-07 18:18:29 +0100 |
| commit | 03b09f7ce06f25b5ccdbd685d8f25931dff41cc8 (patch) | |
| tree | 80b6ccdcb7f3e492c22b8c53c33184ad139cf5a8 /plugins/t/check_swap.t | |
| parent | 9e1c72ac154d44f561635f1754103dac75cffb99 (diff) | |
| parent | f2275431783a5aaed25c35b5deec37c244872a7a (diff) | |
| download | monitoring-plugins-03b09f7ce06f25b5ccdbd685d8f25931dff41cc8.tar.gz | |
Merge pull request #2076 from RincewindsHat/feature/json_parsing_in_tests
Implement JSON output parsing for tests
Diffstat (limited to 'plugins/t/check_swap.t')
| -rw-r--r-- | plugins/t/check_swap.t | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t index 7e61b766..68946f6d 100644 --- a/plugins/t/check_swap.t +++ b/plugins/t/check_swap.t | |||
| @@ -17,42 +17,35 @@ my $message = '/^[0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; | |||
| 17 | 17 | ||
| 18 | $result = NPTest->testCmd( "./check_swap $outputFormat" ); # Always OK | 18 | $result = NPTest->testCmd( "./check_swap $outputFormat" ); # Always OK |
| 19 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); | 19 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
| 20 | $output = decode_json($result->output); | 20 | is($result->{'mp_test_result'}->{'state'}, "OK", "State was correct"); |
| 21 | is($output->{'state'}, "OK", "State was correct"); | 21 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); |
| 22 | like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
| 23 | 22 | ||
| 24 | $result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576 $outputFormat" ); # 1 MB free | 23 | $result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576 $outputFormat" ); # 1 MB free |
| 25 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); | 24 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
| 26 | $output = decode_json($result->output); | 25 | is($result->{'mp_test_result'}->{'state'}, "OK", "State was correct"); |
| 27 | is($output->{'state'}, "OK", "State was correct"); | 26 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); |
| 28 | like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
| 29 | 27 | ||
| 30 | $result = NPTest->testCmd( "./check_swap -w 1% -c 1% $outputFormat" ); # 1% free | 28 | $result = NPTest->testCmd( "./check_swap -w 1% -c 1% $outputFormat" ); # 1% free |
| 31 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); | 29 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
| 32 | $output = decode_json($result->output); | 30 | is($result->{'mp_test_result'}->{'state'}, "OK", "State was correct"); |
| 33 | is($output->{'state'}, "OK", "State was correct"); | 31 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); |
| 34 | like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
| 35 | 32 | ||
| 36 | $result = NPTest->testCmd( "./check_swap -w 100% -c 100% $outputFormat" ); # 100% (always critical) | 33 | $result = NPTest->testCmd( "./check_swap -w 100% -c 100% $outputFormat" ); # 100% (always critical) |
| 37 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); | 34 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
| 38 | $output = decode_json($result->output); | 35 | is($result->{'mp_test_result'}->{'state'}, "CRITICAL", "State was correct"); |
| 39 | is($output->{'state'}, "CRITICAL", "State was correct"); | 36 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); |
| 40 | like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
| 41 | 37 | ||
| 42 | $result = NPTest->testCmd( "./check_swap -w 100% -c 1% $outputFormat" ); # 100% (always warn) | 38 | $result = NPTest->testCmd( "./check_swap -w 100% -c 1% $outputFormat" ); # 100% (always warn) |
| 43 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); | 39 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
| 44 | $output = decode_json($result->output); | 40 | is($result->{'mp_test_result'}->{'state'}, "WARNING", "State was correct"); |
| 45 | is($output->{'state'}, "WARNING", "State was correct"); | 41 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); |
| 46 | like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
| 47 | 42 | ||
| 48 | $result = NPTest->testCmd( "./check_swap -w 100% $outputFormat" ); # 100% (single threshold, always warn) | 43 | $result = NPTest->testCmd( "./check_swap -w 100% $outputFormat" ); # 100% (single threshold, always warn) |
| 49 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); | 44 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
| 50 | $output = decode_json($result->output); | 45 | is($result->{'mp_test_result'}->{'state'}, "WARNING", "State was correct"); |
| 51 | is($output->{'state'}, "WARNING", "State was correct"); | 46 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); |
| 52 | like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
| 53 | 47 | ||
| 54 | $result = NPTest->testCmd( "./check_swap -c 100% $outputFormat" ); # 100% (single threshold, always critical) | 48 | $result = NPTest->testCmd( "./check_swap -c 100% $outputFormat" ); # 100% (single threshold, always critical) |
| 55 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); | 49 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); |
| 56 | $output = decode_json($result->output); | 50 | is($result->{'mp_test_result'}->{'state'}, "CRITICAL", "State was correct"); |
| 57 | is($output->{'state'}, "CRITICAL", "State was correct"); | 51 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct"); |
| 58 | like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct"); | ||
