summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/t/check_file_age.t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts/t/check_file_age.t')
-rw-r--r--plugins-scripts/t/check_file_age.t88
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 0000000..372b9f2
--- /dev/null
+++ b/plugins-scripts/t/check_file_age.t
@@ -0,0 +1,88 @@
1#!/usr/bin/perl -w -I ..
2#
3# check_file_age tests
4#
5# $Id$
6#
7
8use strict;
9use Test::More tests => 15;
10use NPTest;
11
12my $successOutput = '/^FILE_AGE OK: /';
13my $warningOutput = '/^FILE_AGE WARNING: /';
14my $criticalOutput = '/^FILE_AGE CRITICAL: /';
15my $unknownOutput = '/^FILE_AGE UNKNOWN: /';
16
17my $result;
18my $temp_file = "/tmp/check_file_age.tmp";
19my $temp_link = "/tmp/check_file_age.link.tmp";
20
21unlink $temp_file, $temp_link;
22
23$result = NPTest->testCmd(
24 "./check_file_age"
25 );
26cmp_ok( $result->return_code, '==', 3, "Missing parameters" );
27like ( $result->output, $unknownOutput, "Output for unknown correct" );
28
29$result = NPTest->testCmd(
30 "./check_file_age -f $temp_file"
31 );
32cmp_ok( $result->return_code, '==', 2, "File not exists" );
33like ( $result->output, $criticalOutput, "Output for file missing correct" );
34
35write_chars(100);
36$result = NPTest->testCmd(
37 "./check_file_age -f $temp_file"
38 );
39cmp_ok( $result->return_code, '==', 0, "File is new enough" );
40like ( $result->output, $successOutput, "Output for success correct" );
41
42sleep 2;
43
44$result = NPTest->testCmd(
45 "./check_file_age -f $temp_file -w 1"
46 );
47cmp_ok( $result->return_code, '==', 1, "Warning for file over 1 second old" );
48like ( $result->output, $warningOutput, "Output for warning correct" );
49
50$result = NPTest->testCmd(
51 "./check_file_age -f $temp_file -c 1"
52 );
53cmp_ok( $result->return_code, '==', 2, "Critical for file over 1 second old" );
54like ( $result->output, $criticalOutput, "Output for critical correct" );
55
56$result = NPTest->testCmd(
57 "./check_file_age -f $temp_file -c 1000 -W 100"
58 );
59cmp_ok( $result->return_code, '==', 0, "Checking file size" );
60
61$result = NPTest->testCmd(
62 "./check_file_age -f $temp_file -c 1000 -W 101"
63 );
64cmp_ok( $result->return_code, '==', 1, "One byte too short" );
65
66$result = NPTest->testCmd(
67 "./check_file_age -f $temp_file -c 1000 -C 101"
68 );
69cmp_ok( $result->return_code, '==', 2, "One byte too short - critical" );
70
71symlink $temp_file, $temp_link or die "Cannot create symlink";
72$result = NPTest->testCmd("./check_file_age -f $temp_link -c 10");
73cmp_ok( $result->return_code, '==', 0, "Works for symlinks" );
74unlink $temp_link;
75
76unlink $temp_file;
77mkdir $temp_file or die "Cannot create directory";
78$result = NPTest->testCmd("./check_file_age -f $temp_file -c 1");
79cmp_ok( $result->return_code, '==', 0, "Works for directories" );
80rmdir $temp_file;
81
82
83sub write_chars {
84 my $size = shift;
85 open F, "> $temp_file" or die "Cannot write to $temp_file";
86 print F "A" x $size;
87 close F;
88}