File: option_sanity.t

package info (click to toggle)
percona-toolkit 3.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid
  • size: 68,916 kB
  • sloc: perl: 241,287; sql: 22,868; sh: 19,746; javascript: 6,799; makefile: 353; awk: 38; python: 30; sed: 1
file content (183 lines) | stat: -rw-r--r-- 4,830 bytes parent folder | download | duplicates (2)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env perl

BEGIN {
   die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
      unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
   unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};

use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More;

use PerconaTest;
require "$trunk/bin/pt-table-checksum";

my $output;

# Calling the tool pt_table_checksum::main() doesn't work when we're
# dealing with cmd line option error and --help because OptionParser
# exits on such things which would cause this test to exit too.

# ############################################################################
# Check default values for some options to ensure something wasn't
# changed accidentally.  A lot of tests rely on these defaults, so
# if they change, it can have weird side-effects.
# ############################################################################
$output = `$trunk/bin/pt-table-checksum h=127.1 --help`;

like(
   $output,
   qr/^  --check-replication-filters\s+TRUE$/m,
   "Default --check-replication-filters=TRUE"
);

like(
   $output,
   qr/^  --create-replicate-table\s+TRUE$/m,
   "Default --create-replicate-table=TRUE"
);

like(
   $output,
   qr/^  --empty-replicate-table\s+TRUE$/m,
   "Default --empty-replicate-table=TRUE"
);

like(
   $output,
   qr/^  --explain\s+0$/m,
   "Default --explain=0"
);

like(
   $output,
   qr/^  --host\s+localhost$/m,
   "Default --host=localhost"
);

#like(
#   $output,
#   qr/^  --lock-wait-timeout\s+1$/m,
#   "Default --lock-wait-timeout=1"
#);

like(
   $output,
   qr/^  --max-lag\s+1$/m,
   "Default --max-lag=1"
);

like(
   $output,
   qr/^  --quiet\s+0$/m,
   "Default --quiet=0"
);

like(
   $output,
   qr/^  --replicate-check-only\s+FALSE$/m,
   "Default --replicate-check-only=FALSE"
);

like(
   $output,
   qr/^  --replicate\s+percona\.checksums$/m,
   "Default --replicate=percona.checksums"
);

like(
   $output,
   qr/^  --replicate-check\s+TRUE$/m,
   "Default --replicate-check=TRUE"
);

like(
   $output,
   qr/^\s+--recursion-method=a/m,
   "--recursion-method is an array"
);

like(
   $output,
   qr/^\s+--recursion-method\s+processlist,hosts/m,
   "Default --recursion-method is processlist,hosts"
);

# ############################################################################
# Check opts that disable other opts.
# ############################################################################
$output = `$trunk/bin/pt-table-checksum h=127.1 --help --explain`;
like(
   $output,
   qr/^  --empty-replicate-table\s+FALSE$/m,
   "--explain disables --empty-replicate-table"
);

$output = `$trunk/bin/pt-table-checksum h=127.1 --help --resume`;
like(
   $output,
   qr/^  --empty-replicate-table\s+FALSE$/m,
   "--resume disables --empty-replicate-table"
);

$output = `$trunk/bin/pt-table-checksum h=127.1 --help --quiet`;
like(
   $output,
   qr/^  --progress\s+\(No value\)$/m,
   "--quiet disables --progress"
);

$output = `$trunk/bin/pt-table-checksum --help --chunk-size 500`;
like(
   $output,
   qr/^  --chunk-time\s+0$/m,
   "--chunk-size sets --chunk-time=0"
);

# ############################################################################
# Only 1 DSN should be allowed on the command line; no extra args.
# ############################################################################
$output = `$trunk/bin/pt-table-checksum h=127.1 h=host1 h=host2`;
like(
   $output,
   qr/More than one host specified; only one allowed/,
   "Only one DSN allowed on the command line"
);

# ############################################################################
# --replicate table must be db-qualified.
# ############################################################################
$output = `$trunk/bin/pt-table-checksum h=127.1 --replicate checksums`;
like(
   $output,
   qr/--replicate table must be database-qualified/,
   "--replicate table must be database-qualified"
);

# ############################################################################
# --chunk-size-limit >= 1 or 0
# ############################################################################
$output = `$trunk/bin/pt-table-checksum --chunk-size-limit 0.999`;
like(
   $output,
   qr/chunk-size-limit must be >= 1 or 0 to disable/,
   "--chunk-size-limit must be >= 1 or 0"
);

# #############################################################################
# --max-load
# #############################################################################

$output = `$trunk/bin/pt-table-checksum h=127.1,P=12345 --max-load 100`;
like(
   $output,
   qr/Invalid --max-load/,
   "Validates --max-load"
);

# #############################################################################
# Done.
# #############################################################################
done_testing;