[monitoring-plugins] Fix previous check_swap tests
Lorenz Kästle
git at monitoring-plugins.org
Fri Feb 21 14:40:11 CET 2025
Module: monitoring-plugins
Branch: master
Commit: d27e0862a9e514149d81622a82622d31ab3bee9b
Author: Lorenz Kästle <12514511+RincewindsHat at users.noreply.github.com>
Date: Wed Feb 19 11:57:25 2025 +0100
URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=d27e0862
Fix previous check_swap tests
---
plugins/t/check_swap.t | 22 ++++++++++++----------
1 file 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 @@
#
use strict;
+use warnings;
use Test::More tests => 14;
use NPTest;
-my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';
-my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';
-my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';
+my $successOutput = '/^OK.* - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';
+my $failureOutput = '/^CRITICAL: .*- [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';
+my $warnOutput = '/^WARNING: .*- [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';
+my $outputFormat = '--output-format one-line';
my $result;
-$result = NPTest->testCmd( "./check_swap" ); # Always OK
+$result = NPTest->testCmd( "./check_swap $outputFormat" ); # Always OK
cmp_ok( $result->return_code, "==", 0, "Always OK" );
like( $result->output, $successOutput, "Right output" );
-$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free
+$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576 $outputFormat" ); # 1 MB free
cmp_ok( $result->return_code, "==", 0, "At least 1MB free" );
like( $result->output, $successOutput, "Right output" );
-$result = NPTest->testCmd( "./check_swap -w 1% -c 1%" ); # 1% free
+$result = NPTest->testCmd( "./check_swap -w 1% -c 1% $outputFormat" ); # 1% free
cmp_ok( $result->return_code, "==", 0, 'At least 1% free' );
like( $result->output, $successOutput, "Right output" );
-$result = NPTest->testCmd( "./check_swap -w 100% -c 100%" ); # 100% (always critical)
+$result = NPTest->testCmd( "./check_swap -w 100% -c 100% $outputFormat" ); # 100% (always critical)
cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' );
like( $result->output, $failureOutput, "Right output" );
-$result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn)
+$result = NPTest->testCmd( "./check_swap -w 100% -c 1% $outputFormat" ); # 100% (always warn)
cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' );
like( $result->output, $warnOutput, "Right output" );
-$result = NPTest->testCmd( "./check_swap -w 100%" ); # 100% (single threshold, always warn)
+$result = NPTest->testCmd( "./check_swap -w 100% $outputFormat" ); # 100% (single threshold, always warn)
cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' );
like( $result->output, $warnOutput, "Right output" );
-$result = NPTest->testCmd( "./check_swap -c 100%" ); # 100% (single threshold, always critical)
+$result = NPTest->testCmd( "./check_swap -c 100% $outputFormat" ); # 100% (single threshold, always critical)
cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' );
like( $result->output, $failureOutput, "Right output" );
More information about the Commits
mailing list