summaryrefslogtreecommitdiffstats
path: root/t/Nagios-Plugin-Getopt-03.t
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.de>2014-01-19 23:54:34 (GMT)
committerSven Nierlein <sven@nierlein.de>2014-01-19 23:54:34 (GMT)
commitb418181dfe80dd75169b6e8a619ac1932155dea2 (patch)
treecad9c0ae0eae8e800cfff60555ead06ad33c6856 /t/Nagios-Plugin-Getopt-03.t
parent1cd8d1c52cbd47121f344c4074aec84653f412ce (diff)
downloadmonitoring-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/Nagios-Plugin-Getopt-03.t')
-rw-r--r--t/Nagios-Plugin-Getopt-03.t108
1 files changed, 0 insertions, 108 deletions
diff --git a/t/Nagios-Plugin-Getopt-03.t b/t/Nagios-Plugin-Getopt-03.t
deleted file mode 100644
index 560b782..0000000
--- a/t/Nagios-Plugin-Getopt-03.t
+++ /dev/null
@@ -1,108 +0,0 @@
1# Nagios::Plugin::Getopt --extra-opts tests
2
3use strict;
4use File::Spec;
5use File::Basename;
6use IO::File;
7
8use Test::More qw(no_plan);
9BEGIN { use_ok('Nagios::Plugin::Getopt') };
10
11# Needed to get evals to work in testing
12Nagios::Plugin::Functions::_use_die(1);
13
14my $tdir = 'npg03';
15if (! -d $tdir) {
16 my $ttdir = File::Spec->catdir('t', $tdir);
17 die "missing '$tdir' directory\n" unless -d $ttdir;
18 $tdir = $ttdir;
19}
20
21# Load expected files
22my %EXPECTED = ();
23for my $efile (glob File::Spec->catfile($tdir, 'expected', '*')) {
24 my $fh = IO::File->new($efile, 'r') or die "Cannot open input file '$efile': $!";
25 if (my $cmd = $fh->getline()) { # First line only!
26 chomp $cmd;
27 $cmd =~ s/^\s+//;
28 $cmd =~ s/\s+$//;
29 $EXPECTED{ basename($efile) } = $cmd;
30 }
31}
32
33# Override NAGIOS_CONFIG_PATH to use our test plugins.ini file
34$ENV{NAGIOS_CONFIG_PATH} = "/random/bogus/path:$tdir";
35
36my %PARAM = (
37 version => '0.01',
38 blurb => 'This plugin tests various stuff.',
39 usage => "Usage: %s -H <host> -w <warning_threshold>
40 -c <critical threshold>",
41);
42
43sub ng_setup
44{
45 my $arg = shift;
46
47 # Instantiate object
48 my $ng = Nagios::Plugin::Getopt->new(%PARAM);
49
50 if (ref $arg eq 'ARRAY' && @$arg) {
51 $ng->arg(%$_) foreach @$arg;
52 }
53
54 return $ng;
55}
56
57# Setup our Nagios::Plugin::Getopt object
58my $ng;
59my $arg = [
60 { spec => 'S', help => '-S' },
61 { spec => 'H=s', help => '-H' },
62 { spec => 'p=s@', help => '-p' },
63 { spec => 'path=s@', help => '--path' },
64 { spec => 'username|u=s', help => '--username' },
65 { spec => 'password=s', help => '--password' },
66 { spec => 'critical=s', help => '--critical' },
67 { spec => 'warning=s', help => '--warning' },
68 { spec => 'expect=s', help => '--expect' },
69 { spec => 'units=s', help => '--units' },
70];
71
72#my %SKIP = map { $_ => 1 } qw(05_singlechar1 07_singlechar3);
73#my %SKIP = map { $_ => 1 } qw(06_singlechar2);
74my %SKIP = ();
75
76# Process all test cases in $tdir/input
77my $glob = $ARGV[0] || '*';
78for my $infile (glob File::Spec->catfile($tdir, 'input', $glob)) {
79 $ng = ng_setup($arg);
80
81 my $fh = IO::File->new($infile, 'r') or die "Cannot open input file '$infile': $!";
82 $infile = basename($infile);
83
84 if (my $cmd = $fh->getline()) { # First line only!
85 $cmd =~ s/^\s+//;
86 my ($plugin, @args) = split /\s+/, $cmd;
87
88 # Fake out the plugin name
89 $ng->{_attr}->{plugin} = $plugin;
90
91 # Parse the options
92 SKIP: {
93 skip "Skipping ..." if $SKIP{$infile};
94
95 @ARGV = @args;
96 eval { $ng->getopts };
97 if ($@) {
98 chomp $@;
99 ok($infile =~ m/_(dies?|catch)$/, "$infile ($@)");
100 is($@, $EXPECTED{$infile}, $infile) if ($infile =~ m/_catch$/);
101 }
102 else {
103 is($plugin . ' ' . $ng->_cmdline, $EXPECTED{$infile}, $infile);
104 }
105 }
106 }
107}
108