summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorGavin Carr <gonzai@users.sourceforge.net>2006-09-26 01:10:23 (GMT)
committerGavin Carr <gonzai@users.sourceforge.net>2006-09-26 01:10:23 (GMT)
commite548a22a92b3aa345f4a952fddb39cc693c35a70 (patch)
tree606e3872d3070a90b5fa9881303eddb59efc8bbd /t
parentd8f912e8f5abb1476366cfea6e0fb368a9669ec4 (diff)
downloadmonitoring-plugin-perl-e548a22a92b3aa345f4a952fddb39cc693c35a70.tar.gz
Rename NP::Base to NP::Functions; add check_messages() to NP::Functions.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1482 f882894a-f735-0410-b71e-b25c423dba1c
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.t162
-rw-r--r--t/Nagios-Plugin-Performance.t6
-rw-r--r--t/Nagios-Plugin-Range.t10
-rw-r--r--t/Nagios-Plugin-Threshold.t12
-rw-r--r--t/Nagios-Plugin.t7
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 @@
2use strict; 2use strict;
3use Test::More tests => 111; 3use Test::More tests => 111;
4 4
5BEGIN { use_ok("Nagios::Plugin::Base", ":all"); } 5BEGIN { use_ok("Nagios::Plugin::Functions", ":all"); }
6Nagios::Plugin::Base::_fake_exit(1); 6Nagios::Plugin::Functions::_fake_exit(1);
7 7
8my $this_version=$Nagios::Plugin::Base::VERSION; 8my $this_version=$Nagios::Plugin::Functions::VERSION;
9foreach my $m ("", qw(::Threshold ::Getopt ::Performance ::Range)) { 9foreach 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
3use strict;
4use Test::More tests => 33;
5
6BEGIN { use_ok("Nagios::Plugin::Functions", ":all") }
7
8my ($code, $message);
9
10# -------------------------------------------------------------------------
11# Check codes
12my @codes = (
13 [ [ qw(Critical) ], [ qw(Warning) ], CRITICAL ],
14 [ [], [ qw(Warning) ], WARNING ],
15 [ [], [], OK ],
16);
17my $i = 0;
18for (@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
26my %arrays = (
27 critical => [ qw(A B C) ],
28 warning => [ qw(D E F) ],
29 ok => [ qw(G H I) ],
30);
31my %messages = map { $_ => join(' ', @{$arrays{$_}}) } keys %arrays;
32
33# critical, warning
34($code, $message) = check_messages(
35 critical => $arrays{critical}, warning => $arrays{warning},
36);
37is($code, CRITICAL, "(critical, warning) code is $STATUS_TEXT{$code}");
38is($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);
45is($code, CRITICAL, "(critical, warning, ok) code is $STATUS_TEXT{$code}");
46is($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);
53is($code, CRITICAL, "(critical, warning, \$ok) code is $STATUS_TEXT{$code}");
54is($message, $messages{critical}, "(critical, warning, \$ok) message is $message");
55
56# warning
57($code, $message) = check_messages(
58 critical => [], warning => $arrays{warning},
59);
60is($code, WARNING, "(warning) code is $STATUS_TEXT{$code}");
61is($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);
67is($code, WARNING, "(warning, ok) code is $STATUS_TEXT{$code}");
68is($message, $messages{warning}, "(warning, ok) message is $message");
69
70# ok
71($code, $message) = check_messages(
72 critical => [], warning => [], ok => $arrays{ok},
73);
74is($code, OK, "(ok) code is $STATUS_TEXT{$code}");
75is($message, $messages{ok}, "(ok) message is $message");
76
77# $ok
78($code, $message) = check_messages(
79 critical => [], warning => [], ok => 'G H I',
80);
81is($code, OK, "(\$ok) code is $STATUS_TEXT{$code}");
82is($message, $messages{ok}, "(\$ok) message is $message");
83
84# -------------------------------------------------------------------------
85# explicit join
86my $join = '+';
87($code, $message) = check_messages(
88 critical => $arrays{critical}, warning => $arrays{warning},
89 join => $join,
90);
91is($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);
97is($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);
103is($message, join(' ', @{$arrays{ok}}), "joined undef (ok) message is $message");
104
105# -------------------------------------------------------------------------
106# join_all messages
107my $join_all = ' :: ';
108my $msg_all_cwo = join($join_all, map { join(' ', @{$arrays{$_}}) }
109 qw(critical warning ok));
110my $msg_all_cw = join($join_all, map { join(' ', @{$arrays{$_}}) }
111 qw(critical warning));
112my $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);
120is($code, CRITICAL, "(critical, warning, ok) code is $STATUS_TEXT{$code}");
121is($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);
128is($code, CRITICAL, "(critical, warning, \$ok) code is $STATUS_TEXT{$code}");
129is($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);
136is($code, CRITICAL, "(critical, warning) code is $STATUS_TEXT{$code}");
137is($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);
144is($code, WARNING, "(warning, ok) code is $STATUS_TEXT{$code}");
145is($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);
152is($code, WARNING, "(warning, \$ok) code is $STATUS_TEXT{$code}");
153is($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);
160is($code, WARNING, "(warning) code is $STATUS_TEXT{$code}");
161is($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;
3use Test::More tests => 49; 3use Test::More tests => 49;
4BEGIN { use_ok('Nagios::Plugin::Performance') }; 4BEGIN { use_ok('Nagios::Plugin::Performance') };
5 5
6diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n"; 6diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE};
7 7
8use Nagios::Plugin::Base; 8use Nagios::Plugin::Functions;
9Nagios::Plugin::Base::_fake_exit(1); 9Nagios::Plugin::Functions::_fake_exit(1);
10 10
11my @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); 11my @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448");
12cmp_ok( $p[0]->label, 'eq', "/", "label okay"); 12cmp_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 @@
2use strict; 2use strict;
3use Test::More qw(no_plan); #tests => 123; 3use Test::More qw(no_plan); #tests => 123;
4 4
5BEGIN { use_ok('Nagios::Plugin::Range') }; 5BEGIN {
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
7diag "\nusing Nagios::Plugin::Range revision ". $Nagios::Plugin::Range::VERSION . "\n"; 11diag "\nusing Nagios::Plugin::Range revision ". $Nagios::Plugin::Range::VERSION . "\n" if $ENV{TEST_VERBOSE};
8 12
9my $r; 13my $r;
10 14
11diag "'garbage in' checks -- you should see 7 invalid range definition warnings here:"; 15diag "'garbage in' checks -- you should see 7 invalid range definition warnings here:" if $ENV{TEST_VERBOSE};
12 16
13foreach (qw( 17foreach (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.
5BEGIN { 5BEGIN {
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 {
12diag "\nusing Nagios::Plugin::Threshold revision ". $Nagios::Plugin::Threshold::VERSION . "\n" 12diag "\nusing Nagios::Plugin::Threshold revision ". $Nagios::Plugin::Threshold::VERSION . "\n"
13 if $ENV{TEST_VERBOSE}; 13 if $ENV{TEST_VERBOSE};
14 14
15Nagios::Plugin::Base::_fake_exit(1); 15Nagios::Plugin::Functions::_fake_exit(1);
16 16
17diag "threshold: critical if > 80" if $ENV{TEST_VERBOSE}; 17diag "threshold: critical if > 80" if $ENV{TEST_VERBOSE};
18my $t = Nagios::Plugin::Threshold->set_thresholds(critical => "80"); 18my $t = Nagios::Plugin::Threshold->set_thresholds(critical => "80");
@@ -96,8 +96,8 @@ test_expected_statuses( $t, $expected );
96goto SKIP_DEATH; 96goto SKIP_DEATH;
97diag "threshold: test pure crap for arguments - default to OK." if $ENV{TEST_VERBOSE}; 97diag "threshold: test pure crap for arguments - default to OK." if $ENV{TEST_VERBOSE};
98diag "you should see one invalid range definition warning and an UNKNOWN line here:\n"; 98diag "you should see one invalid range definition warning and an UNKNOWN line here:\n";
99Nagios::Plugin::Base->print_on_die(1); 99Nagios::Plugin::Functions->print_on_die(1);
100Nagios::Plugin::Base->exit_on_die(1); 100Nagios::Plugin::Functions->exit_on_die(1);
101 101
102dies_ok( sub { 102dies_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);
109Nagios::Plugin::Base->print_on_die(0); 109Nagios::Plugin::Functions->print_on_die(0);
110Nagios::Plugin::Base->exit_on_die(0); 110Nagios::Plugin::Functions->exit_on_die(0);
111SKIP_DEATH: 111SKIP_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
5BEGIN { use_ok('Nagios::Plugin') }; 5BEGIN { use_ok('Nagios::Plugin') };
6 6
7use Nagios::Plugin::Base; 7use Nagios::Plugin::Functions;
8Nagios::Plugin::Base::_fake_exit(1); 8Nagios::Plugin::Functions::_fake_exit(1);
9 9
10diag "\nusing Nagios::Plugin revision ". $Nagios::Plugin::VERSION . "\n"; 10diag "\nusing Nagios::Plugin revision ". $Nagios::Plugin::VERSION . "\n"
11 if $ENV{TEST_VERBOSE};
11 12
12my $p = Nagios::Plugin->new; 13my $p = Nagios::Plugin->new;
13isa_ok( $p, "Nagios::Plugin"); 14isa_ok( $p, "Nagios::Plugin");