summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: df4c79b)
raw | patch | inline | side by side (parent: df4c79b)
author | Matthias Eble <psychotrahe@users.sourceforge.net> | |
Fri, 30 Mar 2007 09:00:06 +0000 (09:00 +0000) | ||
committer | Matthias Eble <psychotrahe@users.sourceforge.net> | |
Fri, 30 Mar 2007 09:00:06 +0000 (09:00 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1660 f882894a-f735-0410-b71e-b25c423dba1c
lib/tests/test_disk.c | patch | blob | history | |
plugins/t/check_disk.t | patch | blob | history |
diff --git a/lib/tests/test_disk.c b/lib/tests/test_disk.c
index e48b30aaf8415c93f94875bd2593dc2d65e8e449..ac9db0056ab1de22471a439a2359059a52a5e4b4 100644 (file)
--- a/lib/tests/test_disk.c
+++ b/lib/tests/test_disk.c
#include "common.h"
#include "utils_disk.h"
#include "tap.h"
+#include "regex.h"
+
+void np_test_mount_entry_regex (struct mount_entry *dummy_mount_list,
+ char *regstr, int cflags, int expect,
+ char *desc);
+
int
main (int argc, char **argv)
struct mount_entry *dummy_mount_list;
struct mount_entry *me;
struct mount_entry **mtail = &dummy_mount_list;
+ int cflags = REG_NOSUB | REG_EXTENDED;
- plan_tests(18);
+ plan_tests(29);
ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list");
np_add_name(&exclude_filesystem, "/var/log");
*mtail = me;
mtail = &me->me_next;
+ np_test_mount_entry_regex(dummy_mount_list, strdup("/"),
+ cflags, 3, strdup("a"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"),
+ cflags, 3,strdup("regex on dev names:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"),
+ cflags, 0,
+ strdup("regex on non existant dev/path:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"),
+ cflags | REG_ICASE,0,
+ strdup("regi on non existant dev/path:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"),
+ cflags, 3,
+ strdup("partial devname regex match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"),
+ cflags, 1,
+ strdup("partial devname regex match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"),
+ cflags | REG_ICASE, 1,
+ strdup("partial devname regi match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("home"),
+ cflags, 1,
+ strdup("partial pathname regex match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"),
+ cflags | REG_ICASE, 1,
+ strdup("partial pathname regi match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"),
+ cflags, 2,
+ strdup("grouped regex pathname match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"),
+ cflags | REG_ICASE, 2,
+ strdup("grouped regi pathname match:"));
np_add_parameter(&paths, "/home/groups");
np_add_parameter(&paths, "/var");
return exit_status();
}
+
+void
+np_test_mount_entry_regex (struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc)
+{
+ int matches = 0;
+ regex_t re;
+ struct mount_entry *me;
+ if (regcomp(&re,regstr, cflags) == 0) {
+ for (me = dummy_mount_list; me; me= me->me_next) {
+ if(np_regex_match_mount_entry(me,&re))
+ matches++;
+ }
+ ok( matches == expect,
+ "%s '%s' matched %i/3 entries. ok: %i/3",
+ desc, regstr, expect, matches);
+
+ } else
+ ok ( false, "regex '%s' not compileable", regstr);
+}
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index 2c0802cc36dd7bfd9ba38094403ec79c7323dfd7..2ec6cabb0589342832f7aa4a50e8d4c85cc0dae9 100644 (file)
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") {
plan skip_all => "Need 2 mountpoints to test";
} else {
- plan tests => 61;
+ plan tests => 68;
}
$result = NPTest->testCmd(
like ( $result->only_output, qr/free space/, "Have free space text");
like ( $result->only_output, qr/$more_free/, "Have disk name in text");
+$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" );
+cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free");
+$_ = $result->output;
+print $result->output."\n";
+my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+) MB .* (\d+) MB /g);
+my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2;
+print "$free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2\n";
+
+
+
$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");
@@ -284,3 +294,28 @@ unlike( $result->perf_output, '/\/bob/', "perf data does not have /bob in it");
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p / -p /" );
unlike( $result->output, '/ \/ .* \/ /', "Should not show same filesystem twice");
+
+# are partitions added if -C is given without path selection -p ?
+$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -C -w 0% -c 0% -p $mountpoint_valid" );
+like( $result->output, '/;.*;\|/', "-C selects partitions if -p is not given");
+
+# grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit
+$result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all + 1) ." -c ". ($free_mb_on_all + 1) ."-g group -p $mountpoint_valid -p $mountpoint2_valid" );
+cmp_ok( $result->return_code, '==', 2, "grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit");
+
+# grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c
+$result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all + 1) ." -c ". ($free_mb_on_all - 1) ." -g group -p $mountpoint_valid -p $mountpoint2_valid" );
+cmp_ok( $result->return_code, '==', 1, "grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c ");
+
+# grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit
+$result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all - 1) ." -c ". ($free_mb_on_all - 1) ." -g group -p $mountpoint_valid -p $mountpoint2_valid" );
+cmp_ok( $result->return_code, '==', 0, "grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit");
+
+# grouping: exit unknown if group name is given after -p
+$result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all - 1) ." -c ". ($free_mb_on_all - 1) ." -p $mountpoint_valid -g group -p $mountpoint2_valid" );
+cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname");
+
+# regex: exit unknown if given regex is not compileable
+$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -r '('" );
+cmp_ok( $result->return_code, '==', 3, "Exit UNKNOWN if regex is not compileable");
+