test_opts3.t 1.4 KB

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