summaryrefslogtreecommitdiff
path: root/t/02_timesync.t
blob: 9e0432a455e7bb44d3243868c26ef109fed2011a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!perl

## Test of the the "version" action

use 5.006;
use strict;
use warnings;
use Data::Dumper;
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 $S = q{Action 'timesync'};
my $label = 'POSTGRES_TIMESYNC';

my $timepatt = qr{\d{4}-\d\d-\d\d \d\d:\d\d:\d\d};

$t = qq{$S self-identifies correctly};
$result = $cp->run(q{-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(q{--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(q{--output=mrtg -w 1}),
  qr{^\d+\n\d+\n\nDB: $dbname\n}, $t);

exit;