From 0d562a356f45f645014c3908178fc13876006f6e Mon Sep 17 00:00:00 2001 From: Kristian Schuster <116557017+KriSchu@users.noreply.github.com> Date: Tue, 25 Oct 2022 20:49:51 +0200 Subject: check_disk: add tests for new option --ignore-missing --- plugins/t/check_disk.t | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'plugins/t') diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index ec527e7f..bea34a4c 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t @@ -351,3 +351,18 @@ unlike( $result->output, qr/$mountpoint2_valid/, "output data does not have $mou $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '^barbazJodsf\$'"); like( $result->output, qr/$mountpoint_valid/, "ignore: output data does have $mountpoint_valid when regex doesn't match"); like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mountpoint2_valid when regex doesn't match"); + +# ignore-missing: exit okay, when fs is not accessible +$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob"); +cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob"); +like( $result->output, '/^DISK OK - /bob is not accessible .*$/', 'Output OK'); + +# ignore-missing: exit okay, when regex does not match +$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob"); +cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); +like( $result->output, '/^DISK OK: Regular expression did not match any path or disk.*$/', 'Output OK'); + +# ignore-missing: exit okay, when fs with exact match (-E) is not found +$result = NPTest->testCmd( "./check_disk --ignore-missing -E -w 0% -c 0% -p /etc"); +cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs"); +like( $result->output, '/^DISK OK: /etc not found.*$/', 'Output OK'); -- cgit v1.2.3-74-g34f1 From bacacd2cb38c7d7a695a6f75f699168d9df0132d Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Wed, 26 Oct 2022 14:03:22 +0200 Subject: check_disk: adjust test plan --- plugins/t/check_disk.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/t') diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index bea34a4c..a534fd4a 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t @@ -23,7 +23,7 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { plan skip_all => "Need 2 mountpoints to test"; } else { - plan tests => 78; + plan tests => 84; } $result = NPTest->testCmd( -- cgit v1.2.3-74-g34f1 From ca3d59cd6918c9e2739e783b721d4c1122640fd3 Mon Sep 17 00:00:00 2001 From: Kristian Schuster <116557017+KriSchu@users.noreply.github.com> Date: Sun, 19 Feb 2023 23:00:21 +0100 Subject: check_disk: add new tests for new ignore-missing feature --- plugins/t/check_disk.t | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'plugins/t') diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index a534fd4a..275db70d 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t @@ -23,7 +23,7 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { plan skip_all => "Need 2 mountpoints to test"; } else { - plan tests => 84; + plan tests => 86; } $result = NPTest->testCmd( @@ -355,14 +355,24 @@ like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mo # ignore-missing: exit okay, when fs is not accessible $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob"); cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob"); -like( $result->output, '/^DISK OK - /bob is not accessible .*$/', 'Output OK'); +like( $result->output, '/^DISK OK - No disks were found for provided parameters; ignored paths: /bob;.*$/', 'Output OK'); # ignore-missing: exit okay, when regex does not match $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob"); cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); -like( $result->output, '/^DISK OK: Regular expression did not match any path or disk.*$/', 'Output OK'); +like( $result->output, '/^DISK OK - No disks were found for provided parameters;.*$/', 'Output OK'); # ignore-missing: exit okay, when fs with exact match (-E) is not found -$result = NPTest->testCmd( "./check_disk --ignore-missing -E -w 0% -c 0% -p /etc"); +$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc"); cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs"); -like( $result->output, '/^DISK OK: /etc not found.*$/', 'Output OK'); +like( $result->output, '/^DISK OK - No disks were found for provided parameters; ignored paths: /etc;.*$/', 'Output OK'); + +# ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex) +$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/$'"); +cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); +like( $result->output, '/^DISK OK - free space: / .*$/', 'Output OK'); + +# ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path) +$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'"); +cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); +like( $result->output, '/^DISK OK - free space: / .*; ignored paths: /bob;.*$/', 'Output OK'); \ No newline at end of file -- cgit v1.2.3-74-g34f1 From a58293a0c288ee0e050c79715073da9fbdfc4c58 Mon Sep 17 00:00:00 2001 From: Kristian Schuster <116557017+KriSchu@users.noreply.github.com> Date: Mon, 20 Feb 2023 01:27:23 +0100 Subject: check_disk: fix tests by setting correct test number and escaping line end regex --- plugins/t/check_disk.t | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'plugins/t') diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index 275db70d..73f1e374 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t @@ -23,7 +23,7 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { plan skip_all => "Need 2 mountpoints to test"; } else { - plan tests => 86; + plan tests => 88; } $result = NPTest->testCmd( @@ -126,7 +126,7 @@ my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; $result = NPTest->testCmd( "./check_disk -e -w 1 -c 1 -p $more_free" ); -is( $result->only_output, "DISK OK", "No print out of disks with -e for OKs"); +is( $result->only_output, "DISK OK - No disks were found for provided parameters;", "No print out of disks with -e for OKs"); $result = NPTest->testCmd( "./check_disk 100 100 $more_free" ); cmp_ok( $result->return_code, '==', 0, "Old syntax okay" ); @@ -368,9 +368,9 @@ cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact m like( $result->output, '/^DISK OK - No disks were found for provided parameters; ignored paths: /etc;.*$/', 'Output OK'); # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex) -$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/$'"); +$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'"); cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); -like( $result->output, '/^DISK OK - free space: / .*$/', 'Output OK'); +like( $result->output, '/^DISK OK - free space: \/ .*$/', 'Output OK'); # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path) $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'"); -- cgit v1.2.3-74-g34f1 From e102b8a49e857a474db516455d2e871e6834ae34 Mon Sep 17 00:00:00 2001 From: Kristian Schuster <116557017+KriSchu@users.noreply.github.com> Date: Mon, 20 Feb 2023 02:03:01 +0100 Subject: check_disk: fix ugly output with -e option and adapt tests accordingly --- plugins/check_disk.c | 10 +++++----- plugins/t/check_disk.t | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'plugins/t') diff --git a/plugins/check_disk.c b/plugins/check_disk.c index d32841d8..c52d1df4 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -186,8 +186,8 @@ main (int argc, char **argv) char mountdir[32]; #endif - preamble = strdup (" free space:"); - ignored_preamble = strdup (" ignored paths:"); + preamble = strdup (" - free space:"); + ignored_preamble = strdup (" - ignored paths:"); output = strdup (""); ignored = strdup (""); details = strdup (""); @@ -455,12 +455,12 @@ main (int argc, char **argv) if (verbose >= 2) xasprintf (&output, "%s%s", output, details); - if (strcmp(output, "") == 0) { + if (strcmp(output, "") == 0 && ! erronly) { preamble = ""; - xasprintf (&output, " No disks were found for provided parameters;"); + xasprintf (&output, " - No disks were found for provided parameters;"); } - printf ("DISK %s -%s%s%s%s|%s\n", state_text (result), ((erronly && result==STATE_OK)) ? "" : preamble, output, (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf); + printf ("DISK %s%s%s%s%s|%s\n", state_text (result), ((erronly && result==STATE_OK)) ? "" : preamble, output, (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf); return result; } diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index 73f1e374..c8f08f51 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t @@ -126,7 +126,7 @@ my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; $result = NPTest->testCmd( "./check_disk -e -w 1 -c 1 -p $more_free" ); -is( $result->only_output, "DISK OK - No disks were found for provided parameters;", "No print out of disks with -e for OKs"); +is( $result->only_output, "DISK OK", "No print out of disks with -e for OKs"); $result = NPTest->testCmd( "./check_disk 100 100 $more_free" ); cmp_ok( $result->return_code, '==', 0, "Old syntax okay" ); @@ -355,7 +355,7 @@ like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mo # ignore-missing: exit okay, when fs is not accessible $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob"); cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob"); -like( $result->output, '/^DISK OK - No disks were found for provided parameters; ignored paths: /bob;.*$/', 'Output OK'); +like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /bob;.*$/', 'Output OK'); # ignore-missing: exit okay, when regex does not match $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob"); @@ -365,7 +365,7 @@ like( $result->output, '/^DISK OK - No disks were found for provided parameters; # ignore-missing: exit okay, when fs with exact match (-E) is not found $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc"); cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs"); -like( $result->output, '/^DISK OK - No disks were found for provided parameters; ignored paths: /etc;.*$/', 'Output OK'); +like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /etc;.*$/', 'Output OK'); # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex) $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'"); @@ -375,4 +375,4 @@ like( $result->output, '/^DISK OK - free space: \/ .*$/', 'Output OK'); # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path) $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'"); cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); -like( $result->output, '/^DISK OK - free space: / .*; ignored paths: /bob;.*$/', 'Output OK'); \ No newline at end of file +like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK'); \ No newline at end of file -- cgit v1.2.3-74-g34f1