mirror of
https://github.com/postgres/postgres.git
synced 2025-08-05 07:41:25 +03:00
Improve grammar of options for command arrays in TAP tests
This commit rewrites a good chunk of the command arrays in TAP tests with a grammar based on the following rules: - Fat commas are used between option names and their values, making it clear to both humans and perltidy that values and names are bound together. This is particularly useful for the readability of multi-line command arrays, and there are plenty of them in the TAP tests. Most of the test code is updated to use this style. Some commands used parenthesis to show the link, or attached values and options in a single string. These are updated to use fat commas instead. - Option names are switched to use their long names, making them more self-documented. Based on a suggestion by Andrew Dunstan. - Add some trailing commas after the last item in multi-line arrays, which is a common perl style. Not all the places are taken care of, but this covers a very good chunk of them. Author: Dagfinn Ilmari Mannsåker Reviewed-by: Michael Paquier, Peter Smith, Euler Taveira Discussion: https://postgr.es/m/87jzc46d8u.fsf@wibble.ilmari.org
This commit is contained in:
@@ -15,10 +15,15 @@ program_help_ok('pg_ctl');
|
||||
program_version_ok('pg_ctl');
|
||||
program_options_handling_ok('pg_ctl');
|
||||
|
||||
command_exit_is([ 'pg_ctl', 'start', '-D', "$tempdir/nonexistent" ],
|
||||
command_exit_is([ 'pg_ctl', 'start', '--pgdata' => "$tempdir/nonexistent" ],
|
||||
1, 'pg_ctl start with nonexistent directory');
|
||||
|
||||
command_ok([ 'pg_ctl', 'initdb', '-D', "$tempdir/data", '-o', '-N' ],
|
||||
command_ok(
|
||||
[
|
||||
'pg_ctl', 'initdb',
|
||||
'--pgdata' => "$tempdir/data",
|
||||
'--options' => '--no-sync'
|
||||
],
|
||||
'pg_ctl initdb');
|
||||
command_ok([ $ENV{PG_REGRESS}, '--config-auth', "$tempdir/data" ],
|
||||
'configure authentication');
|
||||
@@ -41,8 +46,9 @@ else
|
||||
}
|
||||
close $conf;
|
||||
my $ctlcmd = [
|
||||
'pg_ctl', 'start', '-D', "$tempdir/data", '-l',
|
||||
"$PostgreSQL::Test::Utils::log_path/001_start_stop_server.log"
|
||||
'pg_ctl', 'start',
|
||||
'--pgdata' => "$tempdir/data",
|
||||
'--log' => "$PostgreSQL::Test::Utils::log_path/001_start_stop_server.log"
|
||||
];
|
||||
command_like($ctlcmd, qr/done.*server started/s, 'pg_ctl start');
|
||||
|
||||
@@ -51,17 +57,23 @@ command_like($ctlcmd, qr/done.*server started/s, 'pg_ctl start');
|
||||
# postmaster they start. Waiting more than the 2 seconds slop time allowed
|
||||
# by wait_for_postmaster() prevents that mistake.
|
||||
sleep 3 if ($windows_os);
|
||||
command_fails([ 'pg_ctl', 'start', '-D', "$tempdir/data" ],
|
||||
command_fails([ 'pg_ctl', 'start', '--pgdata' => "$tempdir/data" ],
|
||||
'second pg_ctl start fails');
|
||||
command_ok([ 'pg_ctl', 'stop', '-D', "$tempdir/data" ], 'pg_ctl stop');
|
||||
command_fails([ 'pg_ctl', 'stop', '-D', "$tempdir/data" ],
|
||||
command_ok([ 'pg_ctl', 'stop', '--pgdata' => "$tempdir/data" ],
|
||||
'pg_ctl stop');
|
||||
command_fails([ 'pg_ctl', 'stop', '--pgdata' => "$tempdir/data" ],
|
||||
'second pg_ctl stop fails');
|
||||
|
||||
# Log file for default permission test. The permissions won't be checked on
|
||||
# Windows but we still want to do the restart test.
|
||||
my $logFileName = "$tempdir/data/perm-test-600.log";
|
||||
|
||||
command_ok([ 'pg_ctl', 'restart', '-D', "$tempdir/data", '-l', $logFileName ],
|
||||
command_ok(
|
||||
[
|
||||
'pg_ctl', 'restart',
|
||||
'--pgdata' => "$tempdir/data",
|
||||
'--log' => $logFileName
|
||||
],
|
||||
'pg_ctl restart with server not running');
|
||||
|
||||
# Permissions on log file should be default
|
||||
@@ -82,23 +94,27 @@ SKIP:
|
||||
skip "group access not supported on Windows", 3
|
||||
if ($windows_os || $Config::Config{osname} eq 'cygwin');
|
||||
|
||||
system_or_bail 'pg_ctl', 'stop', '-D', "$tempdir/data";
|
||||
system_or_bail 'pg_ctl', 'stop', '--pgdata' => "$tempdir/data";
|
||||
|
||||
# Change the data dir mode so log file will be created with group read
|
||||
# privileges on the next start
|
||||
chmod_recursive("$tempdir/data", 0750, 0640);
|
||||
|
||||
command_ok(
|
||||
[ 'pg_ctl', 'start', '-D', "$tempdir/data", '-l', $logFileName ],
|
||||
[
|
||||
'pg_ctl', 'start',
|
||||
'--pgdata' => "$tempdir/data",
|
||||
'--log' => $logFileName
|
||||
],
|
||||
'start server to check group permissions');
|
||||
|
||||
ok(-f $logFileName);
|
||||
ok(check_mode_recursive("$tempdir/data", 0750, 0640));
|
||||
}
|
||||
|
||||
command_ok([ 'pg_ctl', 'restart', '-D', "$tempdir/data" ],
|
||||
command_ok([ 'pg_ctl', 'restart', '--pgdata' => "$tempdir/data" ],
|
||||
'pg_ctl restart with server running');
|
||||
|
||||
system_or_bail 'pg_ctl', 'stop', '-D', "$tempdir/data";
|
||||
system_or_bail 'pg_ctl', 'stop', '--pgdata' => "$tempdir/data";
|
||||
|
||||
done_testing();
|
||||
|
@@ -10,20 +10,23 @@ use Test::More;
|
||||
|
||||
my $tempdir = PostgreSQL::Test::Utils::tempdir;
|
||||
|
||||
command_exit_is([ 'pg_ctl', 'status', '-D', "$tempdir/nonexistent" ],
|
||||
command_exit_is([ 'pg_ctl', 'status', '--pgdata' => "$tempdir/nonexistent" ],
|
||||
4, 'pg_ctl status with nonexistent directory');
|
||||
|
||||
my $node = PostgreSQL::Test::Cluster->new('main');
|
||||
$node->init;
|
||||
|
||||
command_exit_is([ 'pg_ctl', 'status', '-D', $node->data_dir ],
|
||||
command_exit_is([ 'pg_ctl', 'status', '--pgdata' => $node->data_dir ],
|
||||
3, 'pg_ctl status with server not running');
|
||||
|
||||
system_or_bail 'pg_ctl', '-l', "$tempdir/logfile", '-D',
|
||||
$node->data_dir, '-w', 'start';
|
||||
command_exit_is([ 'pg_ctl', 'status', '-D', $node->data_dir ],
|
||||
system_or_bail(
|
||||
'pg_ctl',
|
||||
'--log' => "$tempdir/logfile",
|
||||
'--pgdata' => $node->data_dir,
|
||||
'--wait', 'start');
|
||||
command_exit_is([ 'pg_ctl', 'status', '--pgdata' => $node->data_dir ],
|
||||
0, 'pg_ctl status with server running');
|
||||
|
||||
system_or_bail 'pg_ctl', 'stop', '-D', $node->data_dir;
|
||||
system_or_bail 'pg_ctl', 'stop', '--pgdata' => $node->data_dir;
|
||||
|
||||
done_testing();
|
||||
|
@@ -11,7 +11,7 @@ use Test::More;
|
||||
my $tempdir = PostgreSQL::Test::Utils::tempdir;
|
||||
|
||||
command_fails_like(
|
||||
[ 'pg_ctl', '-D', "$tempdir/nonexistent", 'promote' ],
|
||||
[ 'pg_ctl', '--pgdata' => "$tempdir/nonexistent", 'promote' ],
|
||||
qr/directory .* does not exist/,
|
||||
'pg_ctl promote with nonexistent directory');
|
||||
|
||||
@@ -19,14 +19,14 @@ my $node_primary = PostgreSQL::Test::Cluster->new('primary');
|
||||
$node_primary->init(allows_streaming => 1);
|
||||
|
||||
command_fails_like(
|
||||
[ 'pg_ctl', '-D', $node_primary->data_dir, 'promote' ],
|
||||
[ 'pg_ctl', '--pgdata' => $node_primary->data_dir, 'promote' ],
|
||||
qr/PID file .* does not exist/,
|
||||
'pg_ctl promote of not running instance fails');
|
||||
|
||||
$node_primary->start;
|
||||
|
||||
command_fails_like(
|
||||
[ 'pg_ctl', '-D', $node_primary->data_dir, 'promote' ],
|
||||
[ 'pg_ctl', '--pgdata' => $node_primary->data_dir, 'promote' ],
|
||||
qr/not in standby mode/,
|
||||
'pg_ctl promote of primary instance fails');
|
||||
|
||||
@@ -39,8 +39,13 @@ $node_standby->start;
|
||||
is($node_standby->safe_psql('postgres', 'SELECT pg_is_in_recovery()'),
|
||||
't', 'standby is in recovery');
|
||||
|
||||
command_ok([ 'pg_ctl', '-D', $node_standby->data_dir, '-W', 'promote' ],
|
||||
'pg_ctl -W promote of standby runs');
|
||||
command_ok(
|
||||
[
|
||||
'pg_ctl',
|
||||
'--pgdata' => $node_standby->data_dir,
|
||||
'--no-wait', 'promote'
|
||||
],
|
||||
'pg_ctl --no-wait promote of standby runs');
|
||||
|
||||
ok( $node_standby->poll_query_until(
|
||||
'postgres', 'SELECT NOT pg_is_in_recovery()'),
|
||||
@@ -55,7 +60,7 @@ $node_standby->start;
|
||||
is($node_standby->safe_psql('postgres', 'SELECT pg_is_in_recovery()'),
|
||||
't', 'standby is in recovery');
|
||||
|
||||
command_ok([ 'pg_ctl', '-D', $node_standby->data_dir, 'promote' ],
|
||||
command_ok([ 'pg_ctl', '--pgdata' => $node_standby->data_dir, 'promote' ],
|
||||
'pg_ctl promote of standby runs');
|
||||
|
||||
# no wait here
|
||||
|
Reference in New Issue
Block a user