diff options
Diffstat (limited to 't/Nagios-Plugin-Getopt-02.t')
-rw-r--r-- | t/Nagios-Plugin-Getopt-02.t | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/t/Nagios-Plugin-Getopt-02.t b/t/Nagios-Plugin-Getopt-02.t deleted file mode 100644 index f83b180..0000000 --- a/t/Nagios-Plugin-Getopt-02.t +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
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 | # Needed to get evals to work in testing | ||
9 | Nagios::Plugin::Functions::_use_die(1); | ||
10 | |||
11 | my %PARAM = ( | ||
12 | version => '0.01', | ||
13 | url => 'http://www.openfusion.com.au/labs/nagios/', | ||
14 | blurb => 'This plugin tests various stuff.', | ||
15 | usage => "Usage: %s -H <host> -w <warning_threshold> | ||
16 | -c <critical threshold>", | ||
17 | plugin => 'test_plugin', | ||
18 | timeout => 18, | ||
19 | ); | ||
20 | |||
21 | sub setup | ||
22 | { | ||
23 | # Instantiate object | ||
24 | my $ng = Nagios::Plugin::Getopt->new(%PARAM); | ||
25 | ok($ng, 'constructor ok'); | ||
26 | return $ng; | ||
27 | } | ||
28 | |||
29 | my $ng; | ||
30 | |||
31 | # No args | ||
32 | @ARGV = qw(); | ||
33 | $ng = setup(); | ||
34 | $ng->getopts; | ||
35 | is($ng->timeout, 18, 'default timeout set to 18'); | ||
36 | |||
37 | # Check help message | ||
38 | @ARGV = ( '-h' ); | ||
39 | $ng = setup; | ||
40 | ok(! defined eval { $ng->getopts }, 'getopts died on help'); | ||
41 | like($@, qr/times out.*default: 18\b/i, 'help timeout changed to 18'); | ||
42 | |||
43 | # Explicit timeout | ||
44 | @ARGV = qw(--timeout=25 --verbose); | ||
45 | $ng = setup(); | ||
46 | $ng->getopts; | ||
47 | is($ng->timeout, 25, 'timeout changed to 25'); | ||
48 | |||
49 | # Explicit timeout | ||
50 | @ARGV = qw(-t10 --verbose); | ||
51 | $ng = setup(); | ||
52 | $ng->getopts; | ||
53 | is($ng->timeout, 10, 'timeout changed to 10'); | ||
54 | |||
55 | # Short timeout, test default timeout handler | ||
56 | @ARGV = qw(-t2 --verbose); | ||
57 | $ng = setup(); | ||
58 | $ng->getopts; | ||
59 | is($ng->timeout, 2, 'timeout changed to 2'); | ||
60 | alarm($ng->timeout); | ||
61 | # Loop | ||
62 | ok(! defined eval { 1 while 1 }, 'loop timed out'); | ||
63 | like($@, qr/UNKNOWN\b.*\btimed out/, 'default timeout handler ok'); | ||
64 | |||