mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-26 15:31:55 +00:00
v-c: Re-enable https by default, make --version-check take an optional protocol argument
This commit is contained in:
@@ -9,7 +9,7 @@ BEGIN {
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More tests => 151;
|
||||
use Test::More;
|
||||
|
||||
use OptionParser;
|
||||
use DSNParser;
|
||||
@@ -145,6 +145,7 @@ is_deeply(
|
||||
type => 's',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'port' => {
|
||||
spec => 'port|p=i',
|
||||
@@ -158,6 +159,7 @@ is_deeply(
|
||||
type => 'i',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'price' => {
|
||||
spec => 'price=f',
|
||||
@@ -171,6 +173,7 @@ is_deeply(
|
||||
type => 'f',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'hash-req' => {
|
||||
spec => 'hash-req=s',
|
||||
@@ -184,6 +187,7 @@ is_deeply(
|
||||
type => 'H',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'hash-opt' => {
|
||||
spec => 'hash-opt=s',
|
||||
@@ -197,6 +201,7 @@ is_deeply(
|
||||
type => 'h',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'array-req' => {
|
||||
spec => 'array-req=s',
|
||||
@@ -210,6 +215,7 @@ is_deeply(
|
||||
type => 'A',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'array-opt' => {
|
||||
spec => 'array-opt=s',
|
||||
@@ -223,6 +229,7 @@ is_deeply(
|
||||
type => 'a',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'host' => {
|
||||
spec => 'host=s',
|
||||
@@ -236,6 +243,7 @@ is_deeply(
|
||||
type => 'd',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'chunk-size' => {
|
||||
spec => 'chunk-size=s',
|
||||
@@ -249,6 +257,7 @@ is_deeply(
|
||||
type => 'z',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'time' => {
|
||||
spec => 'time=s',
|
||||
@@ -262,6 +271,7 @@ is_deeply(
|
||||
type => 'm',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'help' => {
|
||||
spec => 'help+',
|
||||
@@ -275,6 +285,7 @@ is_deeply(
|
||||
type => undef,
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'other' => {
|
||||
spec => 'other!',
|
||||
@@ -288,6 +299,7 @@ is_deeply(
|
||||
type => undef,
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
}
|
||||
},
|
||||
'Parse opt specs'
|
||||
@@ -508,6 +520,7 @@ is_deeply(
|
||||
type => undef,
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'defaultset' => {
|
||||
spec => 'defaultset!',
|
||||
@@ -523,6 +536,7 @@ is_deeply(
|
||||
type => undef,
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'defaults-file' => {
|
||||
spec => 'defaults-file|F=s',
|
||||
@@ -536,6 +550,7 @@ is_deeply(
|
||||
type => 's',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'dog' => {
|
||||
spec => 'dog|D=s',
|
||||
@@ -549,6 +564,7 @@ is_deeply(
|
||||
type => 's',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'love' => {
|
||||
spec => 'love|l+',
|
||||
@@ -562,6 +578,7 @@ is_deeply(
|
||||
type => undef,
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
},
|
||||
'Parse dog specs'
|
||||
@@ -961,6 +978,7 @@ is_deeply(
|
||||
long => 'bar',
|
||||
type => undef,
|
||||
parsed => 1,
|
||||
optional_value=> 0,
|
||||
},
|
||||
'Disabled opt is not destroyed'
|
||||
);
|
||||
@@ -1990,13 +2008,55 @@ $o->get_opts();
|
||||
$output = output(
|
||||
sub { $o->usage_or_errors(undef, 1); },
|
||||
);
|
||||
$synop{usage} =~ s/([\[\]])/\\$1/g;
|
||||
like(
|
||||
$output,
|
||||
qr/^$synop{description} For more details.+\nUsage: $synop{usage}$/m,
|
||||
qr/^$synop{description} For more details.+\nUsage: \Q$synop{usage}\E\n?$/m,
|
||||
"Uses desc and usage from SYNOPSIS for help"
|
||||
);
|
||||
|
||||
# Add a value_is_optional option
|
||||
@ARGV = qw();
|
||||
$o->get_opts();
|
||||
|
||||
ok(
|
||||
!$o->got('version-check'),
|
||||
"version-check is not true by default"
|
||||
);
|
||||
|
||||
is(
|
||||
$o->get('version-check'),
|
||||
"https",
|
||||
"..but it still has a value",
|
||||
);
|
||||
|
||||
@ARGV = qw(--version-check);
|
||||
$o->get_opts();
|
||||
|
||||
ok(
|
||||
$o->got('version-check'),
|
||||
"version-check is true if specified without arguments"
|
||||
);
|
||||
|
||||
is(
|
||||
$o->get('version-check'),
|
||||
"https",
|
||||
"..and has the default value",
|
||||
);
|
||||
|
||||
@ARGV = qw(--version-check http);
|
||||
$o->get_opts();
|
||||
|
||||
ok(
|
||||
$o->got('version-check'),
|
||||
"version-check is true if specified with arguments"
|
||||
);
|
||||
|
||||
is(
|
||||
$o->get('version-check'),
|
||||
"http",
|
||||
"..and has the specified value",
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
@@ -2010,4 +2070,5 @@ like(
|
||||
qr/Complete test coverage/,
|
||||
'_d() works'
|
||||
);
|
||||
exit;
|
||||
|
||||
done_testing;
|
||||
|
@@ -238,20 +238,37 @@ my $file = File::Spec->catfile($dir, 'percona-toolkit-version-check-test');
|
||||
|
||||
unlink $file if -f $file;
|
||||
|
||||
my $time = int(time());
|
||||
|
||||
ok(
|
||||
Pingback::time_to_check($file, []),
|
||||
Pingback::time_to_check($file, [], $time),
|
||||
"time_to_check() returns true if the file doesn't exist",
|
||||
);
|
||||
|
||||
ok(
|
||||
!Pingback::time_to_check($file, []),
|
||||
"...but false if it exists and it's been less than 24 hours",
|
||||
!-f $file,
|
||||
"time_to_check doesn't create the checks file"
|
||||
);
|
||||
|
||||
Pingback::update_checks_file($file, [], $time);
|
||||
|
||||
ok(
|
||||
-f $file,
|
||||
"...but update_checks_file does"
|
||||
);
|
||||
|
||||
ok(
|
||||
!Pingback::time_to_check($file, [], $time),
|
||||
"...and time_to_check is false if the file exists and it's been less than 24 hours",
|
||||
);
|
||||
|
||||
my $one_day = 60 * 60 * 24;
|
||||
my ($old_atime, $old_mtime) = (stat($file))[8,9];
|
||||
my ($orig_atime, $orig_mtime) = (stat($file))[8,9];
|
||||
|
||||
utime($old_atime - $one_day * 2, $old_mtime - $one_day * 2, $file);
|
||||
my $mod_atime = $orig_atime - $one_day * 2;
|
||||
my $mod_mtime = $orig_mtime - $one_day * 2;
|
||||
|
||||
utime($mod_atime, $mod_mtime, $file);
|
||||
|
||||
cmp_ok(
|
||||
(stat($file))[9],
|
||||
@@ -261,13 +278,24 @@ cmp_ok(
|
||||
);
|
||||
|
||||
ok(
|
||||
Pingback::time_to_check($file, []),
|
||||
Pingback::time_to_check($file, [], $time),
|
||||
"time_to_check true if file exists and mtime < one day", #>"
|
||||
);
|
||||
|
||||
my ($atime, $mtime) = (stat($file))[8,9];
|
||||
|
||||
is($mod_atime, $atime, "time_to_check doesn't update the atime");
|
||||
is($mod_mtime, $mtime, "time_to_check doesn't update the mtime");
|
||||
|
||||
Pingback::update_checks_file($file, [], $time);
|
||||
|
||||
($atime, $mtime) = (stat($file))[8,9];
|
||||
|
||||
ok($orig_atime == $atime && $orig_mtime == $mtime, "but update_checks_file does");
|
||||
|
||||
ok(
|
||||
!Pingback::time_to_check($file, []),
|
||||
"...but fails if tried a second time, as the mtime has been updated",
|
||||
!Pingback::time_to_check($file, [], $time),
|
||||
"...and time_to_check fails after update_checks_file, as the mtime has been updated",
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
@@ -312,7 +340,8 @@ SKIP: {
|
||||
$file,
|
||||
[ $master_inst ],
|
||||
);
|
||||
|
||||
Pingback::update_checks_file($file, $check_inst, int(time()));
|
||||
|
||||
ok(
|
||||
$is_time,
|
||||
"Time to check a new MySQL instance ID",
|
||||
@@ -330,6 +359,8 @@ SKIP: {
|
||||
[ $master_inst ],
|
||||
);
|
||||
|
||||
Pingback::update_checks_file($file, $check_inst, int(time()));
|
||||
|
||||
ok(
|
||||
!$is_time,
|
||||
"...but not the second time around",
|
||||
@@ -344,6 +375,8 @@ SKIP: {
|
||||
[ $master_inst ],
|
||||
);
|
||||
|
||||
Pingback::update_checks_file($file, $check_inst, int(time()));
|
||||
|
||||
is_deeply(
|
||||
$check_inst,
|
||||
[ $master_inst ],
|
||||
@@ -355,6 +388,8 @@ SKIP: {
|
||||
[ $master_inst, $slave1_inst ],
|
||||
);
|
||||
|
||||
Pingback::update_checks_file($file, $check_inst, int(time()));
|
||||
|
||||
is_deeply(
|
||||
$check_inst,
|
||||
[ $slave1_inst ],
|
||||
@@ -371,6 +406,8 @@ SKIP: {
|
||||
[ $master_inst, $slave1_inst ],
|
||||
);
|
||||
|
||||
Pingback::update_checks_file($file, $check_inst, int(time()));
|
||||
|
||||
ok(
|
||||
!$is_time,
|
||||
"...and false if there isn't anything to check",
|
||||
|
Reference in New Issue
Block a user