Skip to content

Commit

Permalink
tests: fping checks require being root or setuid root
Browse files Browse the repository at this point in the history
on the fping binary. Check this before running the test.

Signed-off-by: Sven Nierlein <Sven.Nierlein@consol.de>
  • Loading branch information
sni committed Jun 13, 2014
1 parent fb89acc commit 93901d5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
29 changes: 26 additions & 3 deletions NPTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package NPTest;

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(getTestParameter checkCmd skipMissingCmd);
@EXPORT = qw(getTestParameter checkCmd skipMissingCmd skipMsg);
@EXPORT_OK = qw(DetermineTestHarnessDirectory TestsFrom SetCacheFilename);

use strict;
Expand Down Expand Up @@ -38,8 +38,8 @@ testing.
=head1 FUNCTIONS
This module defines three public functions, C<getTestParameter(...)>,
C<checkCmd(...)> and C<skipMissingCmd(...)>. These are exported by
This module defines four public functions, C<getTestParameter(...)>,
C<checkCmd(...)>, C<skipMissingCmd(...)> and C<skipMsg(...)>. These are exported by
default via the C<use NPTest;> statement.
=over
Expand Down Expand Up @@ -185,6 +185,15 @@ of times.
=back
=item C<skipMsg(...)>
If for any reason the test harness must C<Test::skip()> some
or all of the tests in a given test harness this function provides a
simple iterator to issue an appropriate message the requested number
of times.
=back
=head1 SEE ALSO
L<Test>
Expand Down Expand Up @@ -304,6 +313,20 @@ sub skipMissingCmd
return $testStatus;
}

sub skipMsg
{
my( $msg, $count ) = @_;

my $testStatus;

for ( 1 .. $count )
{
$testStatus += skip( $msg, 1 );
}

return $testStatus;
}

sub getTestParameter
{
my( $param, $envvar, $default, $brief, $scoped );
Expand Down
14 changes: 8 additions & 6 deletions plugins/t/check_fping.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_IN

my $t;

if ( -x "./check_fping" )
{
my $fping = qx(which fping 2> /dev/null);
chomp($fping);
if( ! -x "./check_fping") {
$t += skipMissingCmd( "./check_fping", $tests );
}
elsif ( $> != 0 && (!$fping || ! -u $fping)) {
$t += skipMsg( "./check_fping", $tests );
} else {
$t += checkCmd( "./check_fping $host_responsive", 0, $successOutput );
$t += checkCmd( "./check_fping $host_nonresponsive", [ 1, 2 ] );
$t += checkCmd( "./check_fping $hostname_invalid", [ 1, 2 ] );
}
else
{
$t += skipMissingCmd( "./check_fping", $tests );
}

exit(0) if defined($Test::Harness::VERSION);
exit($tests - $t);

0 comments on commit 93901d5

Please sign in to comment.