diff options
author | Jeff Boes | 2009-04-28 12:56:50 +0000 |
---|---|---|
committer | Jeff Boes | 2009-04-28 12:56:50 +0000 |
commit | 88883e3fe18efb41c6d4e394eab51ba1b86086d7 (patch) | |
tree | 28ee533bf990c4bda1192c4f19b278c04f4c4827 | |
parent | a6e3c7c99481bb0fd70aa14289148afe2cbeb5d0 (diff) |
Added 'timesync' tests.
-rw-r--r-- | 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 000000000..7e7515e00 --- /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; |