[check_postgres] [commit] Added 'timesync' tests.

check_postgres at bucardo.org check_postgres at bucardo.org
Tue Apr 28 12:57:12 UTC 2009


Committed by Jeff Boes <jeff at endpoint.com>

Added 'timesync' tests.

---
 t/02_timesync.t |   73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/t/02_timesync.t b/t/02_timesync.t
new file mode 100644
index 0000000..7e7515e
--- /dev/null
+++ b/t/02_timesync.t
@@ -0,0 +1,73 @@
+use Data::Dumper;
+use DBI;
+use Test::More tests => 20;
+use lib 't','.';
+use CP_Testing;
+
+use vars qw/$dbh $result $t $host $dbname/;
+
+my $cp = CP_Testing->new( {default_action => 'timesync'} );
+
+$dbh = $cp->test_database_handle();
+$dbname = $cp->get_dbname;
+$host = $cp->get_host();
+my $label = 'POSTGRES_TIMESYNC';
+
+my $timepatt = qr{\d{4}-\d\d-\d\d \d\d:\d\d:\d\d};
+
+my $S = q{Action 'timesync'};
+
+$t = qq{$S self-identifies correctly};
+$result = $cp->run(qq{-w 100});
+like ($result, qr{^$label}, $t);
+
+$t = qq{$S identifies database};
+like ($result, qr{DB "$dbname"}, $t);
+
+$t = qq{$S identifies host};
+like ($result, qr{host:$host}, $t);
+
+$t = qq{$S reports time unsynchronized};
+like ($result, qr{$label OK}, $t);
+
+$t = qq{$S reports time unsynchronized};
+like ($cp->run('-w 0'), qr{$label WARNING}, $t);
+
+$t = qq{$S reports formatted time comparison};
+like ($result, qr{timediff=\d+ DB=$timepatt Local=$timepatt }, $t);
+
+$t = qq{$S accepts valid -w input};
+for (qw/1 5 10/) {
+   like ($cp->run(qq{-w "$_"}), qr/^$label/, $t . " ($_)");
+}
+
+$t = qq{$S accepts valid -c input};
+for (qw/1 5 10/) {
+   like ($cp->run(qq{-c "$_"}), qr/^$label/, $t . " ($_)");
+}
+
+$t = qq{$S rejects invalid -w input};
+for ('-1 second',
+     'abc',
+     '-0',
+	) {
+   like ($cp->run(qq{-w "$_"}), qr/^ERROR:.*?must be number of seconds/, $t . " ($_)");
+}
+
+$t = qq{$S rejects invalid -c input};
+for ('-1 second',
+     'abc',
+     '-0',
+	) {
+   like ($cp->run(qq{-c "$_"}), qr/^ERROR:.*?must be number of seconds/, $t . " ($_)");
+}
+
+$t = qq{$S returns correct MRTG information (OK case)};
+like ($cp->run("--output=mrtg -w 1"),
+  qr{^\d+\n\d+\n\nDB: $dbname\n}, $t);
+
+$t = qq{$S returns correct MRTG information (fail case)};
+like($cp->run("--output=mrtg -w 1"),
+  qr{^\d+\n\d+\n\nDB: $dbname\n}, $t);
+
+exit;
-- 
1.6.0.5



More information about the Check_postgres mailing list