summaryrefslogtreecommitdiffstats
path: root/plugins/tests
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2010-12-01 04:57:04 (GMT)
committerThomas Guyot-Sionnest <dermoth@aei.ca>2010-12-01 04:57:04 (GMT)
commitc49fed07c3837fb7590bd05d192d6b6f6c4ae5d4 (patch)
tree568936fcb453f6a00b96462cc987b93b0ea32158 /plugins/tests
parent5a2814a21bff07b87a7589ef19b63c9eecb8be9f (diff)
downloadmonitoring-plugins-c49fed07c3837fb7590bd05d192d6b6f6c4ae5d4.tar.gz
Fix minor test issues
My Test::More wouldn't print the total number of tests anymore, moving the plan at the top appears to fix it. At the same time I made check-http.t eval the special modules so it can skip the tests instead of failing.
Diffstat (limited to 'plugins/tests')
-rwxr-xr-xplugins/tests/check_http.t35
-rwxr-xr-xplugins/tests/check_snmp.t14
2 files changed, 28 insertions, 21 deletions
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index f03933b..74eff17 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -18,9 +18,24 @@ use Test::More;
18use NPTest; 18use NPTest;
19use FindBin qw($Bin); 19use FindBin qw($Bin);
20 20
21use HTTP::Daemon; 21my $common_tests = 66;
22use HTTP::Status; 22my $ssl_only_tests = 6;
23use HTTP::Response; 23# Check that all dependent modules are available
24eval {
25 require HTTP::Daemon;
26 require HTTP::Status;
27 require HTTP::Response;
28};
29
30if ($@) {
31 plan skip_all => "Missing required module for test: $@";
32} else {
33 if (-x "./check_http") {
34 plan tests => $common_tests * 2 + $ssl_only_tests;
35 } else {
36 plan skip_all => "No check_http compiled";
37 }
38}
24 39
25my $servers = { http => 0 }; # HTTP::Daemon should always be available 40my $servers = { http => 0 }; # HTTP::Daemon should always be available
26eval { require HTTP::Daemon::SSL }; 41eval { require HTTP::Daemon::SSL };
@@ -112,9 +127,9 @@ sub run_server {
112 $c->send_response("slow"); 127 $c->send_response("slow");
113 } elsif ($r->url->path eq "/method") { 128 } elsif ($r->url->path eq "/method") {
114 if ($r->method eq "DELETE") { 129 if ($r->method eq "DELETE") {
115 $c->send_error(RC_METHOD_NOT_ALLOWED); 130 $c->send_error(HTTP::Status->RC_METHOD_NOT_ALLOWED);
116 } elsif ($r->method eq "foo") { 131 } elsif ($r->method eq "foo") {
117 $c->send_error(RC_NOT_IMPLEMENTED); 132 $c->send_error(HTTP::Status->RC_NOT_IMPLEMENTED);
118 } else { 133 } else {
119 $c->send_status_line(200, $r->method); 134 $c->send_status_line(200, $r->method);
120 } 135 }
@@ -138,7 +153,7 @@ sub run_server {
138 delete($persist[1000]); 153 delete($persist[1000]);
139 next MAINLOOP; 154 next MAINLOOP;
140 } else { 155 } else {
141 $c->send_error(RC_FORBIDDEN); 156 $c->send_error(HTTP::Status->RC_FORBIDDEN);
142 } 157 }
143 $c->close; 158 $c->close;
144 } 159 }
@@ -157,14 +172,6 @@ if ($ARGV[0] && $ARGV[0] eq "-d") {
157 } 172 }
158} 173}
159 174
160my $common_tests = 66;
161my $ssl_only_tests = 6;
162if (-x "./check_http") {
163 plan tests => $common_tests * 2 + $ssl_only_tests;
164} else {
165 plan skip_all => "No check_http compiled";
166}
167
168my $result; 175my $result;
169my $command = "./check_http -H 127.0.0.1"; 176my $command = "./check_http -H 127.0.0.1";
170 177
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t
index c960f7b..b978a85 100755
--- a/plugins/tests/check_snmp.t
+++ b/plugins/tests/check_snmp.t
@@ -8,6 +8,7 @@ use Test::More;
8use NPTest; 8use NPTest;
9use FindBin qw($Bin); 9use FindBin qw($Bin);
10 10
11my $tests = 39;
11# Check that all dependent modules are available 12# Check that all dependent modules are available
12eval { 13eval {
13 require NetSNMP::OID; 14 require NetSNMP::OID;
@@ -17,6 +18,12 @@ eval {
17 18
18if ($@) { 19if ($@) {
19 plan skip_all => "Missing required module for test: $@"; 20 plan skip_all => "Missing required module for test: $@";
21} else {
22 if (-x "./check_snmp") {
23 plan tests => $tests;
24 } else {
25 plan skip_all => "No check_snmp compiled";
26 }
20} 27}
21 28
22my $port_snmp = 16100 + int(rand(100)); 29my $port_snmp = 16100 + int(rand(100));
@@ -54,13 +61,6 @@ if ($ARGV[0] && $ARGV[0] eq "-d") {
54# We should merge that with $ENV{'NPTEST_CACHE'}, use one dir for all test data 61# We should merge that with $ENV{'NPTEST_CACHE'}, use one dir for all test data
55$ENV{'NAGIOS_PLUGIN_STATE_DIRECTORY'} ||= "/var/tmp"; 62$ENV{'NAGIOS_PLUGIN_STATE_DIRECTORY'} ||= "/var/tmp";
56 63
57my $tests = 39;
58if (-x "./check_snmp") {
59 plan tests => $tests;
60} else {
61 plan skip_all => "No check_snmp compiled";
62}
63
64my $res; 64my $res;
65 65
66$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0"); 66$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0");