aboutsummaryrefslogtreecommitdiff
path: root/src/test/perl/PostgreSQL/Test/Cluster.pm
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2022-11-13 08:45:14 -0500
committerAndrew Dunstan <andrew@dunslane.net>2022-11-13 09:00:38 -0500
commita688c39e1dca56490527ccac13ea4ac752c7116a (patch)
treec31c2a241ecff616099176ae266bd481e271fc05 /src/test/perl/PostgreSQL/Test/Cluster.pm
parentc727f511bd7bf3c58063737bcf7a8f331346f253 (diff)
downloadpostgresql-a688c39e1dca56490527ccac13ea4ac752c7116a.tar.gz
postgresql-a688c39e1dca56490527ccac13ea4ac752c7116a.zip
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.
Diffstat (limited to 'src/test/perl/PostgreSQL/Test/Cluster.pm')
-rw-r--r--src/test/perl/PostgreSQL/Test/Cluster.pm43
1 files changed, 35 insertions, 8 deletions
diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm
index d1017b746fc..c7531c5efb4 100644
--- a/src/test/perl/PostgreSQL/Test/Cluster.pm
+++ b/src/test/perl/PostgreSQL/Test/Cluster.pm
@@ -26,6 +26,14 @@ PostgreSQL::Test::Cluster - class representing PostgreSQL server instance
# Modify or delete an existing setting
$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:
# echo 'SELECT 1' | psql -qAXt postgres -v ON_ERROR_STOP=1
$psql_stdout = $node->safe_psql('postgres', 'SELECT 1');
@@ -345,27 +353,46 @@ sub pg_version
=pod
-=item $node->config_data($option)
+=item $node->config_data( option ...)
+
+Return configuration data from pg_config, using options (if supplied).
+The options will be things like '--sharedir'.
-Return a string holding configuration data from pg_config, with $option
-being the option switch used with the pg_config command.
+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
sub config_data
{
- my ($self, $option) = @_;
+ my ($self, @options) = @_;
local %ENV = $self->_get_env();
my ($stdout, $stderr);
my $result =
- IPC::Run::run [ $self->installed_command('pg_config'), $option ],
+ IPC::Run::run [ $self->installed_command('pg_config'), @options ],
'>', \$stdout, '2>', \$stderr
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);
- $stdout =~ s/\r$//;
-
- return $stdout;
+ # exactly one option: hand back the output (minus LF)
+ return $stdout if (@options == 1);
+ 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