File: basics.t

package info (click to toggle)
percona-toolkit 3.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 106,720 kB
  • sloc: perl: 257,236; sql: 23,577; sh: 21,388; javascript: 6,322; makefile: 398; python: 62; awk: 38; sed: 1
file content (204 lines) | stat: -rw-r--r-- 4,291 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/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;
use Sandbox;
require "$trunk/bin/pt-config-diff";

require VersionParser;
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $source_dbh = $sb->get_dbh_for('source');
my $replica_dbh  = $sb->get_dbh_for('replica1');

if ( !$source_dbh ) {
   plan skip_all => 'Cannot connect to sandbox source';
}
elsif ( !$replica_dbh ) {
   plan skip_all => 'Cannot connect to sandbox replica';
}

my $cnf = '/tmp/12345/my.sandbox.cnf';
my $samples = "$trunk/t/pt-config-diff/samples/";
my $output;
my $retval;

# ############################################################################
# Compare active configs.
# ############################################################################

$output = output(
   sub { $retval = pt_config_diff::main(
      'h=127.1,P=12345,u=msandbox,p=msandbox', 'h=127.1')
   },
   stderr => 1,
);

is(
   $retval,
   0,
   "Server active config doesn't differ with itself"
);

is(
   $output,
   "",
   "No output when no diff"
);

# Diff source to replica1.  There should be several differences.
$output = output(
   sub { $retval = pt_config_diff::main(
      'h=127.1,P=12345,u=msandbox,p=msandbox', 'P=12346')
   },
   stderr => 1,
);

is(
   $retval,
   1,
   "Exit 1 when diffs found"
);

like(
   $output,
   qr{datadir\s+/tmp/12345/data/\s+/tmp/12346/data/},
   "Diff output"
);


# ############################################################################
# Compare opt file and active config.
# ############################################################################

$output = output(
   sub { $retval = pt_config_diff::main(
      $cnf, 'h=127.1,P=12345,u=msandbox,p=msandbox')
   },
   stderr => 1,
);

is(
   $retval,
   0,
   "my.sandbox.cnf doesn't differ with active config"
);

is(
   $output,
   "",
   "No output"
);

# Compare source config to replica active/SHOW VARS
$output = output(
   sub { $retval = pt_config_diff::main(
      $cnf, 'h=127.1,P=12346,u=msandbox,p=msandbox')
   },
   stderr => 1,
);

is(
   $retval,
   1,
   "Source my.sandbox.cnf differs from replica active config"
);

like(
   $output,
   qr{server_id\s+12345\s+12346},
   "Config diff output"
);

# ############################################################################
# Compare option file configs.
# ############################################################################

$output = output(
   sub { $retval = pt_config_diff::main($cnf, $cnf) },
   stderr => 1,
);

is(
   $retval,
   0,
   "Server option file config doesn't differ with itself"
);

is(
   $output,
   "",
   "No output"
);

$output = output(
   sub { $retval = pt_config_diff::main(
      '/tmp/12345/my.sandbox.cnf',
      '/tmp/12346/my.sandbox.cnf',
   ) },
   stderr => 1,
);

is(
   $retval,
   1,
   "Source and replica option files differ"
);

like(
   $output,
   qr{port\s+12345\s+12346},
   "Config diff output"
);

# #############################################################################
# Case insensitivity
# #############################################################################

use File::Spec;

$output = output(
   sub { $retval = pt_config_diff::main(
      File::Spec->catfile($samples, "case1.cnf"),
      File::Spec->catfile($samples, "case2.cnf"),
   ) },
   stderr => 1,
);

is(
   $output,
   "",
   "Case-insensitive by default, finds no diffs"
);

$output = output(
   sub { $retval = pt_config_diff::main(
      File::Spec->catfile($samples, "case1.cnf"),
      File::Spec->catfile($samples, "case2.cnf"),
      '--no-ignore-case',
   ) },
   stderr => 1,
);

like(
   $output,
   qr/binlog_format\s+genlog\s+GENLOG/,
   "With case-insensitivity turned off, finds one diff"
);

# #############################################################################
# Done.
# #############################################################################
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");

done_testing;