diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2006-03-24 16:13:40 (GMT) |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2006-03-24 16:13:40 (GMT) |
commit | f6bfe34a3e3c8c46c2cb5fc728773c2f4b191c8f (patch) | |
tree | 21b284bdf8a01667e95f82ca7e74e8d738e3ce83 /plugins | |
parent | 8c3e7428ae21999e813b288c3d55d3870c9ef258 (diff) | |
download | monitoring-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.t | 59 | ||||
-rw-r--r-- | plugins/t/check_http.t | 22 |
2 files changed, 52 insertions, 29 deletions
diff --git a/plugins/t/check_hpjd.t b/plugins/t/check_hpjd.t index b749c77..2fe5600 100644 --- a/plugins/t/check_hpjd.t +++ b/plugins/t/check_hpjd.t | |||
@@ -6,37 +6,46 @@ | |||
6 | # | 6 | # |
7 | 7 | ||
8 | use strict; | 8 | use strict; |
9 | use Test; | 9 | use Test::More; |
10 | use NPTest; | 10 | use NPTest; |
11 | 11 | ||
12 | use vars qw($tests); | 12 | plan skip_all => "check_hpjd not compiled" unless (-x "check_hpjd"); |
13 | BEGIN {$tests = 5; plan tests => $tests} | 13 | |
14 | plan tests => 5; | ||
14 | 15 | ||
15 | my $successOutput = '/^Printer ok - /'; | 16 | my $successOutput = '/^Printer ok - /'; |
16 | my $failureOutput = '/Timeout: No [Rr]esponse from /'; | 17 | my $failureOutput = '/Timeout: No [Rr]esponse from /'; |
17 | 18 | ||
18 | my $host_tcp_hpjd = getTestParameter( "host_tcp_hpjd", "NP_HOST_TCP_HPJD", undef, | 19 | my $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" | |
21 | my $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 | 24 | my $host_nonresponsive = getTestParameter( | |
24 | my $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", | |
27 | my $t; | 28 | ); |
28 | 29 | ||
29 | if ( -x "./check_hpjd" ) | 30 | my $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 | |
35 | else | 36 | my $res; |
36 | { | 37 | |
37 | $t += skipMissingCmd( "./check_hpjd", $tests ); | 38 | SKIP: { |
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 | ||
40 | exit(0) if defined($Test::Harness::VERSION); | 45 | $res = NPTest->testCmd("./check_hpjd $host_nonresponsive"); |
41 | exit($tests - $t); | 46 | cmp_ok( $res->return_code, 'eq', 2, "Host not responding"); |
47 | like ( $res->output, $failureOutput, "Output OK" ); | ||
48 | |||
49 | $res = NPTest->testCmd("./check_hpjd $hostname_invalid"); | ||
50 | cmp_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 9b90fd0..24e4fd6 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t | |||
@@ -9,6 +9,8 @@ use strict; | |||
9 | use Test::More; | 9 | use Test::More; |
10 | use NPTest; | 10 | use NPTest; |
11 | 11 | ||
12 | plan tests => 12; | ||
13 | |||
12 | my $successOutput = '/OK.*HTTP.*second/'; | 14 | my $successOutput = '/OK.*HTTP.*second/'; |
13 | 15 | ||
14 | my $res; | 16 | my $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 | ||
28 | plan 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 | ); |
46 | cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" ); | 45 | cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" ); |
47 | like( $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 | ||
48 | like( $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 | ); |
52 | cmp_ok( $res->return_code, '==', 0, "Can read https for www.verisign.com" ); | 53 | cmp_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" ); | ||
56 | cmp_ok( $res->return_code, '==', 0, "Checking certificate for www.verisign.com"); | ||
57 | like ( $res->output, '/Certificate will expire on/', "Output OK" ); | ||
58 | my $saved_cert_output = $res->output; | ||
59 | |||
60 | $res = NPTest->testCmd( "./check_http -C 1 www.verisign.com" ); | ||
61 | cmp_ok( $res->output, 'eq', $saved_cert_output, "--ssl option automatically added"); | ||
62 | |||
63 | $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" ); | ||
64 | cmp_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 | ); |
57 | cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" ); | 69 | cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" ); |
70 | |||
71 | |||