1 #!/usr/bin/perl
2 use Test::More;
3 use strict;
4 use warnings;
6 if (! -e "./test_opts3") {
7 plan skip_all => "./test_opts3 not compiled - please install tap library and/or enable parse-ini to test";
8 }
10 # array of argument arrays
11 # - First value is the expected return code
12 # - 2nd value is the NAGIOS_CONFIG_PATH
13 # TODO: looks like we look in default path after looking trough this variable - shall we?
14 # - 3rd value is the plugin name
15 # - 4th and up are arguments
16 my @TESTS = (
17 [3, '/nonexistent', 'prog_name', 'arg1', '--extra-opts', '--arg3', 'val2'],
18 [3, '.', 'prog_name', 'arg1', '--extra-opts=missing@./config-opts.ini', '--arg3', 'val2'],
19 [3, '', 'prog_name', 'arg1', '--extra-opts', 'missing@./config-opts.ini', '--arg3', 'val2'],
20 [3, '.', 'check_missing', 'arg1', '--extra-opts=@./config-opts.ini', '--arg3', 'val2'],
21 [3, '.', 'check_missing', 'arg1', '--extra-opts', '--arg3', 'val2'],
22 [0, '/tmp:/var:/nonexistent:.', 'check_tcp', 'arg1', '--extra-opts', '--arg3', 'val2'],
23 [0, '/usr/local/nagios/etc:.:/etc', 'check_missing', 'arg1', '--extra-opts=check_tcp', '--arg3', 'val2'],
24 );
26 plan tests => scalar(@TESTS);
28 my $count=1;
30 foreach my $args (@TESTS) {
31 my $rc = shift(@$args);
32 if (my $env = shift(@$args)) {
33 $ENV{"NAGIOS_CONFIG_PATH"} = $env;
34 } else {
35 delete($ENV{"NAGIOS_CONFIG_PATH"});
36 }
37 system {'./test_opts3'} @$args;
38 cmp_ok($?>>8, '==', $rc, "Extra-opts die " . $count++);
39 }