summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Eble <psychotrahe@users.sourceforge.net>2007-03-30 09:00:06 (GMT)
committerMatthias Eble <psychotrahe@users.sourceforge.net>2007-03-30 09:00:06 (GMT)
commit950f99c62a942f665bde95b9d606279ffa7804d7 (patch)
treea2f3c48abeb1162bf0768e00ee8610fa57770738
parentdf4c79ba35280b6bed248d673d510d2a0c39cc49 (diff)
downloadmonitoring-plugins-950f99c62a942f665bde95b9d606279ffa7804d7.tar.gz
Test Cases for check_disk's -r, -R, -C and -g
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1660 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--lib/tests/test_disk.c59
-rw-r--r--plugins/t/check_disk.t37
2 files changed, 94 insertions, 2 deletions
diff --git a/lib/tests/test_disk.c b/lib/tests/test_disk.c
index e48b30a..ac9db00 100644
--- a/lib/tests/test_disk.c
+++ b/lib/tests/test_disk.c
@@ -21,6 +21,12 @@
21#include "common.h" 21#include "common.h"
22#include "utils_disk.h" 22#include "utils_disk.h"
23#include "tap.h" 23#include "tap.h"
24#include "regex.h"
25
26void np_test_mount_entry_regex (struct mount_entry *dummy_mount_list,
27 char *regstr, int cflags, int expect,
28 char *desc);
29
24 30
25int 31int
26main (int argc, char **argv) 32main (int argc, char **argv)
@@ -35,8 +41,9 @@ main (int argc, char **argv)
35 struct mount_entry *dummy_mount_list; 41 struct mount_entry *dummy_mount_list;
36 struct mount_entry *me; 42 struct mount_entry *me;
37 struct mount_entry **mtail = &dummy_mount_list; 43 struct mount_entry **mtail = &dummy_mount_list;
44 int cflags = REG_NOSUB | REG_EXTENDED;
38 45
39 plan_tests(18); 46 plan_tests(29);
40 47
41 ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list"); 48 ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list");
42 np_add_name(&exclude_filesystem, "/var/log"); 49 np_add_name(&exclude_filesystem, "/var/log");
@@ -76,6 +83,37 @@ main (int argc, char **argv)
76 *mtail = me; 83 *mtail = me;
77 mtail = &me->me_next; 84 mtail = &me->me_next;
78 85
86 np_test_mount_entry_regex(dummy_mount_list, strdup("/"),
87 cflags, 3, strdup("a"));
88 np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"),
89 cflags, 3,strdup("regex on dev names:"));
90 np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"),
91 cflags, 0,
92 strdup("regex on non existant dev/path:"));
93 np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"),
94 cflags | REG_ICASE,0,
95 strdup("regi on non existant dev/path:"));
96 np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"),
97 cflags, 3,
98 strdup("partial devname regex match:"));
99 np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"),
100 cflags, 1,
101 strdup("partial devname regex match:"));
102 np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"),
103 cflags | REG_ICASE, 1,
104 strdup("partial devname regi match:"));
105 np_test_mount_entry_regex(dummy_mount_list, strdup("home"),
106 cflags, 1,
107 strdup("partial pathname regex match:"));
108 np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"),
109 cflags | REG_ICASE, 1,
110 strdup("partial pathname regi match:"));
111 np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"),
112 cflags, 2,
113 strdup("grouped regex pathname match:"));
114 np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"),
115 cflags | REG_ICASE, 2,
116 strdup("grouped regi pathname match:"));
79 117
80 np_add_parameter(&paths, "/home/groups"); 118 np_add_parameter(&paths, "/home/groups");
81 np_add_parameter(&paths, "/var"); 119 np_add_parameter(&paths, "/var");
@@ -125,3 +163,22 @@ main (int argc, char **argv)
125 return exit_status(); 163 return exit_status();
126} 164}
127 165
166
167void
168np_test_mount_entry_regex (struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc)
169{
170 int matches = 0;
171 regex_t re;
172 struct mount_entry *me;
173 if (regcomp(&re,regstr, cflags) == 0) {
174 for (me = dummy_mount_list; me; me= me->me_next) {
175 if(np_regex_match_mount_entry(me,&re))
176 matches++;
177 }
178 ok( matches == expect,
179 "%s '%s' matched %i/3 entries. ok: %i/3",
180 desc, regstr, expect, matches);
181
182 } else
183 ok ( false, "regex '%s' not compileable", regstr);
184}
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index 2c0802c..2ec6cab 100644
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -24,7 +24,7 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth
24if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { 24if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") {
25 plan skip_all => "Need 2 mountpoints to test"; 25 plan skip_all => "Need 2 mountpoints to test";
26} else { 26} else {
27 plan tests => 61; 27 plan tests => 68;
28} 28}
29 29
30$result = NPTest->testCmd( 30$result = NPTest->testCmd(
@@ -111,6 +111,16 @@ like ( $result->output, $successOutput, "OK output" );
111like ( $result->only_output, qr/free space/, "Have free space text"); 111like ( $result->only_output, qr/free space/, "Have free space text");
112like ( $result->only_output, qr/$more_free/, "Have disk name in text"); 112like ( $result->only_output, qr/$more_free/, "Have disk name in text");
113 113
114$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" );
115cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free");
116$_ = $result->output;
117print $result->output."\n";
118my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+) MB .* (\d+) MB /g);
119my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2;
120print "$free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2\n";
121
122
123
114$result = NPTest->testCmd( "./check_disk -e -w 1 -c 1 -p $more_free" ); 124$result = NPTest->testCmd( "./check_disk -e -w 1 -c 1 -p $more_free" );
115is( $result->only_output, "DISK OK", "No print out of disks with -e for OKs"); 125is( $result->only_output, "DISK OK", "No print out of disks with -e for OKs");
116 126
@@ -284,3 +294,28 @@ unlike( $result->perf_output, '/\/bob/', "perf data does not have /bob in it");
284 294
285$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p / -p /" ); 295$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p / -p /" );
286unlike( $result->output, '/ \/ .* \/ /', "Should not show same filesystem twice"); 296unlike( $result->output, '/ \/ .* \/ /', "Should not show same filesystem twice");
297
298# are partitions added if -C is given without path selection -p ?
299$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -C -w 0% -c 0% -p $mountpoint_valid" );
300like( $result->output, '/;.*;\|/', "-C selects partitions if -p is not given");
301
302# grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit
303$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" );
304cmp_ok( $result->return_code, '==', 2, "grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit");
305
306# grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c
307$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" );
308cmp_ok( $result->return_code, '==', 1, "grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c ");
309
310# grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit
311$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" );
312cmp_ok( $result->return_code, '==', 0, "grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit");
313
314# grouping: exit unknown if group name is given after -p
315$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" );
316cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname");
317
318# regex: exit unknown if given regex is not compileable
319$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -r '('" );
320cmp_ok( $result->return_code, '==', 3, "Exit UNKNOWN if regex is not compileable");
321