diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2005-12-15 15:17:49 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2005-12-15 15:17:49 +0000 |
commit | 73b77a44c43960b6fcf8b3c29c1016ba1940aa89 (patch) | |
tree | a8adb7ae427b4cf7b7c6c4f35de9fc0a918140d4 /plugins-scripts/t | |
parent | 162faf883a864a94c0f75ca0e21360cbd001e0f3 (diff) | |
download | monitoring-plugins-73b77a44c43960b6fcf8b3c29c1016ba1940aa89.tar.gz |
Allow directories and links to be tested by check_file_age. Sanitise output.
Added tests
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1297 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-scripts/t')
-rw-r--r-- | plugins-scripts/t/check_file_age.t | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/plugins-scripts/t/check_file_age.t b/plugins-scripts/t/check_file_age.t new file mode 100644 index 00000000..372b9f2e --- /dev/null +++ b/plugins-scripts/t/check_file_age.t @@ -0,0 +1,88 @@ +#!/usr/bin/perl -w -I .. +# +# check_file_age tests +# +# $Id$ +# + +use strict; +use Test::More tests => 15; +use NPTest; + +my $successOutput = '/^FILE_AGE OK: /'; +my $warningOutput = '/^FILE_AGE WARNING: /'; +my $criticalOutput = '/^FILE_AGE CRITICAL: /'; +my $unknownOutput = '/^FILE_AGE UNKNOWN: /'; + +my $result; +my $temp_file = "/tmp/check_file_age.tmp"; +my $temp_link = "/tmp/check_file_age.link.tmp"; + +unlink $temp_file, $temp_link; + +$result = NPTest->testCmd( + "./check_file_age" + ); +cmp_ok( $result->return_code, '==', 3, "Missing parameters" ); +like ( $result->output, $unknownOutput, "Output for unknown correct" ); + +$result = NPTest->testCmd( + "./check_file_age -f $temp_file" + ); +cmp_ok( $result->return_code, '==', 2, "File not exists" ); +like ( $result->output, $criticalOutput, "Output for file missing correct" ); + +write_chars(100); +$result = NPTest->testCmd( + "./check_file_age -f $temp_file" + ); +cmp_ok( $result->return_code, '==', 0, "File is new enough" ); +like ( $result->output, $successOutput, "Output for success correct" ); + +sleep 2; + +$result = NPTest->testCmd( + "./check_file_age -f $temp_file -w 1" + ); +cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old" ); +like ( $result->output, $warningOutput, "Output for warning correct" ); + +$result = NPTest->testCmd( + "./check_file_age -f $temp_file -c 1" + ); +cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" ); +like ( $result->output, $criticalOutput, "Output for critical correct" ); + +$result = NPTest->testCmd( + "./check_file_age -f $temp_file -c 1000 -W 100" + ); +cmp_ok( $result->return_code, '==', 0, "Checking file size" ); + +$result = NPTest->testCmd( + "./check_file_age -f $temp_file -c 1000 -W 101" + ); +cmp_ok( $result->return_code, '==', 1, "One byte too short" ); + +$result = NPTest->testCmd( + "./check_file_age -f $temp_file -c 1000 -C 101" + ); +cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" ); + +symlink $temp_file, $temp_link or die "Cannot create symlink"; +$result = NPTest->testCmd("./check_file_age -f $temp_link -c 10"); +cmp_ok( $result->return_code, '==', 0, "Works for symlinks" ); +unlink $temp_link; + +unlink $temp_file; +mkdir $temp_file or die "Cannot create directory"; +$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1"); +cmp_ok( $result->return_code, '==', 0, "Works for directories" ); +rmdir $temp_file; + + +sub write_chars { + my $size = shift; + open F, "> $temp_file" or die "Cannot write to $temp_file"; + print F "A" x $size; + close F; +} |