Files
percona-toolkit/t/pt-find/pt-find.t
Sveta Smirnova 2f584c85db PT-2140 - Update modules in the main branch (#570)
* PT-2140 - Update modules in the main branch

Updated modules for:
- pt-align
- pt-archiver
- pt-config-diff
- pt-deadlock-logger
- pt-diskstats
- pt-duplicate-key-checker
- pt-fifo-split
- pt-find
- pt-fingerprint
- pt-fk-error-logger
- pt-heartbeat
- pt-index-usage
- pt-ioprofile
- pt-kill
- pt-mext
- pt-mysql-summary
- pt-online-schema-change
- pt-pmp
- pt-query-digest
- pt-show-grants
- pt-sift
- pt-slave-delay
- pt-slave-find
- pt-slave-restart
- pt-summary
- pt-table-sync
- pt-upgrade
- pt-variable-advisor

Added execute bit for pt-query-digest

* PT-2140 Update modules in the main branch

Fixed Daemon.pm plugin usage
Updated all tests, related to the Daemon plugin.
I intentionally did not fix failing tests, not related to Daemon plugin,
to avoid making this PR too big.

- bin/pt-archiver
	- PT-2141 - Fixed usage of Daemon.pm
	- PT-2141 - Updated t/pt-archiver/standard_options.t
- bin/pt-deadlock-logger
	- PT-2143 - Fixed usage of Daemon.pm
	- PT-2143 - Updated t/pt-deadlock-logger/standard_options.t
- bin/pt-fifo-split
	- PT-2144 - Fixed usage of Daemon.pm
	- PT-2144 - Updated t/pt-fifo-split/pt-fifo-split.t
- bin/pt-find
	- PT-2145 - Fixed usage of Daemon.pm
	- PT-2145 - Updated t/pt-find/pt-find.t
- bin/pt-fk-error-logger
	- PT-2146 - Fixed usage of Daemon.pm
	- PT-2146 - Updated t/pt-fk-error-logger/basics.t
- bin/pt-heartbeat
	- PT-2147 - Fixed usage of Daemon.pm
	- PT-2147 - Updated t/pt-heartbeat/standard_options.t, t/pt-heartbeat/basics.t
- bin/pt-kill
	- PT-2148 - Fixed usage of Daemon.pm
	- PT-2148 - Updated t/pt-kill/standard_options.t
- bin/pt-show-grants
	- PT-2152 - Fixed usage of Daemon.pm
	- PT-2152 - Updated t/pt-show-grants/standard_options.t
- bin/pt-slave-delay
	- Fixed usage of Daemon.pm
	- Updated t/pt-slave-delay/standard_options.t
- bin/pt-slave-find
	- PT-2153 - Fixed usage of Daemon.pm
	- PT-2153 -Updated t/pt-slave-find/pt-slave-find.t
- bin/pt-slave-restart
	- Fixed usage of Daemon.pm
	- Updated t/pt-slave-restart/pt-slave-restart.t
- bin/pt-table-sync
	- PT-2154 - Fixed usage of Daemon.pm
	- PT-2154 -Updated t/pt-table-sync/standard_options.t
2023-01-06 15:04:10 +03:00

304 lines
7.3 KiB
Perl

#!/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-find";
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $dbh = $sb->get_dbh_for('master');
if ( !$dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
$sb->load_file('master', 't/lib/samples/stored-objs.sql');
my $output;
my $cnf = '/tmp/12345/my.sandbox.cnf';
my $cmd = "$trunk/bin/pt-find -F $cnf ";
$output = `$cmd mysql --tblregex column`;
like($output, qr/`mysql`.`columns_priv`/, 'Found mysql.columns_priv');
$output = `$cmd mysql`;
like(
$output,
qr/`mysql`.`columns_priv`/,
'Prints tables without any tests'
);
$output = `$cmd --view .`;
like(
$output,
qr/`sakila`.`sales_by_store`/,
'Prints views'
);
unlike(
$output,
qr/`sakila`.`actor`/,
'Does not print non-views'
);
SKIP: {
skip 'Sandbox master does not have the sakila database', 17
unless @{$dbh->selectcol_arrayref("SHOW DATABASES LIKE 'sakila'")};
# ########################################################################
# First, test actions: --exec*, print*, etc.
# ########################################################################
# POD says: "[--print] is the default action if no other action is
# specified."
$output = `$cmd --autoinc 1001`;
is(
$output,
"`sakila`.`film`\n",
'--print is default action'
);
# Test that explicit --print doesn't blow up.
$output = `$cmd --autoinc 1001 --print`;
is(
$output,
"`sakila`.`film`\n",
'Explicit --print',
);
# Test --column-*
$output = `$cmd sakila --column-name release_year --print`;
is(
$output,
"`sakila`.`film`\n",
'--column-name'
);
$output = `$cmd sakila --tbllike actor --column-type smallint --print`;
is(
$output,
"`sakila`.`actor`\n",
'--column-type'
);
# Test --view.
$output = `$cmd sakila --view 'left join \`film_category\`' --print`;
is(
$output,
"`sakila`.`actor_info`
`sakila`.`film_list`
`sakila`.`nicer_but_slower_film_list`\n",
'--view that matches'
);
$output = `$cmd sakila --view blah --print`;
is(
$output,
'',
"--view that doesn't match"
);
# Test --procedure.
$output = `$cmd pt_find --procedure param1 --print`;
is(
$output,
"`pt_find`.`PROCEDURE simpleproc`\n",
'--procedure that matches'
);
$output = `$cmd pt_find --procedure blah --print`;
is(
$output,
'',
"--procedure that doesn't match"
);
# Test --function.
$output = `$cmd pt_find --function Hello --print`;
is(
$output,
"`pt_find`.`FUNCTION hello`\n",
'--function that matches'
);
$output = `$cmd pt_find --function blah --print`;
is(
$output,
'',
"--function that doesn't match"
);
# Test --trigger without --trigger-table.
$output = `$cmd pt_find --trigger 'INSERT INTO t2' --print`;
is(
$output,
"`pt_find`.`INSERT TRIGGER ins_trg on t1`\n",
'--trigger that matches without --trigger-table'
);
$output = `$cmd pt_find --trigger blah --print`;
is(
$output,
'',
"--trigger that doesn't match without --trigger-table"
);
# Test --trigger with --trigger-table.
$output = `$cmd pt_find --trigger 'INSERT INTO t2' --trigger-table t1 --print`;
is(
$output,
"`pt_find`.`INSERT TRIGGER ins_trg on t1`\n",
'--trigger that matches with matching --trigger-table'
);
$output = `$cmd pt_find --trigger blah --trigger-table t1 --print`;
is(
$output,
'',
"--trigger that doesn't match with matching --trigger-table"
);
$output = `$cmd pt_find --trigger 'INSERT INTO t2' --trigger-table foo --print`;
is(
$output,
'',
'--trigger that matches with non-matching --trigger-table'
);
$output = `$cmd pt_find --trigger blah --trigger-table foo --print`;
is(
$output,
'',
"--trigger that doesn't match with non-matching --trigger-table"
);
SKIP: {
skip "MySQL 8.0+ returns 0, not NULL", 1 if ($sandbox_version gt '5.7');
# Test NULL sizes.
$output = `$cmd sakila --datasize NULL`,
is(
$output,
"`sakila`.`actor_info`
`sakila`.`customer_list`
`sakila`.`film_list`
`sakila`.`nicer_but_slower_film_list`
`sakila`.`sales_by_film_category`
`sakila`.`sales_by_store`
`sakila`.`staff_list`
",
'--datasize NULL',
);
};
}
$sb->load_file('master', "t/pt-find/samples/pseudo-sakila.sql");
# Test --procedure.
$output = `$cmd sakila_test --procedure min_monthly_purchases --print`;
is(
$output,
"`sakila_test`.`PROCEDURE rewards_report`\n",
'--procedure that matches'
);
$output = `$cmd sakila_test --procedure blah --print`;
is(
$output,
'',
"--procedure that doesn't match"
);
# Test --function.
$output = `$cmd sakila_test --function v_out --print`;
is(
$output,
"`sakila_test`.`FUNCTION inventory_in_stock`\n",
'--function that matches'
);
$output = `$cmd sakila_test --function blah --print`;
is(
$output,
'',
"--function that doesn't match"
);
# Test --trigger without --trigger-table.
$output = `$cmd sakila_test --trigger 'UPDATE film_text' --print`;
is(
$output,
"`sakila_test`.`UPDATE TRIGGER upd_film on film`\n",
'--trigger that matches without --trigger-table'
);
$output = `$cmd sakila_test --trigger blah --print`;
is(
$output,
'',
"--trigger that doesn't match without --trigger-table"
);
# Test --trigger with --trigger-table.
$output = `$cmd sakila_test --trigger 'UPDATE film_text' --trigger-table film --print`;
is(
$output,
"`sakila_test`.`UPDATE TRIGGER upd_film on film`\n",
'--trigger that matches with matching --trigger-table'
);
$output = `$cmd sakila_test --trigger blah --trigger-table film --print`;
is(
$output,
'',
"--trigger that doesn't match with matching --trigger-table"
);
$output = `$cmd sakila_test --trigger 'UPDATE film_text' --trigger-table foo --print`;
is(
$output,
'',
'--trigger that matches with non-matching --trigger-table'
);
$output = `$cmd sakila_test --trigger blah --trigger-table foo --print`;
is(
$output,
'',
"--trigger that doesn't match with non-matching --trigger-table"
);
$dbh->do("DROP DATABASE sakila_test");
# #########################################################################
# Issue 391: Add --pid option to all scripts
# #########################################################################
`touch /tmp/mk-script.pid`;
$output = `$cmd mysql --pid /tmp/mk-script.pid 2>&1`;
like(
$output,
qr{PID file /tmp/mk-script.pid exists},
'Dies if PID file already exists (issue 391)'
);
`rm -rf /tmp/mk-script.pid`;
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
done_testing;
exit;