diff options
author | Sven Nierlein <sven@nierlein.de> | 2014-01-20 00:54:34 +0100 |
---|---|---|
committer | Sven Nierlein <sven@nierlein.de> | 2014-01-20 00:54:34 +0100 |
commit | b418181dfe80dd75169b6e8a619ac1932155dea2 (patch) | |
tree | cad9c0ae0eae8e800cfff60555ead06ad33c6856 /t/Monitoring-Plugin-03.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/Monitoring-Plugin-03.t')
-rw-r--r-- | t/Monitoring-Plugin-03.t | 262 |
1 files changed, 262 insertions, 0 deletions
diff --git a/t/Monitoring-Plugin-03.t b/t/Monitoring-Plugin-03.t new file mode 100644 index 0000000..d419342 --- /dev/null +++ b/t/Monitoring-Plugin-03.t | |||
@@ -0,0 +1,262 @@ | |||
1 | # $np->check_messages tests | ||
2 | |||
3 | use strict; | ||
4 | use Test::More tests => 61; | ||
5 | |||
6 | BEGIN { | ||
7 | use_ok("Monitoring::Plugin"); | ||
8 | use_ok("Monitoring::Plugin::Functions", ":all"); | ||
9 | } | ||
10 | Monitoring::Plugin::Functions::_fake_exit(1); | ||
11 | |||
12 | my $plugin = 'MP_CHECK_MESSAGES_03'; | ||
13 | my $np = Monitoring::Plugin->new( shortname => $plugin, () ); | ||
14 | is($np->shortname, $plugin, "shortname() is $plugin"); | ||
15 | |||
16 | my ($code, $message); | ||
17 | |||
18 | # ------------------------------------------------------------------------- | ||
19 | # Check codes | ||
20 | my @codes = ( | ||
21 | [ [ qw(Critical) ], [ qw(Warning) ], CRITICAL ], | ||
22 | [ [], [ qw(Warning) ], WARNING ], | ||
23 | [ [], [], OK ], | ||
24 | ); | ||
25 | my $i = 0; | ||
26 | for (@codes) { | ||
27 | $i++; | ||
28 | $code = $np->check_messages( critical => $_->[0], warning => $_->[1] ); | ||
29 | is($code, $_->[2], "Code test $i returned $STATUS_TEXT{$_->[2]}"); | ||
30 | } | ||
31 | |||
32 | # ------------------------------------------------------------------------- | ||
33 | # Check messages | ||
34 | my %arrays = ( | ||
35 | critical => [ qw(A B C) ], | ||
36 | warning => [ qw(D E F) ], | ||
37 | ok => [ qw(G H I) ], | ||
38 | ); | ||
39 | my %messages = map { $_ => join(' ', @{$arrays{$_}}) } keys %arrays; | ||
40 | |||
41 | # critical, warning | ||
42 | ($code, $message) = $np->check_messages( | ||
43 | critical => $arrays{critical}, warning => $arrays{warning}, | ||
44 | ); | ||
45 | is($code, CRITICAL, "(critical, warning) code is $STATUS_TEXT{$code}"); | ||
46 | is($message, $messages{critical}, "(critical, warning) message is $message"); | ||
47 | |||
48 | # critical, warning, ok | ||
49 | ($code, $message) = $np->check_messages( | ||
50 | critical => $arrays{critical}, warning => $arrays{warning}, | ||
51 | ok => $arrays{ok}, | ||
52 | ); | ||
53 | is($code, CRITICAL, "(critical, warning, ok) code is $STATUS_TEXT{$code}"); | ||
54 | is($message, $messages{critical}, "(critical, warning, ok) message is $message"); | ||
55 | |||
56 | # critical, warning, $ok | ||
57 | ($code, $message) = $np->check_messages( | ||
58 | critical => $arrays{critical}, warning => $arrays{warning}, | ||
59 | ok => 'G H I', | ||
60 | ); | ||
61 | is($code, CRITICAL, "(critical, warning, \$ok) code is $STATUS_TEXT{$code}"); | ||
62 | is($message, $messages{critical}, "(critical, warning, \$ok) message is $message"); | ||
63 | |||
64 | # warning | ||
65 | ($code, $message) = $np->check_messages( | ||
66 | critical => [], warning => $arrays{warning}, | ||
67 | ); | ||
68 | is($code, WARNING, "(warning) code is $STATUS_TEXT{$code}"); | ||
69 | is($message, $messages{warning}, "(warning) message is $message"); | ||
70 | |||
71 | # warning, ok | ||
72 | ($code, $message) = $np->check_messages( | ||
73 | critical => [], warning => $arrays{warning}, ok => $arrays{ok}, | ||
74 | ); | ||
75 | is($code, WARNING, "(warning, ok) code is $STATUS_TEXT{$code}"); | ||
76 | is($message, $messages{warning}, "(warning, ok) message is $message"); | ||
77 | |||
78 | # ok | ||
79 | ($code, $message) = $np->check_messages( | ||
80 | critical => [], warning => [], ok => $arrays{ok}, | ||
81 | ); | ||
82 | is($code, OK, "(ok) code is $STATUS_TEXT{$code}"); | ||
83 | is($message, $messages{ok}, "(ok) message is $message"); | ||
84 | |||
85 | # $ok | ||
86 | ($code, $message) = $np->check_messages( | ||
87 | critical => [], warning => [], ok => 'G H I', | ||
88 | ); | ||
89 | is($code, OK, "(\$ok) code is $STATUS_TEXT{$code}"); | ||
90 | is($message, $messages{ok}, "(\$ok) message is $message"); | ||
91 | |||
92 | # ------------------------------------------------------------------------- | ||
93 | # explicit join | ||
94 | my $join = '+'; | ||
95 | ($code, $message) = $np->check_messages( | ||
96 | critical => $arrays{critical}, warning => $arrays{warning}, | ||
97 | join => $join, | ||
98 | ); | ||
99 | is($message, join($join, @{$arrays{critical}}), "joined '$join' (critical, warning) message is $message"); | ||
100 | $join = ''; | ||
101 | ($code, $message) = $np->check_messages( | ||
102 | critical => [], warning => $arrays{warning}, | ||
103 | join => $join, | ||
104 | ); | ||
105 | is($message, join($join, @{$arrays{warning}}), "joined '$join' (warning) message is $message"); | ||
106 | $join = undef; | ||
107 | ($code, $message) = $np->check_messages( | ||
108 | critical => [], warning => [], ok => $arrays{ok}, | ||
109 | join => $join, | ||
110 | ); | ||
111 | is($message, join(' ', @{$arrays{ok}}), "joined undef (ok) message is $message"); | ||
112 | |||
113 | # ------------------------------------------------------------------------- | ||
114 | # join_all messages | ||
115 | my $join_all = ' :: '; | ||
116 | my $msg_all_cwo = join($join_all, map { join(' ', @{$arrays{$_}}) } | ||
117 | qw(critical warning ok)); | ||
118 | my $msg_all_cw = join($join_all, map { join(' ', @{$arrays{$_}}) } | ||
119 | qw(critical warning)); | ||
120 | my $msg_all_wo = join($join_all, map { join(' ', @{$arrays{$_}}) } | ||
121 | qw(warning ok)); | ||
122 | |||
123 | # critical, warning, ok | ||
124 | ($code, $message) = $np->check_messages( | ||
125 | critical => $arrays{critical}, warning => $arrays{warning}, ok => $arrays{ok}, | ||
126 | join_all => $join_all, | ||
127 | ); | ||
128 | is($code, CRITICAL, "(critical, warning, ok) code is $STATUS_TEXT{$code}"); | ||
129 | is($message, $msg_all_cwo, "join_all '$join_all' (critical, warning, ok) message is $message"); | ||
130 | |||
131 | # critical, warning, $ok | ||
132 | ($code, $message) = $np->check_messages( | ||
133 | critical => $arrays{critical}, warning => $arrays{warning}, ok => 'G H I', | ||
134 | join_all => $join_all, | ||
135 | ); | ||
136 | is($code, CRITICAL, "(critical, warning, \$ok) code is $STATUS_TEXT{$code}"); | ||
137 | is($message, $msg_all_cwo, "join_all '$join_all' (critical, warning, \$ok) message is $message"); | ||
138 | |||
139 | # critical, warning | ||
140 | ($code, $message) = $np->check_messages( | ||
141 | critical => $arrays{critical}, warning => $arrays{warning}, | ||
142 | join_all => $join_all, | ||
143 | ); | ||
144 | is($code, CRITICAL, "(critical, warning) code is $STATUS_TEXT{$code}"); | ||
145 | is($message, $msg_all_cw, "join_all '$join_all' (critical, warning) message is $message"); | ||
146 | |||
147 | # warning, ok | ||
148 | ($code, $message) = $np->check_messages( | ||
149 | critical => [], warning => $arrays{warning}, ok => $arrays{ok}, | ||
150 | join_all => $join_all, | ||
151 | ); | ||
152 | is($code, WARNING, "(warning, ok) code is $STATUS_TEXT{$code}"); | ||
153 | is($message, $msg_all_wo, "join_all '$join_all' (critical, warning, ok) message is $message"); | ||
154 | |||
155 | # warning, $ok | ||
156 | ($code, $message) = $np->check_messages( | ||
157 | critical => [], warning => $arrays{warning}, ok => 'G H I', | ||
158 | join_all => $join_all, | ||
159 | ); | ||
160 | is($code, WARNING, "(warning, \$ok) code is $STATUS_TEXT{$code}"); | ||
161 | is($message, $msg_all_wo, "join_all '$join_all' (critical, warning, \$ok) message is $message"); | ||
162 | |||
163 | # warning | ||
164 | ($code, $message) = $np->check_messages( | ||
165 | critical => [], warning => $arrays{warning}, | ||
166 | join_all => $join_all, | ||
167 | ); | ||
168 | is($code, WARNING, "(warning) code is $STATUS_TEXT{$code}"); | ||
169 | is($message, 'D E F', "join_all '$join_all' (critical, warning) message is $message"); | ||
170 | |||
171 | # ------------------------------------------------------------------------- | ||
172 | # add_messages | ||
173 | |||
174 | # Constant codes | ||
175 | $np = Monitoring::Plugin->new(); | ||
176 | $np->add_message( CRITICAL, "A B C" ); | ||
177 | $np->add_message( WARNING, "D E F" ); | ||
178 | ($code, $message) = $np->check_messages(); | ||
179 | is($code, CRITICAL, "(CRITICAL, WARNING) code is $STATUS_TEXT{$code}"); | ||
180 | is($message, $messages{critical}, "(CRITICAL, WARNING) message is $message"); | ||
181 | |||
182 | $np = Monitoring::Plugin->new(); | ||
183 | $np->add_message( CRITICAL, "A B C" ); | ||
184 | ($code, $message) = $np->check_messages(); | ||
185 | is($code, CRITICAL, "(CRITICAL) code is $STATUS_TEXT{$code}"); | ||
186 | is($message, $messages{critical}, "(CRITICAL) message is $message"); | ||
187 | |||
188 | $np = Monitoring::Plugin->new(); | ||
189 | $np->add_message( WARNING, "D E F" ); | ||
190 | ($code, $message) = $np->check_messages(); | ||
191 | is($code, WARNING, "(WARNING) code is $STATUS_TEXT{$code}"); | ||
192 | is($message, $messages{warning}, "(WARNING) message is $message"); | ||
193 | |||
194 | $np = Monitoring::Plugin->new(); | ||
195 | $np->add_message( WARNING, "D E F" ); | ||
196 | $np->add_message( OK, "G H I" ); | ||
197 | ($code, $message) = $np->check_messages(); | ||
198 | is($code, WARNING, "(WARNING, OK) code is $STATUS_TEXT{$code}"); | ||
199 | is($message, $messages{warning}, "(WARNING, OK) message is $message"); | ||
200 | |||
201 | $np = Monitoring::Plugin->new(); | ||
202 | $np->add_message( OK, "G H I" ); | ||
203 | ($code, $message) = $np->check_messages(); | ||
204 | is($code, OK, "(OK) code is $STATUS_TEXT{$code}"); | ||
205 | is($message, $messages{ok}, "(OK) message is $message"); | ||
206 | |||
207 | |||
208 | # String codes | ||
209 | $np = Monitoring::Plugin->new(); | ||
210 | $np->add_message( critical => "A B C" ); | ||
211 | $np->add_message( warning => "D E F" ); | ||
212 | ($code, $message) = $np->check_messages(); | ||
213 | is($code, CRITICAL, "(critical, warning) code is $STATUS_TEXT{$code}"); | ||
214 | is($message, $messages{critical}, "(critical, warning) message is $message"); | ||
215 | |||
216 | $np = Monitoring::Plugin->new(); | ||
217 | $np->add_message( critical => "A B C" ); | ||
218 | ($code, $message) = $np->check_messages(); | ||
219 | is($code, CRITICAL, "(critical) code is $STATUS_TEXT{$code}"); | ||
220 | is($message, $messages{critical}, "(critical) message is $message"); | ||
221 | |||
222 | $np = Monitoring::Plugin->new(); | ||
223 | $np->add_message( warning => "D E F" ); | ||
224 | ($code, $message) = $np->check_messages(); | ||
225 | is($code, WARNING, "(warning) code is $STATUS_TEXT{$code}"); | ||
226 | is($message, $messages{warning}, "(warning) message is $message"); | ||
227 | |||
228 | $np = Monitoring::Plugin->new(); | ||
229 | $np->add_message( warning => "D E F" ); | ||
230 | $np->add_message( ok => "G H I" ); | ||
231 | ($code, $message) = $np->check_messages(); | ||
232 | is($code, WARNING, "(warning, ok) code is $STATUS_TEXT{$code}"); | ||
233 | is($message, $messages{warning}, "(warning, ok) message is $message"); | ||
234 | |||
235 | $np = Monitoring::Plugin->new(); | ||
236 | $np->add_message( ok => "G H I" ); | ||
237 | ($code, $message) = $np->check_messages(); | ||
238 | is($code, OK, "(ok) code is $STATUS_TEXT{$code}"); | ||
239 | is($message, $messages{ok}, "(ok) message is $message"); | ||
240 | |||
241 | |||
242 | # No add_message | ||
243 | $np = Monitoring::Plugin->new(); | ||
244 | ($code, $message) = $np->check_messages(); | ||
245 | is($code, OK, "() code is $STATUS_TEXT{$code}"); | ||
246 | is($message, '', "() message is ''"); | ||
247 | |||
248 | |||
249 | # ------------------------------------------------------------------------- | ||
250 | # Error conditions | ||
251 | |||
252 | # add_message errors | ||
253 | $np = Monitoring::Plugin->new(); | ||
254 | ok(! defined eval { $np->add_message( foobar => 'hi mum' ) }, | ||
255 | 'add_message dies on invalid code'); | ||
256 | ok(! defined eval { $np->add_message( OKAY => 'hi mum' ) }, | ||
257 | 'add_message dies on invalid code'); | ||
258 | # UNKNOWN and DEPENDENT error codes | ||
259 | ok(! defined eval { $np->add_message( unknown => 'hi mum' ) }, | ||
260 | 'add_message dies on UNKNOWN code'); | ||
261 | ok(! defined eval { $np->add_message( dependent => 'hi mum' ) }, | ||
262 | 'add_message dies on DEPENDENT code'); | ||