summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 73b77a4)
raw | patch | inline | side by side (parent: 73b77a4)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Thu, 15 Dec 2005 15:19:55 +0000 (15:19 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Thu, 15 Dec 2005 15:19:55 +0000 (15:19 +0000) |
Added notes re: testing in developer guidelines.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1298 f882894a-f735-0410-b71e-b25c423dba1c
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1298 f882894a-f735-0410-b71e-b25c423dba1c
NPTest.pm | patch | blob | history | |
doc/developer-guidelines.sgml | patch | blob | history | |
plugins/t/check_disk.t | patch | blob | history |
diff --git a/NPTest.pm b/NPTest.pm
index 440e7343e36ebb4505797402fe0109925e8a6c33..4036a9d0e4a04520c8d42fe66c48849eae430632 100644 (file)
--- a/NPTest.pm
+++ b/NPTest.pm
=over
-=item C<getTestParameter(...)>
+=item getTestParameter( "ENV_VARIABLE", $brief_description, $default )
-A flexible and user override-able method of collecting, storing and
-retrieving test parameters. This function allows the test harness
+This function allows the test harness
developer to interactively request test parameter information from the
-user, when the no means of obtaining the information automatically has
-been successful. The user is provided with the option of accepting
-test harness developer's default value for the parameter, if a suggested
-default is provided.
-
-User supplied responses are stored in an external (file-based)
-cache. These values are retrieved on subsequent runs alleviating the
-user of reconfirming the previous entered responses. The user is able
-to override the value of a parameter on any given run by setting the
-associated environment variable. These environment variable based
-overrides are not stored in the cache, allowing one-time and what-if
-based tests on the command line without polluting the cache.
+user. The user can accept the developer's default value or reply "none"
+which will then be returned as "" for the test to skip if appropriate.
+
+Responses are stored in an external, file-based
+cache so subsequent test runs will use these values. The user is able
+to change the values by amending the values in the file /var/tmp/NPTest.pm,
+or by setting the appropriate environment variable before running the test.
The option exists to store parameters in a scoped means, allowing a
test harness to a localise a parameter should the need arise. This
cache is first searched for "check_disk"/"mountpoint_valid", if this
fails, then a search is conducted for "mountpoint_valid".
-The facilitate quick testing setup, it is possible to accept all the
+To facilitate quick testing setup, it is possible to accept all the
developer provided defaults by setting the environment variable
"NPTEST_ACCEPTDEFAULT" to "1" (or any other perl truth value). Note
that, such defaults are not stored in the cache, as there is currently
sub getTestParameter
{
- my( $param, $envvar, $default, $brief, $scoped ) = @_;
+ my( $param, $envvar, $default, $brief, $scoped );
+ my $new_style;
+ if (scalar @_ == 3) {
+ ($param, $brief, $default) = @_;
+ $envvar = $param;
+ $new_style = 1;
+ } else {
+ ( $param, $envvar, $default, $brief, $scoped ) = @_;
+ $new_style = 0;
+ }
# Apply default values for optional arguments
$scoped = ( defined( $scoped ) && $scoped );
}
my $cachedValue = SearchCache( $param, $testharness );
- if ( defined( $cachedValue ) && $cachedValue )
+ if ( defined( $cachedValue ) )
{
+ # This save required to convert to new style because the key required is
+ # changing to the environment variable
+ if ($new_style == 0) {
+ SetCacheParameter( $envvar, undef, $cachedValue );
+ }
return $cachedValue;
}
print STDERR "\n";
print STDERR "Test Harness : $testharness\n";
print STDERR "Test Parameter : $param\n";
- print STDERR "Environment Variable : $envvar\n";
+ print STDERR "Environment Variable : $envvar\n" if ($param ne $envvar);
print STDERR "Brief Description : $brief\n";
- print STDERR "Enter value ", ($defaultValid ? "[${default}]" : "[]"), " => ";
+ print STDERR "Enter value (or 'none') ", ($defaultValid ? "[${default}]" : "[]"), " => ";
$userResponse = <STDIN>;
$userResponse = "" if ! defined( $userResponse ); # Handle EOF
chomp( $userResponse );
print STDERR "\n";
+ if ($userResponse =~ /^(na|none)$/) {
+ $userResponse = "";
+ }
+
# define all user responses at global scope
SetCacheParameter( $param, ( $scoped ? $testharness : undef ), $userResponse );
{
return $CACHE{$param};
}
+ return undef; # Need this to say "nothing found"
}
sub SetCacheParameter
index 433a3022b1a1f7bde4e0e66fdfa5f25aff40c4d6..3c37e5c104a858c9faeed19794f18fb776410813 100644 (file)
</section>
</section>
+<section id="Testcases"><title>Test cases</title>
+<para>
+Tests are the best way of knowing if the plugins work as expected. Please
+create and update test cases where possible.
+</para>
+
+<para>
+To run a test, from the top level directory, run "make test". This will run
+all the current tests and report an overall success rate.
+</para>
+
+<para>
+See the <ulink url="http://tinderbox.altinity.org">Nagios Plugins Tinderbox server</ulink>
+for the daily test results.
+</para>
+
+<section><title>Test cases for plugins</title>
+<para>These use perl's Test::More. To do a one time test, run "cd plugins && perl t/check_disk.t".
+</para>
+
+<para>There will somtimes be failures seen in this output which are known failures that
+need to be fixed. As long as the return code is 0, it will be reported as "test pass".
+(If you have a fix so that the specific test passes, that will be gratefully received!)
+</para>
+
+<para>
+If you want a summary test, run: "cd plugins && perl -MTest::Harness -e 'runtests(@ARGV)' t/check_disk.t".
+This runs the test in a summary format.
+</para>
+
+<para>
+For a good and amusing tutorial on using Test::More, see this
+<ulink url="http://search.cpan.org/~mschwern/Test-Simple-0.62/lib/Test/Tutorial.pod">
+link</ulink>
+</para>
+
+</section>
+
+<section><title>Testing the C library functions</title>
+<para>
+Will be looking at using libtap, which is utilised by the FreeBSD team. The output is
+based on perl's TAP (Test Anything Protocol) format, so that Test::Harness will understand
+results. This is still in planning stages.
+</para>
+</section>
+
+</section>
<section id="CodingGuidelines"><title>Coding guidelines</title>
<para>See <ulink url="http://www.gnu.org/prep/standards_toc.html">GNU
Coding standards</ulink> for general guidelines.</para>
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index d35d02c93216f356fc4444c236431c2315431ad0..385865fe9e89860f2210911130760a42a9abf78b 100644 (file)
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
#
use strict;
-use Test::More tests => 26;
+use Test::More;
use NPTest;
use POSIX qw(ceil floor);
my $result;
-my $mountpoint_valid = getTestParameter( "mountpoint_valid", "NP_MOUNTPOINT_VALID", "/",
- "The path to a valid mountpoint" );
-
-my $mountpoint2_valid = getTestParameter( "mountpoint2_valid", "NP_MOUNTPOINT2_VALID", "/var",
- "The path to another valid mountpoint. Must be different from 1st one." );
+my $mountpoint_valid = getTestParameter( "NP_MOUNTPOINT_VALID", "Path to valid mountpoint", "/");
+my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to another valid mountpoint. Must be different from 1st one", "/var");
+if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") {
+ plan skip_all => "Need 2 mountpoints to test";
+} else {
+ plan tests => 26;
+}
$result = NPTest->testCmd(
"./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -p $mountpoint2_valid"