diff options
author | Sven Nierlein <sven@nierlein.de> | 2014-01-19 23:54:34 (GMT) |
---|---|---|
committer | Sven Nierlein <sven@nierlein.de> | 2014-01-19 23:54:34 (GMT) |
commit | b418181dfe80dd75169b6e8a619ac1932155dea2 (patch) | |
tree | cad9c0ae0eae8e800cfff60555ead06ad33c6856 /t/Nagios-Plugin-Range.t | |
parent | 1cd8d1c52cbd47121f344c4074aec84653f412ce (diff) | |
download | monitoring-plugin-perl-b418181dfe80dd75169b6e8a619ac1932155dea2.tar.gz |
renamed module into Monitoring::Plugin
since the complete monitoring team has been renamed, we
also rename this module.
Signed-off-by: Sven Nierlein <sven@nierlein.de>
Diffstat (limited to 't/Nagios-Plugin-Range.t')
-rw-r--r-- | t/Nagios-Plugin-Range.t | 243 |
1 files changed, 0 insertions, 243 deletions
diff --git a/t/Nagios-Plugin-Range.t b/t/Nagios-Plugin-Range.t deleted file mode 100644 index 6fe080c..0000000 --- a/t/Nagios-Plugin-Range.t +++ /dev/null | |||
@@ -1,243 +0,0 @@ | |||
1 | |||
2 | use strict; | ||
3 | #use Test::More qw(no_plan); | ||
4 | use Test::More tests => 151; | ||
5 | |||
6 | BEGIN { | ||
7 | use_ok('Nagios::Plugin::Range'); | ||
8 | # Silence warnings unless TEST_VERBOSE is set | ||
9 | $SIG{__WARN__} = sub { warn $_[0] if $ENV{TEST_VERBOSE} }; | ||
10 | }; | ||
11 | |||
12 | diag "\nusing Nagios::Plugin::Range revision ". $Nagios::Plugin::Range::VERSION . "\n" if $ENV{TEST_VERBOSE}; | ||
13 | |||
14 | my $r; | ||
15 | |||
16 | diag "'garbage in' checks -- you should see 7 invalid range definition warnings here:" if $ENV{TEST_VERBOSE}; | ||
17 | |||
18 | foreach (qw( | ||
19 | : | ||
20 | 1:~ | ||
21 | foo | ||
22 | 1-10 | ||
23 | 10:~ | ||
24 | 1-10:2.4 | ||
25 | |||
26 | ), '1,10' # avoid warning about using , inside qw() | ||
27 | ) { | ||
28 | $r =Nagios::Plugin::Range->parse_range_string($_); | ||
29 | is $r, undef, "'$_' should not be a valid range" ; | ||
30 | } | ||
31 | |||
32 | |||
33 | diag "range: 0..6 inclusive" if $ENV{TEST_VERBOSE}; | ||
34 | $r = Nagios::Plugin::Range->parse_range_string("6"); | ||
35 | isa_ok( $r, "Nagios::Plugin::Range"); | ||
36 | ok( defined $r, "'6' is valid range"); | ||
37 | cmp_ok( $r->start, '==', 0, "Start correct"); | ||
38 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | ||
39 | cmp_ok( $r->end, '==', 6, "End correct"); | ||
40 | cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity"); | ||
41 | cmp_ok( $r, 'eq', "6", "Stringification back to original"); | ||
42 | |||
43 | my $expected = { | ||
44 | -1 => 1, # 1 means it raises an alert because it's OUTSIDE the range | ||
45 | 0 => 0, # 0 means it's inside the range (no alert) | ||
46 | 4 => 0, | ||
47 | 6 => 0, | ||
48 | 6.1 => 1, | ||
49 | 79.999999 => 1, | ||
50 | }; | ||
51 | |||
52 | sub test_expected { | ||
53 | my $r = shift; | ||
54 | my $expected = shift; | ||
55 | foreach (sort {$a<=>$b} keys %$expected) { | ||
56 | is $r->check_range($_), $expected->{$_}, | ||
57 | " $_ should " . ($expected->{$_} ? 'not ' : '') . "be in the range (line ".(caller)[2].")"; | ||
58 | } | ||
59 | } | ||
60 | |||
61 | test_expected( $r, $expected ); | ||
62 | |||
63 | diag "range : -7..23, inclusive" if $ENV{TEST_VERBOSE}; | ||
64 | $r = Nagios::Plugin::Range->parse_range_string("-7:23"); | ||
65 | ok( defined $r, "'-7:23' is valid range"); | ||
66 | cmp_ok( $r->start, '==', -7, "Start correct"); | ||
67 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | ||
68 | cmp_ok( $r->end, '==', 23, "End correct"); | ||
69 | cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity"); | ||
70 | cmp_ok( $r, 'eq', "-7:23", "Stringification back to original"); | ||
71 | |||
72 | $expected = { | ||
73 | -23 => 1, | ||
74 | -7 => 0, | ||
75 | -1 => 0, | ||
76 | 0 => 0, | ||
77 | 4 => 0, | ||
78 | 23 => 0, | ||
79 | 23.1 => 1, | ||
80 | 79.999999 => 1, | ||
81 | }; | ||
82 | test_expected( $r, $expected ); | ||
83 | |||
84 | |||
85 | diag "range : 0..5.75, inclusive" if $ENV{TEST_VERBOSE}; | ||
86 | $r = Nagios::Plugin::Range->parse_range_string(":5.75"); | ||
87 | ok( defined $r, "':5.75' is valid range"); | ||
88 | cmp_ok( $r->start, '==', 0, "Start correct"); | ||
89 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | ||
90 | cmp_ok( $r->end, '==', 5.75, "End correct"); | ||
91 | cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity"); | ||
92 | cmp_ok( $r, 'eq', "5.75", "Stringification to simplification"); | ||
93 | $expected = { | ||
94 | -1 => 1, | ||
95 | 0 => 0, | ||
96 | 4 => 0, | ||
97 | 5.75 => 0, | ||
98 | 5.7501 => 1, | ||
99 | 6 => 1, | ||
100 | 6.1 => 1, | ||
101 | 79.999999 => 1, | ||
102 | }; | ||
103 | test_expected( $r, $expected ); | ||
104 | |||
105 | |||
106 | |||
107 | diag "range : negative infinity .. -95.99, inclusive" if $ENV{TEST_VERBOSE}; | ||
108 | $r = Nagios::Plugin::Range->parse_range_string("~:-95.99"); | ||
109 | ok( defined $r, "'~:-95.99' is valid range"); | ||
110 | cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity"); | ||
111 | cmp_ok( $r->end, '==', -95.99, "End correct"); | ||
112 | cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity"); | ||
113 | cmp_ok( $r, 'eq', "~:-95.99", "Stringification back to original"); | ||
114 | $expected = { | ||
115 | -1001341 => 0, | ||
116 | -96 => 0, | ||
117 | -95.999 => 0, | ||
118 | -95.99 => 0, | ||
119 | -95.989 => 1, | ||
120 | -95 => 1, | ||
121 | 0 => 1, | ||
122 | 5.7501 => 1, | ||
123 | 79.999999 => 1, | ||
124 | }; | ||
125 | test_expected( $r, $expected ); | ||
126 | |||
127 | diag "range 10..infinity , inclusive" if $ENV{TEST_VERBOSE}; | ||
128 | test_expected( $r, $expected ); | ||
129 | $r = Nagios::Plugin::Range->parse_range_string("10:"); | ||
130 | ok( defined $r, "'10:' is valid range"); | ||
131 | cmp_ok( $r->start, '==', 10, "Start correct"); | ||
132 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | ||
133 | cmp_ok( $r->end_infinity, '==', 1, "Using positive infinity"); | ||
134 | cmp_ok( $r, 'eq', "10:", "Stringification back to original"); | ||
135 | $expected = { | ||
136 | -95.999 => 1, | ||
137 | -1 => 1, | ||
138 | 0 => 1, | ||
139 | 9.91 => 1, | ||
140 | 10 => 0, | ||
141 | 11.1 => 0, | ||
142 | 123456789012346 => 0, | ||
143 | }; | ||
144 | test_expected( $r, $expected ); | ||
145 | |||
146 | |||
147 | |||
148 | diag "range 123456789012345..infinity , inclusive" if $ENV{TEST_VERBOSE}; | ||
149 | test_expected( $r, $expected ); | ||
150 | $r = Nagios::Plugin::Range->parse_range_string("123456789012345:"); | ||
151 | ok( defined $r, "'123456789012345:' is valid range"); | ||
152 | cmp_ok( $r->start, '==', 123456789012345, "Start correct"); | ||
153 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | ||
154 | cmp_ok( $r->end_infinity, '==', 1, "Using positive infinity"); | ||
155 | cmp_ok( $r, 'eq', "123456789012345:", "Stringification back to original"); | ||
156 | $expected = { | ||
157 | -95.999 => 1, | ||
158 | -1 => 1, | ||
159 | 0 => 1, | ||
160 | # The fractional values needs to be quoted, otherwise the hash rounds it up to ..345 | ||
161 | # and there is one less test run. | ||
162 | # I think some newer versions of perl use a higher precision value for the hash key. | ||
163 | # This doesn't appear to affect the actual plugin though | ||
164 | "123456789012344.91" => 1, | ||
165 | 123456789012345 => 0, | ||
166 | "123456789012345.61" => 0, | ||
167 | 123456789012346 => 0, | ||
168 | }; | ||
169 | test_expected( $r, $expected ); | ||
170 | |||
171 | |||
172 | diag "range: <= zero " if $ENV{TEST_VERBOSE}; | ||
173 | $r = Nagios::Plugin::Range->parse_range_string("~:0"); | ||
174 | ok( defined $r, "'~:0' is valid range"); | ||
175 | cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity"); | ||
176 | cmp_ok( $r->end, '==', 0, "End correct"); | ||
177 | cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity"); | ||
178 | cmp_ok( $r->alert_on, '==', 0, "Will alert on outside of range"); | ||
179 | cmp_ok( $r, 'eq', "~:0", "Stringification back to original"); | ||
180 | ok( $r->check_range(0.5) == 1, "0.5 - alert"); | ||
181 | ok( $r->check_range(-10) == 0, "-10 - no alert"); | ||
182 | ok( $r->check_range(0) == 0, "0 - no alert"); | ||
183 | $expected = { | ||
184 | -123456789012344.91 => 0, | ||
185 | -1 => 0, | ||
186 | 0 => 0, | ||
187 | .001 => 1, | ||
188 | 123456789012345 => 1, | ||
189 | }; | ||
190 | test_expected( $r, $expected ); | ||
191 | |||
192 | |||
193 | diag "range: OUTSIDE 0..657.8210567" if $ENV{TEST_VERBOSE}; | ||
194 | $r = Nagios::Plugin::Range->parse_range_string('@0:657.8210567'); | ||
195 | ok( defined $r, '"@0:657.8210567" is a valid range'); | ||
196 | cmp_ok( $r->start, '==', 0, "Start correct"); | ||
197 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | ||
198 | cmp_ok( $r->end, '==', 657.8210567, "End correct"); | ||
199 | cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity"); | ||
200 | cmp_ok( $r->alert_on, '==', 1, "Will alert on inside of range"); | ||
201 | cmp_ok( $r, 'eq', '@657.8210567', "Stringification to simplified version"); | ||
202 | ok( $r->check_range(32.88) == 1, "32.88 - alert"); | ||
203 | ok( $r->check_range(-2) == 0, "-2 - no alert"); | ||
204 | ok( $r->check_range(657.8210567) == 1, "657.8210567 - alert"); | ||
205 | ok( $r->check_range(0) == 1, "0 - alert"); | ||
206 | $expected = { | ||
207 | -134151 => 0, | ||
208 | -1 => 0, | ||
209 | 0 => 1, | ||
210 | .001 => 1, | ||
211 | 657.8210567 => 1, | ||
212 | 657.9 => 0, | ||
213 | 123456789012345 => 0, | ||
214 | }; | ||
215 | test_expected( $r, $expected ); | ||
216 | |||
217 | |||
218 | diag "range: 1..1 inclusive (equals one)" if $ENV{TEST_VERBOSE}; | ||
219 | $r = Nagios::Plugin::Range->parse_range_string('1:1'); | ||
220 | ok( defined $r, '"1:1" is a valid range'); | ||
221 | cmp_ok( $r->start, '==', 1, "Start correct"); | ||
222 | cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity"); | ||
223 | cmp_ok( $r->end, '==', 1, "End correct"); | ||
224 | cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity"); | ||
225 | cmp_ok( $r, 'eq', "1:1", "Stringification to simplified version"); | ||
226 | ok( $r->check_range(0.5) == 1, "0.5 - alert"); | ||
227 | ok( $r->check_range(1) == 0, "1 - no alert"); | ||
228 | ok( $r->check_range(5.2) == 1, "5.2 - alert"); | ||
229 | $expected = { | ||
230 | -1 => 1, | ||
231 | 0 => 1, | ||
232 | .5 => 1, | ||
233 | 1 => 0, | ||
234 | 1.001 => 1, | ||
235 | 5.2 => 1, | ||
236 | }; | ||
237 | test_expected( $r, $expected ); | ||
238 | |||
239 | |||
240 | $r = Nagios::Plugin::Range->parse_range_string('2:1'); | ||
241 | ok( ! defined $r, '"2:1" is rejected'); | ||
242 | |||
243 | # TODO: Need more tests for invalid data | ||