diff options
Diffstat (limited to 'NPTest.pm')
| -rw-r--r-- | NPTest.pm | 51 |
1 files changed, 30 insertions, 21 deletions
| @@ -1,7 +1,7 @@ | |||
| 1 | package NPTest; | 1 | package NPTest; |
| 2 | 2 | ||
| 3 | # | 3 | # |
| 4 | # Helper Functions for testing Nagios Plugins | 4 | # Helper Functions for testing Monitoring Plugins |
| 5 | # | 5 | # |
| 6 | 6 | ||
| 7 | require Exporter; | 7 | require Exporter; |
| @@ -25,14 +25,14 @@ $VERSION = "1556."; # must be all one line, for MakeMaker | |||
| 25 | 25 | ||
| 26 | =head1 NAME | 26 | =head1 NAME |
| 27 | 27 | ||
| 28 | NPTest - Simplify the testing of Nagios Plugins | 28 | NPTest - Simplify the testing of Monitoring Plugins |
| 29 | 29 | ||
| 30 | =head1 DESCRIPTION | 30 | =head1 DESCRIPTION |
| 31 | 31 | ||
| 32 | This modules provides convenience functions to assist in the testing | 32 | This modules provides convenience functions to assist in the testing |
| 33 | of Nagios Plugins, making the testing code easier to read and write; | 33 | of Monitoring Plugins, making the testing code easier to read and write; |
| 34 | hopefully encouraging the development of a more complete test suite for | 34 | hopefully encouraging the development of a more complete test suite for |
| 35 | the Nagios Plugins. It is based on the patterns of testing seen in the | 35 | the Monitoring Plugins. It is based on the patterns of testing seen in the |
| 36 | 1.4.0 release, and continues to use the L<Test> module as the basis of | 36 | 1.4.0 release, and continues to use the L<Test> module as the basis of |
| 37 | testing. | 37 | testing. |
| 38 | 38 | ||
| @@ -92,7 +92,7 @@ Testing of results would be done in your test script, not in this module. | |||
| 92 | This function is obsolete. Use C<testCmd()> instead. | 92 | This function is obsolete. Use C<testCmd()> instead. |
| 93 | 93 | ||
| 94 | This function attempts to encompass the majority of test styles used | 94 | This function attempts to encompass the majority of test styles used |
| 95 | in testing Nagios Plugins. As each plug-in is a separate command, the | 95 | in testing Monitoring Plugins. As each plug-in is a separate command, the |
| 96 | typical tests we wish to perform are against the exit status of the | 96 | typical tests we wish to perform are against the exit status of the |
| 97 | command and the output (if any) it generated. Simplifying these tests | 97 | command and the output (if any) it generated. Simplifying these tests |
| 98 | into a single function call, makes the test harness easier to read and | 98 | into a single function call, makes the test harness easier to read and |
| @@ -132,7 +132,7 @@ of either C<Test::ok(...)> or C<Test::skip(...)>, so remember this | |||
| 132 | when counting the number of tests to place in the C<Test::plan(...)> | 132 | when counting the number of tests to place in the C<Test::plan(...)> |
| 133 | call. | 133 | call. |
| 134 | 134 | ||
| 135 | Many Nagios Plugins test network services, some of which may not be | 135 | Many Monitoring Plugins test network services, some of which may not be |
| 136 | present on all systems. To cater for this, C<checkCmd(...)> allows the | 136 | present on all systems. To cater for this, C<checkCmd(...)> allows the |
| 137 | tester to define exceptions based on the command's exit status. These | 137 | tester to define exceptions based on the command's exit status. These |
| 138 | exceptions are provided to skip tests if the test case developer | 138 | exceptions are provided to skip tests if the test case developer |
| @@ -199,7 +199,7 @@ Copyright (c) 2005 Peter Bray. All rights reserved. | |||
| 199 | 199 | ||
| 200 | This package is free software and is provided "as is" without express | 200 | This package is free software and is provided "as is" without express |
| 201 | or implied warranty. It may be used, redistributed and/or modified | 201 | or implied warranty. It may be used, redistributed and/or modified |
| 202 | under the same terms as the Nagios Plugins release. | 202 | under the same terms as the Monitoring Plugins release. |
| 203 | 203 | ||
| 204 | =cut | 204 | =cut |
| 205 | 205 | ||
| @@ -347,7 +347,7 @@ sub getTestParameter | |||
| 347 | } | 347 | } |
| 348 | 348 | ||
| 349 | # Set "none" if no terminal attached (eg, tinderbox build servers when new variables set) | 349 | # Set "none" if no terminal attached (eg, tinderbox build servers when new variables set) |
| 350 | return "" unless (-t STDERR); | 350 | return "" unless (-t STDIN); |
| 351 | 351 | ||
| 352 | my $userResponse = ""; | 352 | my $userResponse = ""; |
| 353 | 353 | ||
| @@ -438,7 +438,7 @@ sub LoadCache | |||
| 438 | 438 | ||
| 439 | chomp($fileContents); | 439 | chomp($fileContents); |
| 440 | my( $contentsRef ) = eval $fileContents; | 440 | my( $contentsRef ) = eval $fileContents; |
| 441 | %CACHE = %{$contentsRef}; | 441 | %CACHE = %{$contentsRef} if (defined($contentsRef)); |
| 442 | 442 | ||
| 443 | } | 443 | } |
| 444 | 444 | ||
| @@ -494,26 +494,35 @@ sub SetCacheFilename | |||
| 494 | 494 | ||
| 495 | sub DetermineTestHarnessDirectory | 495 | sub DetermineTestHarnessDirectory |
| 496 | { | 496 | { |
| 497 | my( $userSupplied ) = @_; | 497 | my( @userSupplied ) = @_; |
| 498 | my @dirs; | ||
| 498 | 499 | ||
| 499 | # User Supplied | 500 | # User Supplied |
| 500 | if ( defined( $userSupplied ) && $userSupplied ) | 501 | if ( @userSupplied > 0 ) |
| 501 | { | 502 | { |
| 502 | if ( -d $userSupplied ) | 503 | for my $u ( @userSupplied ) |
| 503 | { | 504 | { |
| 504 | return $userSupplied; | 505 | if ( -d $u ) |
| 505 | } | 506 | { |
| 506 | else | 507 | push ( @dirs, $u ); |
| 507 | { | 508 | } |
| 508 | return undef; # userSupplied is invalid -> FAIL | ||
| 509 | } | 509 | } |
| 510 | } | 510 | } |
| 511 | 511 | ||
| 512 | # Simple Case : "t" is a subdirectory of the current directory | 512 | # Simple Cases: "t" and tests are subdirectories of the current directory |
| 513 | if ( -d "./t" ) | 513 | if ( -d "./t" ) |
| 514 | { | 514 | { |
| 515 | return "./t"; | 515 | push ( @dirs, "./t"); |
| 516 | } | 516 | } |
| 517 | if ( -d "./tests" ) | ||
| 518 | { | ||
| 519 | push ( @dirs, "./tests"); | ||
| 520 | } | ||
| 521 | |||
| 522 | if ( @dirs > 0 ) | ||
| 523 | { | ||
| 524 | return @dirs; | ||
| 525 | } | ||
| 517 | 526 | ||
| 518 | # To be honest I don't understand which case satisfies the | 527 | # To be honest I don't understand which case satisfies the |
| 519 | # original code in test.pl : when $tstdir == `pwd` w.r.t. | 528 | # original code in test.pl : when $tstdir == `pwd` w.r.t. |
| @@ -526,7 +535,7 @@ sub DetermineTestHarnessDirectory | |||
| 526 | 535 | ||
| 527 | if ( $pwd =~ m|/t$| ) | 536 | if ( $pwd =~ m|/t$| ) |
| 528 | { | 537 | { |
| 529 | return $pwd; | 538 | push ( @dirs, $pwd ); |
| 530 | 539 | ||
| 531 | # The alternate that might work better is | 540 | # The alternate that might work better is |
| 532 | # chdir( ".." ); | 541 | # chdir( ".." ); |
| @@ -535,7 +544,7 @@ sub DetermineTestHarnessDirectory | |||
| 535 | # to be tested is in the current directory (ie "./check_disk ....") | 544 | # to be tested is in the current directory (ie "./check_disk ....") |
| 536 | } | 545 | } |
| 537 | 546 | ||
| 538 | return undef; | 547 | return @dirs; |
| 539 | } | 548 | } |
| 540 | 549 | ||
| 541 | sub TestsFrom | 550 | sub TestsFrom |
