mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-06 14:47:10 +02:00
Make PostgreSQL::Test::Cluster::config_data more flexible
Currently this only allows for one argument, which must be present, and always returns a single string. With this change the following now all work: $all_config = $node->config_data; %config_map = ($node->config_data); $incdir = $node->config_data('--include-dir'); ($incdir, $sharedir) = $node->config_data( qw(--include-dir --share-dir)); Backpatch to release 15 where this was introduced. Discussion: https://postgr.es/m/73eea68e-3b6f-5f63-6024-25ed26b52016@dunslane.net Reviewed by Tom Lane, Alvaro Herrera, Michael Paquier.
This commit is contained in:
parent
e5f94d42eb
commit
7a387f513d
@ -26,6 +26,14 @@ PostgreSQL::Test::Cluster - class representing PostgreSQL server instance
|
|||||||
# Modify or delete an existing setting
|
# Modify or delete an existing setting
|
||||||
$node->adjust_conf('postgresql.conf', 'max_wal_senders', '10');
|
$node->adjust_conf('postgresql.conf', 'max_wal_senders', '10');
|
||||||
|
|
||||||
|
# get pg_config settings
|
||||||
|
# all the settings in one string
|
||||||
|
$pgconfig = $node->config_data;
|
||||||
|
# all the settings as a map
|
||||||
|
%config_map = ($node->config_data);
|
||||||
|
# specified settings
|
||||||
|
($incdir, $sharedir) = $node->config_data(qw(--includedir --sharedir));
|
||||||
|
|
||||||
# run a query with psql, like:
|
# run a query with psql, like:
|
||||||
# echo 'SELECT 1' | psql -qAXt postgres -v ON_ERROR_STOP=1
|
# echo 'SELECT 1' | psql -qAXt postgres -v ON_ERROR_STOP=1
|
||||||
$psql_stdout = $node->safe_psql('postgres', 'SELECT 1');
|
$psql_stdout = $node->safe_psql('postgres', 'SELECT 1');
|
||||||
@ -345,27 +353,46 @@ sub pg_version
|
|||||||
|
|
||||||
=pod
|
=pod
|
||||||
|
|
||||||
=item $node->config_data($option)
|
=item $node->config_data( option ...)
|
||||||
|
|
||||||
Return a string holding configuration data from pg_config, with $option
|
Return configuration data from pg_config, using options (if supplied).
|
||||||
being the option switch used with the pg_config command.
|
The options will be things like '--sharedir'.
|
||||||
|
|
||||||
|
If no options are supplied, return a string in scalar context or a map in
|
||||||
|
array context.
|
||||||
|
|
||||||
|
If options are supplied, return the list of values.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub config_data
|
sub config_data
|
||||||
{
|
{
|
||||||
my ($self, $option) = @_;
|
my ($self, @options) = @_;
|
||||||
local %ENV = $self->_get_env();
|
local %ENV = $self->_get_env();
|
||||||
|
|
||||||
my ($stdout, $stderr);
|
my ($stdout, $stderr);
|
||||||
my $result =
|
my $result =
|
||||||
IPC::Run::run [ $self->installed_command('pg_config'), $option ],
|
IPC::Run::run [ $self->installed_command('pg_config'), @options ],
|
||||||
'>', \$stdout, '2>', \$stderr
|
'>', \$stdout, '2>', \$stderr
|
||||||
or die "could not execute pg_config";
|
or die "could not execute pg_config";
|
||||||
|
# standardize line endings
|
||||||
|
$stdout =~ s/\r(?=\n)//g;
|
||||||
|
# no options, scalar context: just hand back the output
|
||||||
|
return $stdout unless (wantarray || @options);
|
||||||
chomp($stdout);
|
chomp($stdout);
|
||||||
$stdout =~ s/\r$//;
|
# exactly one option: hand back the output (minus LF)
|
||||||
|
return $stdout if (@options == 1);
|
||||||
return $stdout;
|
my @lines = split(/\n/, $stdout);
|
||||||
|
# more than one option: hand back the list of values;
|
||||||
|
return @lines if (@options);
|
||||||
|
# no options, array context: return a map
|
||||||
|
my @map;
|
||||||
|
foreach my $line (@lines)
|
||||||
|
{
|
||||||
|
my ($k,$v) = split (/ = /,$line,2);
|
||||||
|
push(@map, $k, $v);
|
||||||
|
}
|
||||||
|
return @map;
|
||||||
}
|
}
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
|
Loading…
Reference in New Issue
Block a user