diff options
Diffstat (limited to 't')
| -rw-r--r-- | t/Nagios-Plugin-01.t (renamed from t/Nagios-Plugin.t) | 0 | ||||
| -rw-r--r-- | t/Nagios-Plugin-02.t | 148 | ||||
| -rw-r--r-- | t/Nagios-Plugin-03.t | 263 | 
3 files changed, 411 insertions, 0 deletions
diff --git a/t/Nagios-Plugin.t b/t/Nagios-Plugin-01.t index 0ae2113..0ae2113 100644 --- a/t/Nagios-Plugin.t +++ b/t/Nagios-Plugin-01.t  | |||
diff --git a/t/Nagios-Plugin-02.t b/t/Nagios-Plugin-02.t new file mode 100644 index 0000000..8f25cff --- /dev/null +++ b/t/Nagios-Plugin-02.t  | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | |||
| 2 | use strict; | ||
| 3 | use Test::More tests => 101; | ||
| 4 | |||
| 5 | BEGIN { use_ok("Nagios::Plugin") } | ||
| 6 | require Nagios::Plugin::Functions; | ||
| 7 | Nagios::Plugin::Functions::_fake_exit(1); | ||
| 8 | |||
| 9 | # Hardcoded checks of constants | ||
| 10 | my %ERRORS = %Nagios::Plugin::Functions::ERRORS; | ||
| 11 | is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}"); | ||
| 12 | is(WARNING, $ERRORS{WARNING}, "WARNING => $ERRORS{WARNING}"); | ||
| 13 | is(CRITICAL, $ERRORS{CRITICAL}, "CRITICAL => $ERRORS{CRITICAL}"); | ||
| 14 | is(UNKNOWN, $ERRORS{UNKNOWN}, "UNKNOWN => $ERRORS{UNKNOWN}"); | ||
| 15 | is(DEPENDENT, $ERRORS{DEPENDENT}, "DEPENDENT => $ERRORS{DEPENDENT}"); | ||
| 16 | |||
| 17 | my $plugin = 'TEST_PLUGIN'; | ||
| 18 | my $np = Nagios::Plugin->new( shortname => $plugin ); | ||
| 19 | is($np->shortname, $plugin, "shortname() is $plugin"); | ||
| 20 | |||
| 21 | # Test nagios_exit( CONSTANT, $msg ), nagios_exit( $string, $msg ) | ||
| 22 | my $r; | ||
| 23 | my @ok = ( | ||
| 24 | [ OK, "OK", 'test the first', ], | ||
| 25 | [ WARNING, "WARNING", 'test the second', ], | ||
| 26 | [ CRITICAL, "CRITICAL", 'test the third', ], | ||
| 27 | [ UNKNOWN, "UNKNOWN", 'test the fourth', ], | ||
| 28 | [ DEPENDENT, "DEPENDENT", 'test the fifth', ], | ||
| 29 | ); | ||
| 30 | for (@ok) { | ||
| 31 | # CONSTANT | ||
| 32 | $r = $np->nagios_exit($_->[0], $_->[2]); | ||
| 33 | is($r->return_code, $_->[0], | ||
| 34 | sprintf('nagios_exit(%s, $msg) returned %s', $_->[1], $_->[0])); | ||
| 35 | like($r->message, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/, | ||
| 36 | sprintf('nagios_exit(%s, $msg) output matched "%s"', $_->[1], | ||
| 37 | $plugin . ' ' . $_->[1] . '.*' . $_->[2])); | ||
| 38 | |||
| 39 | # $string | ||
| 40 | $r = $np->nagios_exit($_->[1], $_->[2]); | ||
| 41 | is($r->return_code, $_->[0], | ||
| 42 | sprintf('nagios_exit("%s", $msg) returned %s', $_->[1], $_->[0])); | ||
| 43 | like($r->message, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/, | ||
| 44 | sprintf('nagios_exit("%s", $msg) output matched "%s"', $_->[1], | ||
| 45 | $plugin . ' ' . $_->[1] . '.*' . $_->[2])); | ||
| 46 | like($r, qr/$plugin\b.*$_->[1]\b.*\b$_->[2]$/, | ||
| 47 | sprintf('nagios_exit("%s", $msg) stringified matched "%s"', $_->[1], | ||
| 48 | $plugin . ' ' . $_->[1] . '.*' . $_->[2])); | ||
| 49 | } | ||
| 50 | |||
| 51 | # nagios_exit code corner cases | ||
| 52 | my @ugly1 = ( | ||
| 53 | [ -1, 'testing code -1' ], | ||
| 54 | [ 7, 'testing code 7' ], | ||
| 55 | [ undef, 'testing code undef' ], | ||
| 56 | [ '', qq(testing code '') ], | ||
| 57 | [ 'string', qq(testing code 'string') ], | ||
| 58 | ); | ||
| 59 | for (@ugly1) { | ||
| 60 | $r = $np->nagios_exit($_->[0], $_->[1]); | ||
| 61 | my $display = defined $_->[0] ? "'$_->[0]'" : 'undef'; | ||
| 62 | is($r->return_code, UNKNOWN, "nagios_exit($display, \$msg) returned ". UNKNOWN); | ||
| 63 | like($r->message, qr/UNKNOWN\b.*\b$_->[1]$/, | ||
| 64 | sprintf('nagios_exit(%s, $msg) output matched "%s"', | ||
| 65 | $display, 'UNKNOWN.*' . $_->[1])); | ||
| 66 | } | ||
| 67 | |||
| 68 | # nagios_exit message corner cases | ||
| 69 | my @ugly2 = ( | ||
| 70 | [ '' ], | ||
| 71 | [ undef ], | ||
| 72 | [ UNKNOWN ], | ||
| 73 | ); | ||
| 74 | for (@ugly2) { | ||
| 75 | $r = $np->nagios_exit(CRITICAL, $_->[0]); | ||
| 76 | my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef"; | ||
| 77 | my $display2 = defined $_->[0] ? $_->[0] : ''; | ||
| 78 | like($r->message, qr/CRITICAL\b.*\b$display2$/, | ||
| 79 | sprintf('nagios_exit(%s, $msg) output matched "%s"', | ||
| 80 | $display1, "CRITICAL.*$display2")); | ||
| 81 | } | ||
| 82 | |||
| 83 | # Test nagios_die( $msg ) | ||
| 84 | my @msg = ( | ||
| 85 | [ 'die you dog' ], | ||
| 86 | [ '' ], | ||
| 87 | [ undef ], | ||
| 88 | ); | ||
| 89 | for (@msg) { | ||
| 90 | $r = $np->nagios_die($_->[0]); | ||
| 91 | my $display1 = defined $_->[0] ? "'$_->[0]'" : "undef"; | ||
| 92 | my $display2 = defined $_->[0] ? $_->[0] : ''; | ||
| 93 | is($r->return_code, UNKNOWN, | ||
| 94 | sprintf('nagios_die(%s) returned UNKNOWN', $display1)); | ||
| 95 | like($r->message, qr/UNKNOWN\b.*\b$display2$/, | ||
| 96 | sprintf('nagios_die(%s) output matched "%s"', $display1, | ||
| 97 | "UNKNOWN.*$display2")); | ||
| 98 | } | ||
| 99 | |||
| 100 | # Test nagios_die( CONSTANT, $msg ), nagios_die( $msg, CONSTANT ), | ||
| 101 | # nagios_die( $string, $msg ), and nagios_die( $msg, $string ) | ||
| 102 | @ok = ( | ||
| 103 | [ OK, "OK", 'test the first', ], | ||
| 104 | [ WARNING, "WARNING", 'test the second', ], | ||
| 105 | [ CRITICAL, "CRITICAL", 'test the third', ], | ||
| 106 | [ UNKNOWN, "UNKNOWN", 'test the fourth', ], | ||
| 107 | [ DEPENDENT, "DEPENDENT", 'test the fifth', ], | ||
| 108 | ); | ||
| 109 | for (@ok) { | ||
| 110 | # CONSTANT, $msg | ||
| 111 | $r = $np->nagios_die($_->[0], $_->[2]); | ||
| 112 | is($r->return_code, $_->[0], | ||
| 113 | sprintf('nagios_die(%s, $msg) returned %s', $_->[1], $_->[0])); | ||
| 114 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
| 115 | sprintf('nagios_die(%s, $msg) output matched "%s"', | ||
| 116 | $_->[1], $_->[1] . '.*' . $_->[2])); | ||
| 117 | |||
| 118 | # $msg, CONSTANT | ||
| 119 | $r = $np->nagios_die($_->[2], $_->[0]); | ||
| 120 | is($r->return_code, $_->[0], | ||
| 121 | sprintf('nagios_die($msg, %s) returned %s', $_->[1], $_->[0])); | ||
| 122 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
| 123 | sprintf('nagios_die($msg, %s) output matched "%s"', | ||
| 124 | $_->[1], $_->[1] . '.*' . $_->[2])); | ||
| 125 | |||
| 126 | # $string, $msg | ||
| 127 | $r = $np->nagios_die($_->[1], $_->[2]); | ||
| 128 | is($r->return_code, $_->[0], | ||
| 129 | sprintf('nagios_die("%s", $msg) returned %s', $_->[1], $_->[0])); | ||
| 130 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
| 131 | sprintf('nagios_die("%s", $msg) output matched "%s"', $_->[1], | ||
| 132 | $_->[1] . '.*' . $_->[2])); | ||
| 133 | like($r, qr/$_->[1]\b.*\b$_->[2]$/, | ||
| 134 | sprintf('nagios_die("%s", $msg) stringified matched "%s"', $_->[1], | ||
| 135 | $_->[1] . '.*' . $_->[2])); | ||
| 136 | |||
| 137 | # $string, $msg | ||
| 138 | $r = $np->nagios_die($_->[2], $_->[1]); | ||
| 139 | is($r->return_code, $_->[0], | ||
| 140 | sprintf('nagios_die($msg, "%s") returned %s', $_->[1], $_->[0])); | ||
| 141 | like($r->message, qr/$_->[1]\b.*\b$_->[2]$/, | ||
| 142 | sprintf('nagios_die($msg, "%s") output matched "%s"', $_->[1], | ||
| 143 | $_->[1] . '.*' . $_->[2])); | ||
| 144 | like($r, qr/$_->[1]\b.*\b$_->[2]$/, | ||
| 145 | sprintf('nagios_die($msg, "%s") stringified matched "%s"', $_->[1], | ||
| 146 | $_->[1] . '.*' . $_->[2])); | ||
| 147 | } | ||
| 148 | |||
diff --git a/t/Nagios-Plugin-03.t b/t/Nagios-Plugin-03.t new file mode 100644 index 0000000..0366156 --- /dev/null +++ b/t/Nagios-Plugin-03.t  | |||
| @@ -0,0 +1,263 @@ | |||
| 1 | # $np->check_messages tests | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use Test::More tests => 61; | ||
| 5 | |||
| 6 | BEGIN { | ||
| 7 | use_ok("Nagios::Plugin"); | ||
| 8 | use_ok("Nagios::Plugin::Functions", ":all"); | ||
| 9 | } | ||
| 10 | Nagios::Plugin::Functions::_fake_exit(1); | ||
| 11 | |||
| 12 | my $plugin = 'NP_CHECK_MESSAGES_03'; | ||
| 13 | my $np = Nagios::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 = Nagios::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 = Nagios::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 = Nagios::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 = Nagios::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 = Nagios::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 = Nagios::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 = Nagios::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 = Nagios::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 = Nagios::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 = Nagios::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 = Nagios::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 = Nagios::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'); | ||
| 263 | |||
