summaryrefslogtreecommitdiffstats
path: root/t/Nagios-Plugin-Getopt-02.t
diff options
context:
space:
mode:
authorGavin Carr <gonzai@users.sourceforge.net>2006-08-30 01:20:41 (GMT)
committerGavin Carr <gonzai@users.sourceforge.net>2006-08-30 01:20:41 (GMT)
commita70a6ff5acf2a2b252328427293801ce0ff42888 (patch)
tree8d3b573f3abaaa68f4eec0cbae4afa739bdfb2a7 /t/Nagios-Plugin-Getopt-02.t
parent96933fd2e1f53aff9c9ef26639fafe9a84ec754e (diff)
downloadmonitoring-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.t61
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
3use strict;
4
5use Test::More tests => 14;
6BEGIN { use_ok('Nagios::Plugin::Getopt') };
7
8my %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
18sub setup
19{
20 # Instantiate object
21 my $ng = Nagios::Plugin::Getopt->new(%PARAM);
22 ok($ng, 'constructor ok');
23 return $ng;
24}
25
26my $ng;
27
28# No args
29@ARGV = qw();
30$ng = setup();
31$ng->getopts;
32is($ng->timeout, 18, 'default timeout set to 18');
33
34# Check help message
35@ARGV = ( '-h' );
36$ng = setup;
37ok(! defined eval { $ng->getopts }, 'getopts died on help');
38like($@, 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;
44is($ng->timeout, 25, 'timeout changed to 25');
45
46# Explicit timeout
47@ARGV = qw(-t10 --verbose);
48$ng = setup();
49$ng->getopts;
50is($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;
56is($ng->timeout, 2, 'timeout changed to 2');
57alarm($ng->timeout);
58# Loop
59ok(! defined eval { 1 while 1 }, 'loop timed out');
60like($@, qr/UNKNOWN\b.*\btimed out/, 'default timeout handler ok');
61