diff options
author | Sven Nierlein <Sven.Nierlein@consol.de> | 2018-12-04 14:08:21 +0100 |
---|---|---|
committer | Sven Nierlein <Sven.Nierlein@consol.de> | 2018-12-04 14:54:12 +0100 |
commit | 660e0cf4e2968c97adeabf9ba91a54f1bd4ad240 (patch) | |
tree | 7ee68ebd9f2fde5536fb04568730c899d7911ae5 /plugins-scripts | |
parent | 19be129ff8986511e82fb2c628c04c28a080210b (diff) | |
download | monitoring-plugins-660e0cf4e2968c97adeabf9ba91a54f1bd4ad240.tar.gz |
tests: skip some tests if Monitoring::Plugin::Range isn't available
The check_file_age uses Monitoring::Plugin::Range internally. Skip thoses tests
if the module isn't available.
Diffstat (limited to 'plugins-scripts')
-rw-r--r-- | plugins-scripts/t/check_file_age.t | 103 |
1 files changed, 36 insertions, 67 deletions
diff --git a/plugins-scripts/t/check_file_age.t b/plugins-scripts/t/check_file_age.t index ebf673f5..8b876708 100644 --- a/plugins-scripts/t/check_file_age.t +++ b/plugins-scripts/t/check_file_age.t @@ -20,105 +20,74 @@ my $temp_link = "/tmp/check_file_age.link.tmp"; unlink $temp_file, $temp_link; -$result = NPTest->testCmd( - "./check_file_age" - ); +$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" - ); +$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" - ); +$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" - ); +$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 -w 0:1" - ); -cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old by range" ); -like ( $result->output, $warningOutput, "Output for warning by range correct" ); - -$result = NPTest->testCmd( - "./check_file_age -f $temp_file -c 1" - ); +$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 0:1" - ); -cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old by range" ); -like ( $result->output, $criticalOutput, "Output for critical by range correct" ); - -$result = NPTest->testCmd( - "./check_file_age -f $temp_file -c 1000 -W 100" - ); +$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 0:1000 -W 0:100" - ); -cmp_ok( $result->return_code, '==', 0, "Checking file size by range" ); - -$result = NPTest->testCmd( - "./check_file_age -f $temp_file -c 1000 -W 100" - ); +$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100"); like( $result->output, $performanceOutput, "Checking for performance Output" ); -$result = NPTest->testCmd( - "./check_file_age -f $temp_file -c 1000 -W 100" - ); +$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 100"); like( $result->output, $performanceOutput, "Checking for performance Output from range" ); -$result = NPTest->testCmd( - "./check_file_age -f /non/existent --ignore-missing" - ); +$result = NPTest->testCmd("./check_file_age -f /non/existent --ignore-missing"); cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" ); -$result = NPTest->testCmd( - "./check_file_age -f $temp_file -c 1000 -W 101" - ); +$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 -W 101:" - ); -cmp_ok( $result->return_code, '==', 1, "One byte too short by range" ); - -$result = NPTest->testCmd( - "./check_file_age -f $temp_file -c 1000 -C 101" - ); +$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 101"); cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" ); -$result = NPTest->testCmd( - "./check_file_age -f $temp_file -c 1000 -C 101:" - ); -cmp_ok( $result->return_code, '==', 2, "One byte too short by range - critical" ); +SKIP: { + eval 'use Monitoring::Plugin::Range'; + skip "Monitoring::Plugin::Range module require", 9 if $@; + + $result = NPTest->testCmd("./check_file_age -f $temp_file -w 0:1"); + cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old by range" ); + like ( $result->output, $warningOutput, "Output for warning by range correct" ); + + $result = NPTest->testCmd("./check_file_age -f $temp_file -c 0:1"); + cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old by range" ); + like ( $result->output, $criticalOutput, "Output for critical by range correct" ); + + $result = NPTest->testCmd("./check_file_age -f $temp_file -c 0:1000 -W 0:100"); + cmp_ok( $result->return_code, '==', 0, "Checking file size by range" ); + + $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 101:"); + cmp_ok( $result->return_code, '==', 1, "One byte too short by range" ); + + $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -W 0:99"); + cmp_ok( $result->return_code, '==', 1, "One byte too long by range" ); -$result = NPTest->testCmd( - "./check_file_age -f $temp_file -c 1000 -W 0:99" - ); -cmp_ok( $result->return_code, '==', 1, "One byte too long by range" ); + $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 101:"); + cmp_ok( $result->return_code, '==', 2, "One byte too short by range - critical" ); -$result = NPTest->testCmd( - "./check_file_age -f $temp_file -c 1000 -C 0:99" - ); -cmp_ok( $result->return_code, '==', 2, "One byte too long by range - critical" ); + $result = NPTest->testCmd("./check_file_age -f $temp_file -c 1000 -C 0:99"); + cmp_ok( $result->return_code, '==', 2, "One byte too long by range - critical" ); +}; symlink $temp_file, $temp_link or die "Cannot create symlink"; $result = NPTest->testCmd("./check_file_age -f $temp_link -c 10"); |