Implemented Pingback::time_to_check()

This commit is contained in:
Brian Fraser fraserb@gmail.com
2012-08-21 16:50:12 -03:00
parent e9fc764e02
commit 01937e6d9f
2 changed files with 77 additions and 2 deletions

View File

@@ -179,6 +179,42 @@ SKIP: {
);
}
# #############################################################################
# Testing time_to_check
# #############################################################################
my $dir = File::Spec->tmpdir();
my $file = File::Spec->catfile($dir, 'percona-toolkit-version-check-test');
unlink $file;
ok(
Pingback::time_to_check($file),
"time_to_check() returns true if the file doesn't exist",
);
ok(
!Pingback::time_to_check($file),
"...but false if it exists and it's been less than 24 hours",
);
my $one_day = 60 * 60 * 24;
my ($old_atime, $old_mtime) = (stat($file))[8,9];
utime($old_atime - $one_day * 2, $old_mtime - $one_day * 2, $file);
cmp_ok(
(stat($file))[9],
q{<},
time() - $one_day,
"Sanity check, the file's mtime is now at least one day behind time()",
);
ok(
Pingback::time_to_check($file),
"time_to_check returns true if the file exists and it's mtime is at least one day old",
);
# #############################################################################
# Done.
# #############################################################################