diff options
author | Gavin Carr <gonzai@users.sourceforge.net> | 2006-08-30 01:20:41 (GMT) |
---|---|---|
committer | Gavin Carr <gonzai@users.sourceforge.net> | 2006-08-30 01:20:41 (GMT) |
commit | a70a6ff5acf2a2b252328427293801ce0ff42888 (patch) | |
tree | 8d3b573f3abaaa68f4eec0cbae4afa739bdfb2a7 /t/Nagios-Plugin-Getopt-02.t | |
parent | 96933fd2e1f53aff9c9ef26639fafe9a84ec754e (diff) | |
download | monitoring-plugin-perl-a70a6ff5acf2a2b252328427293801ce0ff42888.tar.gz |
Add first-pass Nagios::Plugin::Getopt.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1470 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 't/Nagios-Plugin-Getopt-02.t')
-rw-r--r-- | t/Nagios-Plugin-Getopt-02.t | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/t/Nagios-Plugin-Getopt-02.t b/t/Nagios-Plugin-Getopt-02.t new file mode 100644 index 0000000..26e0293 --- /dev/null +++ b/t/Nagios-Plugin-Getopt-02.t | |||
@@ -0,0 +1,61 @@ | |||
1 | # Nagios::Plugin::Getopt timeout tests | ||
2 | |||
3 | use strict; | ||
4 | |||
5 | use Test::More tests => 14; | ||
6 | BEGIN { use_ok('Nagios::Plugin::Getopt') }; | ||
7 | |||
8 | my %PARAM = ( | ||
9 | version => '0.01', | ||
10 | url => 'http://www.openfusion.com.au/labs/nagios/', | ||
11 | blurb => 'This plugin tests various stuff.', | ||
12 | usage => "Usage: %s -H <host> -w <warning_threshold> | ||
13 | -c <critical threshold>", | ||
14 | plugin => 'test_plugin', | ||
15 | timeout => 18, | ||
16 | ); | ||
17 | |||
18 | sub setup | ||
19 | { | ||
20 | # Instantiate object | ||
21 | my $ng = Nagios::Plugin::Getopt->new(%PARAM); | ||
22 | ok($ng, 'constructor ok'); | ||
23 | return $ng; | ||
24 | } | ||
25 | |||
26 | my $ng; | ||
27 | |||
28 | # No args | ||
29 | @ARGV = qw(); | ||
30 | $ng = setup(); | ||
31 | $ng->getopts; | ||
32 | is($ng->timeout, 18, 'default timeout set to 18'); | ||
33 | |||
34 | # Check help message | ||
35 | @ARGV = ( '-h' ); | ||
36 | $ng = setup; | ||
37 | ok(! defined eval { $ng->getopts }, 'getopts died on help'); | ||
38 | like($@, qr/times out.*default: 18\b/i, 'help timeout changed to 18'); | ||
39 | |||
40 | # Explicit timeout | ||
41 | @ARGV = qw(--timeout=25 --verbose); | ||
42 | $ng = setup(); | ||
43 | $ng->getopts; | ||
44 | is($ng->timeout, 25, 'timeout changed to 25'); | ||
45 | |||
46 | # Explicit timeout | ||
47 | @ARGV = qw(-t10 --verbose); | ||
48 | $ng = setup(); | ||
49 | $ng->getopts; | ||
50 | is($ng->timeout, 10, 'timeout changed to 10'); | ||
51 | |||
52 | # Short timeout, test default timeout handler | ||
53 | @ARGV = qw(-t2 --verbose); | ||
54 | $ng = setup(); | ||
55 | $ng->getopts; | ||
56 | is($ng->timeout, 2, 'timeout changed to 2'); | ||
57 | alarm($ng->timeout); | ||
58 | # Loop | ||
59 | ok(! defined eval { 1 while 1 }, 'loop timed out'); | ||
60 | like($@, qr/UNKNOWN\b.*\btimed out/, 'default timeout handler ok'); | ||
61 | |||