diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-02-19 11:57:25 +0100 |
---|---|---|
committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-02-19 11:57:25 +0100 |
commit | d27e0862a9e514149d81622a82622d31ab3bee9b (patch) | |
tree | 74f0bf9b9c6ed65dbd8b5d3130af36bf13d4b785 /plugins/t | |
parent | 6320a4e9534595d9c5f0d6d73e6858f548092a3e (diff) | |
download | monitoring-plugins-d27e0862a9e514149d81622a82622d31ab3bee9b.tar.gz |
Fix previous check_swap tests
Diffstat (limited to 'plugins/t')
-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" ); |