diff options
| author | Sven Nierlein <sven@nierlein.de> | 2014-01-20 00:54:34 +0100 |
|---|---|---|
| committer | Sven Nierlein <sven@nierlein.de> | 2014-01-20 00:54:34 +0100 |
| commit | b418181dfe80dd75169b6e8a619ac1932155dea2 (patch) | |
| tree | cad9c0ae0eae8e800cfff60555ead06ad33c6856 /t/Monitoring-Plugin-Getopt-02.t | |
| parent | 1cd8d1c52cbd47121f344c4074aec84653f412ce (diff) | |
| download | monitoring-plugin-perl-b418181dfe80dd75169b6e8a619ac1932155dea2.tar.gz | |
renamed module into Monitoring::Plugin
since the complete monitoring team has been renamed, we
also rename this module.
Signed-off-by: Sven Nierlein <sven@nierlein.de>
Diffstat (limited to 't/Monitoring-Plugin-Getopt-02.t')
| -rw-r--r-- | t/Monitoring-Plugin-Getopt-02.t | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/t/Monitoring-Plugin-Getopt-02.t b/t/Monitoring-Plugin-Getopt-02.t new file mode 100644 index 0000000..c6c563e --- /dev/null +++ b/t/Monitoring-Plugin-Getopt-02.t | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | # Monitoring::Plugin::Getopt timeout tests | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | use Test::More tests => 14; | ||
| 6 | BEGIN { use_ok('Monitoring::Plugin::Getopt') }; | ||
| 7 | |||
| 8 | # Needed to get evals to work in testing | ||
| 9 | Monitoring::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 = Monitoring::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'); | ||
