diff options
Diffstat (limited to 't')
-rw-r--r-- | t/Nagios-Plugin-Functions-01.t (renamed from t/Nagios-Plugin-Base.t) | 8 | ||||
-rw-r--r-- | t/Nagios-Plugin-Functions-02.t | 162 | ||||
-rw-r--r-- | t/Nagios-Plugin-Performance.t | 6 | ||||
-rw-r--r-- | t/Nagios-Plugin-Range.t | 10 | ||||
-rw-r--r-- | t/Nagios-Plugin-Threshold.t | 12 | ||||
-rw-r--r-- | t/Nagios-Plugin.t | 7 |
6 files changed, 186 insertions, 19 deletions
diff --git a/t/Nagios-Plugin-Base.t b/t/Nagios-Plugin-Functions-01.t index 68a02fe..7401945 100644 --- a/t/Nagios-Plugin-Base.t +++ b/t/Nagios-Plugin-Functions-01.t | |||
@@ -2,17 +2,17 @@ | |||
2 | use strict; | 2 | use strict; |
3 | use Test::More tests => 111; | 3 | use Test::More tests => 111; |
4 | 4 | ||
5 | BEGIN { use_ok("Nagios::Plugin::Base", ":all"); } | 5 | BEGIN { use_ok("Nagios::Plugin::Functions", ":all"); } |
6 | Nagios::Plugin::Base::_fake_exit(1); | 6 | Nagios::Plugin::Functions::_fake_exit(1); |
7 | 7 | ||
8 | my $this_version=$Nagios::Plugin::Base::VERSION; | 8 | my $this_version=$Nagios::Plugin::Functions::VERSION; |
9 | foreach my $m ("", qw(::Threshold ::Getopt ::Performance ::Range)) { | 9 | foreach my $m ("", qw(::Threshold ::Getopt ::Performance ::Range)) { |
10 | my $mod = "Nagios::Plugin$m"; | 10 | my $mod = "Nagios::Plugin$m"; |
11 | use_ok($mod); | 11 | use_ok($mod); |
12 | # Lots of hackery below. Easier to say $mod->VERSION, but this is probably a recent perl thing | 12 | # Lots of hackery below. Easier to say $mod->VERSION, but this is probably a recent perl thing |
13 | my $v = "$mod"."::VERSION"; | 13 | my $v = "$mod"."::VERSION"; |
14 | my $a = eval "\$$v"; | 14 | my $a = eval "\$$v"; |
15 | is($a, $this_version, "Version number for $mod the same as Base: $this_version"); | 15 | is($a, $this_version, "Version number for $mod the same as Functions: $this_version"); |
16 | } | 16 | } |
17 | 17 | ||
18 | # Hardcoded checks of constants | 18 | # Hardcoded checks of constants |
diff --git a/t/Nagios-Plugin-Functions-02.t b/t/Nagios-Plugin-Functions-02.t new file mode 100644 index 0000000..981e2eb --- /dev/null +++ b/t/Nagios-Plugin-Functions-02.t | |||
@@ -0,0 +1,162 @@ | |||
1 | # check_messages tests | ||
2 | |||
3 | use strict; | ||
4 | use Test::More tests => 33; | ||
5 | |||
6 | BEGIN { use_ok("Nagios::Plugin::Functions", ":all") } | ||
7 | |||
8 | my ($code, $message); | ||
9 | |||
10 | # ------------------------------------------------------------------------- | ||
11 | # Check codes | ||
12 | my @codes = ( | ||
13 | [ [ qw(Critical) ], [ qw(Warning) ], CRITICAL ], | ||
14 | [ [], [ qw(Warning) ], WARNING ], | ||
15 | [ [], [], OK ], | ||
16 | ); | ||
17 | my $i = 0; | ||
18 | for (@codes) { | ||
19 | $i++; | ||
20 | $code = check_messages( critical => $_->[0], warning => $_->[1] ); | ||
21 | is($code, $_->[2], "Code test $i returned $STATUS_TEXT{$_->[2]}"); | ||
22 | } | ||
23 | |||
24 | # ------------------------------------------------------------------------- | ||
25 | # Check messages | ||
26 | my %arrays = ( | ||
27 | critical => [ qw(A B C) ], | ||
28 | warning => [ qw(D E F) ], | ||
29 | ok => [ qw(G H I) ], | ||
30 | ); | ||
31 | my %messages = map { $_ => join(' ', @{$arrays{$_}}) } keys %arrays; | ||
32 | |||
33 | # critical, warning | ||
34 | ($code, $message) = check_messages( | ||
35 | critical => $arrays{critical}, warning => $arrays{warning}, | ||
36 | ); | ||
37 | is($code, CRITICAL, "(critical, warning) code is $STATUS_TEXT{$code}"); | ||
38 | is($message, $messages{critical}, "(critical, warning) message is $message"); | ||
39 | |||
40 | # critical, warning, ok | ||
41 | ($code, $message) = check_messages( | ||
42 | critical => $arrays{critical}, warning => $arrays{warning}, | ||
43 | ok => $arrays{ok}, | ||
44 | ); | ||
45 | is($code, CRITICAL, "(critical, warning, ok) code is $STATUS_TEXT{$code}"); | ||
46 | is($message, $messages{critical}, "(critical, warning, ok) message is $message"); | ||
47 | |||
48 | # critical, warning, $ok | ||
49 | ($code, $message) = check_messages( | ||
50 | critical => $arrays{critical}, warning => $arrays{warning}, | ||
51 | ok => 'G H I', | ||
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 | # warning | ||
57 | ($code, $message) = check_messages( | ||
58 | critical => [], warning => $arrays{warning}, | ||
59 | ); | ||
60 | is($code, WARNING, "(warning) code is $STATUS_TEXT{$code}"); | ||
61 | is($message, $messages{warning}, "(warning) message is $message"); | ||
62 | |||
63 | # warning, ok | ||
64 | ($code, $message) = check_messages( | ||
65 | critical => [], warning => $arrays{warning}, ok => $arrays{ok}, | ||
66 | ); | ||
67 | is($code, WARNING, "(warning, ok) code is $STATUS_TEXT{$code}"); | ||
68 | is($message, $messages{warning}, "(warning, ok) message is $message"); | ||
69 | |||
70 | # ok | ||
71 | ($code, $message) = check_messages( | ||
72 | critical => [], warning => [], ok => $arrays{ok}, | ||
73 | ); | ||
74 | is($code, OK, "(ok) code is $STATUS_TEXT{$code}"); | ||
75 | is($message, $messages{ok}, "(ok) message is $message"); | ||
76 | |||
77 | # $ok | ||
78 | ($code, $message) = check_messages( | ||
79 | critical => [], warning => [], ok => 'G H I', | ||
80 | ); | ||
81 | is($code, OK, "(\$ok) code is $STATUS_TEXT{$code}"); | ||
82 | is($message, $messages{ok}, "(\$ok) message is $message"); | ||
83 | |||
84 | # ------------------------------------------------------------------------- | ||
85 | # explicit join | ||
86 | my $join = '+'; | ||
87 | ($code, $message) = check_messages( | ||
88 | critical => $arrays{critical}, warning => $arrays{warning}, | ||
89 | join => $join, | ||
90 | ); | ||
91 | is($message, join($join, @{$arrays{critical}}), "joined '$join' (critical, warning) message is $message"); | ||
92 | $join = ''; | ||
93 | ($code, $message) = check_messages( | ||
94 | critical => [], warning => $arrays{warning}, | ||
95 | join => $join, | ||
96 | ); | ||
97 | is($message, join($join, @{$arrays{warning}}), "joined '$join' (warning) message is $message"); | ||
98 | $join = undef; | ||
99 | ($code, $message) = check_messages( | ||
100 | critical => [], warning => [], ok => $arrays{ok}, | ||
101 | join => $join, | ||
102 | ); | ||
103 | is($message, join(' ', @{$arrays{ok}}), "joined undef (ok) message is $message"); | ||
104 | |||
105 | # ------------------------------------------------------------------------- | ||
106 | # join_all messages | ||
107 | my $join_all = ' :: '; | ||
108 | my $msg_all_cwo = join($join_all, map { join(' ', @{$arrays{$_}}) } | ||
109 | qw(critical warning ok)); | ||
110 | my $msg_all_cw = join($join_all, map { join(' ', @{$arrays{$_}}) } | ||
111 | qw(critical warning)); | ||
112 | my $msg_all_wo = join($join_all, map { join(' ', @{$arrays{$_}}) } | ||
113 | qw(warning ok)); | ||
114 | |||
115 | # critical, warning, ok | ||
116 | ($code, $message) = check_messages( | ||
117 | critical => $arrays{critical}, warning => $arrays{warning}, ok => $arrays{ok}, | ||
118 | join_all => $join_all, | ||
119 | ); | ||
120 | is($code, CRITICAL, "(critical, warning, ok) code is $STATUS_TEXT{$code}"); | ||
121 | is($message, $msg_all_cwo, "join_all '$join_all' (critical, warning, ok) message is $message"); | ||
122 | |||
123 | # critical, warning, $ok | ||
124 | ($code, $message) = check_messages( | ||
125 | critical => $arrays{critical}, warning => $arrays{warning}, ok => 'G H I', | ||
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 | ||
132 | ($code, $message) = check_messages( | ||
133 | critical => $arrays{critical}, warning => $arrays{warning}, | ||
134 | join_all => $join_all, | ||
135 | ); | ||
136 | is($code, CRITICAL, "(critical, warning) code is $STATUS_TEXT{$code}"); | ||
137 | is($message, $msg_all_cw, "join_all '$join_all' (critical, warning) message is $message"); | ||
138 | |||
139 | # warning, ok | ||
140 | ($code, $message) = check_messages( | ||
141 | critical => [], warning => $arrays{warning}, ok => $arrays{ok}, | ||
142 | join_all => $join_all, | ||
143 | ); | ||
144 | is($code, WARNING, "(warning, ok) code is $STATUS_TEXT{$code}"); | ||
145 | is($message, $msg_all_wo, "join_all '$join_all' (critical, warning, ok) message is $message"); | ||
146 | |||
147 | # warning, $ok | ||
148 | ($code, $message) = check_messages( | ||
149 | critical => [], warning => $arrays{warning}, ok => 'G H I', | ||
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 | ||
156 | ($code, $message) = check_messages( | ||
157 | critical => [], warning => $arrays{warning}, | ||
158 | join_all => $join_all, | ||
159 | ); | ||
160 | is($code, WARNING, "(warning) code is $STATUS_TEXT{$code}"); | ||
161 | is($message, 'D E F', "join_all '$join_all' (critical, warning) message is $message"); | ||
162 | |||
diff --git a/t/Nagios-Plugin-Performance.t b/t/Nagios-Plugin-Performance.t index 1da3191..e0eb2f6 100644 --- a/t/Nagios-Plugin-Performance.t +++ b/t/Nagios-Plugin-Performance.t | |||
@@ -3,10 +3,10 @@ use strict; | |||
3 | use Test::More tests => 49; | 3 | use Test::More tests => 49; |
4 | BEGIN { use_ok('Nagios::Plugin::Performance') }; | 4 | BEGIN { use_ok('Nagios::Plugin::Performance') }; |
5 | 5 | ||
6 | diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n"; | 6 | diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; |
7 | 7 | ||
8 | use Nagios::Plugin::Base; | 8 | use Nagios::Plugin::Functions; |
9 | Nagios::Plugin::Base::_fake_exit(1); | 9 | Nagios::Plugin::Functions::_fake_exit(1); |
10 | 10 | ||
11 | my @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); | 11 | my @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); |
12 | cmp_ok( $p[0]->label, 'eq', "/", "label okay"); | 12 | cmp_ok( $p[0]->label, 'eq', "/", "label okay"); |
diff --git a/t/Nagios-Plugin-Range.t b/t/Nagios-Plugin-Range.t index f01518d..df5dbd5 100644 --- a/t/Nagios-Plugin-Range.t +++ b/t/Nagios-Plugin-Range.t | |||
@@ -2,13 +2,17 @@ | |||
2 | use strict; | 2 | use strict; |
3 | use Test::More qw(no_plan); #tests => 123; | 3 | use Test::More qw(no_plan); #tests => 123; |
4 | 4 | ||
5 | BEGIN { use_ok('Nagios::Plugin::Range') }; | 5 | BEGIN { |
6 | use_ok('Nagios::Plugin::Range'); | ||
7 | # Silence warnings unless TEST_VERBOSE is set | ||
8 | $SIG{__WARN__} = sub { warn $_[0] if $ENV{TEST_VERBOSE} }; | ||
9 | }; | ||
6 | 10 | ||
7 | diag "\nusing Nagios::Plugin::Range revision ". $Nagios::Plugin::Range::VERSION . "\n"; | 11 | diag "\nusing Nagios::Plugin::Range revision ". $Nagios::Plugin::Range::VERSION . "\n" if $ENV{TEST_VERBOSE}; |
8 | 12 | ||
9 | my $r; | 13 | my $r; |
10 | 14 | ||
11 | diag "'garbage in' checks -- you should see 7 invalid range definition warnings here:"; | 15 | diag "'garbage in' checks -- you should see 7 invalid range definition warnings here:" if $ENV{TEST_VERBOSE}; |
12 | 16 | ||
13 | foreach (qw( | 17 | foreach (qw( |
14 | : | 18 | : |
diff --git a/t/Nagios-Plugin-Threshold.t b/t/Nagios-Plugin-Threshold.t index 677c054..cdb8d77 100644 --- a/t/Nagios-Plugin-Threshold.t +++ b/t/Nagios-Plugin-Threshold.t | |||
@@ -4,7 +4,7 @@ use Test::More tests => 71; | |||
4 | #use Test::Exception; # broken for now so we don't need this. | 4 | #use Test::Exception; # broken for now so we don't need this. |
5 | BEGIN { | 5 | BEGIN { |
6 | use_ok('Nagios::Plugin::Threshold'); | 6 | use_ok('Nagios::Plugin::Threshold'); |
7 | use_ok('Nagios::Plugin::Base', ':all' ); | 7 | use_ok('Nagios::Plugin::Functions', ':all' ); |
8 | # Silence warnings unless TEST_VERBOSE is set | 8 | # Silence warnings unless TEST_VERBOSE is set |
9 | $SIG{__WARN__} = sub { warn $_[0] if $ENV{TEST_VERBOSE} }; | 9 | $SIG{__WARN__} = sub { warn $_[0] if $ENV{TEST_VERBOSE} }; |
10 | } | 10 | } |
@@ -12,7 +12,7 @@ BEGIN { | |||
12 | diag "\nusing Nagios::Plugin::Threshold revision ". $Nagios::Plugin::Threshold::VERSION . "\n" | 12 | diag "\nusing Nagios::Plugin::Threshold revision ". $Nagios::Plugin::Threshold::VERSION . "\n" |
13 | if $ENV{TEST_VERBOSE}; | 13 | if $ENV{TEST_VERBOSE}; |
14 | 14 | ||
15 | Nagios::Plugin::Base::_fake_exit(1); | 15 | Nagios::Plugin::Functions::_fake_exit(1); |
16 | 16 | ||
17 | diag "threshold: critical if > 80" if $ENV{TEST_VERBOSE}; | 17 | diag "threshold: critical if > 80" if $ENV{TEST_VERBOSE}; |
18 | my $t = Nagios::Plugin::Threshold->set_thresholds(critical => "80"); | 18 | my $t = Nagios::Plugin::Threshold->set_thresholds(critical => "80"); |
@@ -96,8 +96,8 @@ test_expected_statuses( $t, $expected ); | |||
96 | goto SKIP_DEATH; | 96 | goto SKIP_DEATH; |
97 | diag "threshold: test pure crap for arguments - default to OK." if $ENV{TEST_VERBOSE}; | 97 | diag "threshold: test pure crap for arguments - default to OK." if $ENV{TEST_VERBOSE}; |
98 | diag "you should see one invalid range definition warning and an UNKNOWN line here:\n"; | 98 | diag "you should see one invalid range definition warning and an UNKNOWN line here:\n"; |
99 | Nagios::Plugin::Base->print_on_die(1); | 99 | Nagios::Plugin::Functions->print_on_die(1); |
100 | Nagios::Plugin::Base->exit_on_die(1); | 100 | Nagios::Plugin::Functions->exit_on_die(1); |
101 | 101 | ||
102 | dies_ok( sub { | 102 | dies_ok( sub { |
103 | $t = Nagios::Plugin::Threshold->set_thresholds( | 103 | $t = Nagios::Plugin::Threshold->set_thresholds( |
@@ -106,8 +106,8 @@ dies_ok( sub { | |||
106 | ) | 106 | ) |
107 | }, "bad thresholds cause death" | 107 | }, "bad thresholds cause death" |
108 | ); | 108 | ); |
109 | Nagios::Plugin::Base->print_on_die(0); | 109 | Nagios::Plugin::Functions->print_on_die(0); |
110 | Nagios::Plugin::Base->exit_on_die(0); | 110 | Nagios::Plugin::Functions->exit_on_die(0); |
111 | SKIP_DEATH: | 111 | SKIP_DEATH: |
112 | 112 | ||
113 | 113 | ||
diff --git a/t/Nagios-Plugin.t b/t/Nagios-Plugin.t index 213e514..0ae2113 100644 --- a/t/Nagios-Plugin.t +++ b/t/Nagios-Plugin.t | |||
@@ -4,10 +4,11 @@ use Test::More tests => 12; | |||
4 | 4 | ||
5 | BEGIN { use_ok('Nagios::Plugin') }; | 5 | BEGIN { use_ok('Nagios::Plugin') }; |
6 | 6 | ||
7 | use Nagios::Plugin::Base; | 7 | use Nagios::Plugin::Functions; |
8 | Nagios::Plugin::Base::_fake_exit(1); | 8 | Nagios::Plugin::Functions::_fake_exit(1); |
9 | 9 | ||
10 | diag "\nusing Nagios::Plugin revision ". $Nagios::Plugin::VERSION . "\n"; | 10 | diag "\nusing Nagios::Plugin revision ". $Nagios::Plugin::VERSION . "\n" |
11 | if $ENV{TEST_VERBOSE}; | ||
11 | 12 | ||
12 | my $p = Nagios::Plugin->new; | 13 | my $p = Nagios::Plugin->new; |
13 | isa_ok( $p, "Nagios::Plugin"); | 14 | isa_ok( $p, "Nagios::Plugin"); |