summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2006-03-24 16:13:40 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2006-03-24 16:13:40 +0000
commitf6bfe34a3e3c8c46c2cb5fc728773c2f4b191c8f (patch)
tree21b284bdf8a01667e95f82ca7e74e8d738e3ce83 /plugins
parent8c3e7428ae21999e813b288c3d55d3870c9ef258 (diff)
downloadmonitoring-plugins-f6bfe34a3e3c8c46c2cb5fc728773c2f4b191c8f.tar.gz
Tests converted to new style
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1354 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/t/check_hpjd.t59
-rw-r--r--plugins/t/check_http.t22
2 files changed, 52 insertions, 29 deletions
diff --git a/plugins/t/check_hpjd.t b/plugins/t/check_hpjd.t
index b749c778..2fe56000 100644
--- a/plugins/t/check_hpjd.t
+++ b/plugins/t/check_hpjd.t
@@ -6,37 +6,46 @@
6# 6#
7 7
8use strict; 8use strict;
9use Test; 9use Test::More;
10use NPTest; 10use NPTest;
11 11
12use vars qw($tests); 12plan skip_all => "check_hpjd not compiled" unless (-x "check_hpjd");
13BEGIN {$tests = 5; plan tests => $tests} 13
14plan tests => 5;
14 15
15my $successOutput = '/^Printer ok - /'; 16my $successOutput = '/^Printer ok - /';
16my $failureOutput = '/Timeout: No [Rr]esponse from /'; 17my $failureOutput = '/Timeout: No [Rr]esponse from /';
17 18
18my $host_tcp_hpjd = getTestParameter( "host_tcp_hpjd", "NP_HOST_TCP_HPJD", undef, 19my $host_tcp_hpjd = getTestParameter(
19 "A host (usually a printer) providing the HP-JetDirect Services" ); 20 "NP_HOST_TCP_HPJD",
20 21 "A host (usually a printer) providing the HP-JetDirect Services"
21my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", 22 );
22 "The hostname of system not responsive to network requests" ); 23
23 24my $host_nonresponsive = getTestParameter(
24my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", 25 "NP_HOST_NONRESPONSIVE",
25 "An invalid (not known to DNS) hostname" ); 26 "The hostname of system not responsive to network requests",
26 27 "10.0.0.1",
27my $t; 28 );
28 29
29if ( -x "./check_hpjd" ) 30my $hostname_invalid = getTestParameter(
30{ 31 "NP_HOSTNAME_INVALID",
31 $t += checkCmd( "./check_hpjd $host_tcp_hpjd", 0, $successOutput ); 32 "An invalid (not known to DNS) hostname",
32 $t += checkCmd( "./check_hpjd $host_nonresponsive", 2, $failureOutput ); 33 "nosuchhost",
33 $t += checkCmd( "./check_hpjd $hostname_invalid", 3 ); 34 );
34} 35
35else 36my $res;
36{ 37
37 $t += skipMissingCmd( "./check_hpjd", $tests ); 38SKIP: {
39 skip "No HP JetDirect defined", 2 unless $host_tcp_hpjd;
40 $res = NPTest->testCmd("./check_hpjd $host_tcp_hpjd");
41 cmp_ok( $res->return_code, '==', 0, "Jetdirect responding" );
42 like ( $res->output, $successOutput, "Output correct" );
38} 43}
39 44
40exit(0) if defined($Test::Harness::VERSION); 45$res = NPTest->testCmd("./check_hpjd $host_nonresponsive");
41exit($tests - $t); 46cmp_ok( $res->return_code, 'eq', 2, "Host not responding");
47like ( $res->output, $failureOutput, "Output OK" );
48
49$res = NPTest->testCmd("./check_hpjd $hostname_invalid");
50cmp_ok( $res->return_code, 'eq', 3, "Hostname invalid");
42 51
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 9b90fd06..24e4fd6d 100644
--- a/plugins/t/check_http.t
+++ b/plugins/t/check_http.t
@@ -9,6 +9,8 @@ use strict;
9use Test::More; 9use Test::More;
10use NPTest; 10use NPTest;
11 11
12plan tests => 12;
13
12my $successOutput = '/OK.*HTTP.*second/'; 14my $successOutput = '/OK.*HTTP.*second/';
13 15
14my $res; 16my $res;
@@ -25,9 +27,6 @@ my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
25 "An invalid (not known to DNS) hostname", 27 "An invalid (not known to DNS) hostname",
26 "nosuchhost"); 28 "nosuchhost");
27 29
28plan tests => 8;
29
30
31$res = NPTest->testCmd( 30$res = NPTest->testCmd(
32 "./check_http $host_tcp_http -wt 300 -ct 600" 31 "./check_http $host_tcp_http -wt 300 -ct 600"
33 ); 32 );
@@ -44,14 +43,29 @@ $res = NPTest->testCmd(
44 "./check_http $hostname_invalid -wt 1 -ct 2" 43 "./check_http $hostname_invalid -wt 1 -ct 2"
45 ); 44 );
46cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" ); 45cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" );
47like( $res->output, "/Name or service not known.*/", "Output OK"); 46# The first part of the message comes from the OS catalogue, so cannot check this.
47# On Debian, it is Name or service not known, on Darwin, it is No address associated with nodename
48like( $res->output, "/Unable to open TCP socket/", "Output OK");
48 49
49$res = NPTest->testCmd( 50$res = NPTest->testCmd(
50 "./check_http --ssl www.verisign.com" 51 "./check_http --ssl www.verisign.com"
51 ); 52 );
52cmp_ok( $res->return_code, '==', 0, "Can read https for www.verisign.com" ); 53cmp_ok( $res->return_code, '==', 0, "Can read https for www.verisign.com" );
53 54
55$res = NPTest->testCmd( "./check_http -C 1 --ssl www.verisign.com" );
56cmp_ok( $res->return_code, '==', 0, "Checking certificate for www.verisign.com");
57like ( $res->output, '/Certificate will expire on/', "Output OK" );
58my $saved_cert_output = $res->output;
59
60$res = NPTest->testCmd( "./check_http -C 1 www.verisign.com" );
61cmp_ok( $res->output, 'eq', $saved_cert_output, "--ssl option automatically added");
62
63$res = NPTest->testCmd( "./check_http www.verisign.com -C 1" );
64cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works");
65
54$res = NPTest->testCmd( 66$res = NPTest->testCmd(
55 "./check_http --ssl www.e-paycobalt.com" 67 "./check_http --ssl www.e-paycobalt.com"
56 ); 68 );
57cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" ); 69cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" );
70
71