diff options
Diffstat (limited to 'plugins-scripts/t')
| -rw-r--r-- | plugins-scripts/t/check_file_age.t | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/plugins-scripts/t/check_file_age.t b/plugins-scripts/t/check_file_age.t index 50a2e699..ebf673f5 100644 --- a/plugins-scripts/t/check_file_age.t +++ b/plugins-scripts/t/check_file_age.t | |||
| @@ -5,14 +5,14 @@ | |||
| 5 | # | 5 | # |
| 6 | 6 | ||
| 7 | use strict; | 7 | use strict; |
| 8 | use Test::More tests => 17; | 8 | use Test::More tests => 27; |
| 9 | use NPTest; | 9 | use NPTest; |
| 10 | 10 | ||
| 11 | my $successOutput = '/^FILE_AGE OK: /'; | 11 | my $successOutput = '/^FILE_AGE OK: /'; |
| 12 | my $warningOutput = '/^FILE_AGE WARNING: /'; | 12 | my $warningOutput = '/^FILE_AGE WARNING: /'; |
| 13 | my $criticalOutput = '/^FILE_AGE CRITICAL: /'; | 13 | my $criticalOutput = '/^FILE_AGE CRITICAL: /'; |
| 14 | my $unknownOutput = '/^FILE_AGE UNKNOWN: /'; | 14 | my $unknownOutput = '/^FILE_AGE UNKNOWN: /'; |
| 15 | my $performanceOutput = '/ \| age=[0-9]+s;[0-9]+;[0-9]+ size=[0-9]+B;[0-9]+;[0-9]+;0$/'; | 15 | my $performanceOutput = '/ \| age=[0-9]+s;[0-9:]+;[0-9:]+ size=[0-9]+B;[0-9:]+;[0-9:]+;0$/'; |
| 16 | 16 | ||
| 17 | my $result; | 17 | my $result; |
| 18 | my $temp_file = "/tmp/check_file_age.tmp"; | 18 | my $temp_file = "/tmp/check_file_age.tmp"; |
| @@ -48,22 +48,44 @@ cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old" ); | |||
| 48 | like ( $result->output, $warningOutput, "Output for warning correct" ); | 48 | like ( $result->output, $warningOutput, "Output for warning correct" ); |
| 49 | 49 | ||
| 50 | $result = NPTest->testCmd( | 50 | $result = NPTest->testCmd( |
| 51 | "./check_file_age -f $temp_file -w 0:1" | ||
| 52 | ); | ||
| 53 | cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old by range" ); | ||
| 54 | like ( $result->output, $warningOutput, "Output for warning by range correct" ); | ||
| 55 | |||
| 56 | $result = NPTest->testCmd( | ||
| 51 | "./check_file_age -f $temp_file -c 1" | 57 | "./check_file_age -f $temp_file -c 1" |
| 52 | ); | 58 | ); |
| 53 | cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" ); | 59 | cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" ); |
| 54 | like ( $result->output, $criticalOutput, "Output for critical correct" ); | 60 | like ( $result->output, $criticalOutput, "Output for critical correct" ); |
| 55 | 61 | ||
| 56 | $result = NPTest->testCmd( | 62 | $result = NPTest->testCmd( |
| 63 | "./check_file_age -f $temp_file -c 0:1" | ||
| 64 | ); | ||
| 65 | cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old by range" ); | ||
| 66 | like ( $result->output, $criticalOutput, "Output for critical by range correct" ); | ||
| 67 | |||
| 68 | $result = NPTest->testCmd( | ||
| 57 | "./check_file_age -f $temp_file -c 1000 -W 100" | 69 | "./check_file_age -f $temp_file -c 1000 -W 100" |
| 58 | ); | 70 | ); |
| 59 | cmp_ok( $result->return_code, '==', 0, "Checking file size" ); | 71 | cmp_ok( $result->return_code, '==', 0, "Checking file size" ); |
| 60 | 72 | ||
| 61 | $result = NPTest->testCmd( | 73 | $result = NPTest->testCmd( |
| 74 | "./check_file_age -f $temp_file -c 0:1000 -W 0:100" | ||
| 75 | ); | ||
| 76 | cmp_ok( $result->return_code, '==', 0, "Checking file size by range" ); | ||
| 77 | |||
| 78 | $result = NPTest->testCmd( | ||
| 62 | "./check_file_age -f $temp_file -c 1000 -W 100" | 79 | "./check_file_age -f $temp_file -c 1000 -W 100" |
| 63 | ); | 80 | ); |
| 64 | like( $result->output, $performanceOutput, "Checking for performance Output" ); | 81 | like( $result->output, $performanceOutput, "Checking for performance Output" ); |
| 65 | 82 | ||
| 66 | $result = NPTest->testCmd( | 83 | $result = NPTest->testCmd( |
| 84 | "./check_file_age -f $temp_file -c 1000 -W 100" | ||
| 85 | ); | ||
| 86 | like( $result->output, $performanceOutput, "Checking for performance Output from range" ); | ||
| 87 | |||
| 88 | $result = NPTest->testCmd( | ||
| 67 | "./check_file_age -f /non/existent --ignore-missing" | 89 | "./check_file_age -f /non/existent --ignore-missing" |
| 68 | ); | 90 | ); |
| 69 | cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" ); | 91 | cmp_ok( $result->return_code, '==', 0, "Honours --ignore-missing" ); |
| @@ -74,10 +96,30 @@ $result = NPTest->testCmd( | |||
| 74 | cmp_ok( $result->return_code, '==', 1, "One byte too short" ); | 96 | cmp_ok( $result->return_code, '==', 1, "One byte too short" ); |
| 75 | 97 | ||
| 76 | $result = NPTest->testCmd( | 98 | $result = NPTest->testCmd( |
| 99 | "./check_file_age -f $temp_file -c 1000 -W 101:" | ||
| 100 | ); | ||
| 101 | cmp_ok( $result->return_code, '==', 1, "One byte too short by range" ); | ||
| 102 | |||
| 103 | $result = NPTest->testCmd( | ||
| 77 | "./check_file_age -f $temp_file -c 1000 -C 101" | 104 | "./check_file_age -f $temp_file -c 1000 -C 101" |
| 78 | ); | 105 | ); |
| 79 | cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" ); | 106 | cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" ); |
| 80 | 107 | ||
| 108 | $result = NPTest->testCmd( | ||
| 109 | "./check_file_age -f $temp_file -c 1000 -C 101:" | ||
| 110 | ); | ||
| 111 | cmp_ok( $result->return_code, '==', 2, "One byte too short by range - critical" ); | ||
| 112 | |||
| 113 | $result = NPTest->testCmd( | ||
| 114 | "./check_file_age -f $temp_file -c 1000 -W 0:99" | ||
| 115 | ); | ||
| 116 | cmp_ok( $result->return_code, '==', 1, "One byte too long by range" ); | ||
| 117 | |||
| 118 | $result = NPTest->testCmd( | ||
| 119 | "./check_file_age -f $temp_file -c 1000 -C 0:99" | ||
| 120 | ); | ||
| 121 | cmp_ok( $result->return_code, '==', 2, "One byte too long by range - critical" ); | ||
| 122 | |||
| 81 | symlink $temp_file, $temp_link or die "Cannot create symlink"; | 123 | symlink $temp_file, $temp_link or die "Cannot create symlink"; |
| 82 | $result = NPTest->testCmd("./check_file_age -f $temp_link -c 10"); | 124 | $result = NPTest->testCmd("./check_file_age -f $temp_link -c 10"); |
| 83 | cmp_ok( $result->return_code, '==', 0, "Works for symlinks" ); | 125 | cmp_ok( $result->return_code, '==', 0, "Works for symlinks" ); |
