diff options
-rw-r--r-- | plugins/t/check_ssh.t | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/plugins/t/check_ssh.t b/plugins/t/check_ssh.t new file mode 100644 index 0000000..8008349 --- /dev/null +++ b/plugins/t/check_ssh.t | |||
@@ -0,0 +1,49 @@ | |||
1 | #! /usr/bin/perl -w -I .. | ||
2 | # | ||
3 | # check_ssh tests | ||
4 | # | ||
5 | # | ||
6 | |||
7 | use strict; | ||
8 | use Test::More; | ||
9 | use NPTest; | ||
10 | |||
11 | # Required parameters | ||
12 | my $ssh_host = getTestParameter("NP_SSH_HOST", | ||
13 | "A host providing SSH service", | ||
14 | "localhost"); | ||
15 | |||
16 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", | ||
17 | "The hostname of system not responsive to network requests", | ||
18 | "10.0.0.1" ); | ||
19 | |||
20 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", | ||
21 | "An invalid (not known to DNS) hostname", | ||
22 | "nosuchhost" ); | ||
23 | |||
24 | |||
25 | plan skip_all => "SSH_HOST must be defined" unless $ssh_host; | ||
26 | plan tests => 6; | ||
27 | |||
28 | |||
29 | my $result = NPTest->testCmd( | ||
30 | "./check_ssh -H $ssh_host" | ||
31 | ); | ||
32 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); | ||
33 | like($result->output, '/^SSH OK - /', "Status text if command returned none (OK)"); | ||
34 | |||
35 | |||
36 | $result = NPTest->testCmd( | ||
37 | "./check_ssh -H $host_nonresponsive -t 2" | ||
38 | ); | ||
39 | cmp_ok($result->return_code, '==', 2, "Exit with return code 0 (OK)"); | ||
40 | like($result->output, '/^CRITICAL - Socket timeout after 2 seconds/', "Status text if command returned none (OK)"); | ||
41 | |||
42 | |||
43 | |||
44 | $result = NPTest->testCmd( | ||
45 | "./check_ssh -H $hostname_invalid -t 2" | ||
46 | ); | ||
47 | cmp_ok($result->return_code, '==', 3, "Exit with return code 0 (OK)"); | ||
48 | like($result->output, '/^check_ssh: Invalid hostname/', "Status text if command returned none (OK)"); | ||
49 | |||