diff options
author | Michael Paquier <michael@paquier.xyz> | 2021-04-05 10:13:57 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2021-04-05 10:13:57 +0900 |
commit | c50624cdd248c13b4ba199f95e24c88d2cc8a097 (patch) | |
tree | 6fb036a55f9ad4f15b63cc64c23127d24759de6c /src/test/perl/PostgresNode.pm | |
parent | dfc843d465689d2c2af8b0e01c66c51ccaae2343 (diff) | |
download | postgresql-c50624cdd248c13b4ba199f95e24c88d2cc8a097.tar.gz postgresql-c50624cdd248c13b4ba199f95e24c88d2cc8a097.zip |
Refactor all TAP test suites doing connection checks
This commit refactors more TAP tests to adapt with the recent
introduction of connect_ok() and connect_fails() in PostgresNode,
introduced by 0d1a3343. This changes the following test suites to use
the same code paths for connection checks:
- Kerberos
- LDAP
- SSL
- Authentication
Those routines are extended to be able to handle optional parameters
that are set depending on each suite's needs, as of:
- custom SQL query.
- expected stderr matching pattern.
- expected stdout matching pattern.
The new design is extensible with more parameters, and there are some
plans for those routines in the future with checks based on the contents
of the backend logs.
Author: Jacob Champion, Michael Paquier
Discussion: https://postgr.es/m/d17b919e27474abfa55d97786cb9cfadfe2b59e9.camel@vmware.com
Diffstat (limited to 'src/test/perl/PostgresNode.pm')
-rw-r--r-- | src/test/perl/PostgresNode.pm | 71 |
1 files changed, 59 insertions, 12 deletions
diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm index d6e10544bb9..bbde34c9291 100644 --- a/src/test/perl/PostgresNode.pm +++ b/src/test/perl/PostgresNode.pm @@ -1860,47 +1860,94 @@ sub interactive_psql =pod -=item $node->connect_ok($connstr, $test_name) +=item $node->connect_ok($connstr, $test_name, %params) Attempt a connection with a custom connection string. This is expected to succeed. +=over + +=item sql => B<value> + +If this parameter is set, this query is used for the connection attempt +instead of the default. + +=item expected_stdout => B<value> + +If this regular expression is set, matches it with the output generated. + +=back + =cut sub connect_ok { local $Test::Builder::Level = $Test::Builder::Level + 1; - my ($self, $connstr, $test_name) = @_; - my ($ret, $stdout, $stderr) = $self->psql( + my ($self, $connstr, $test_name, %params) = @_; + + my $sql; + if (defined($params{sql})) + { + $sql = $params{sql}; + } + else + { + $sql = "SELECT \$\$connected with $connstr\$\$"; + } + + # Never prompt for a password, any callers of this routine should + # have set up things properly, and this should not block. + my ($ret, $stdout, $stderr) = $self->psql( 'postgres', - "SELECT \$\$connected with $connstr\$\$", + $sql, + extra_params => ['-w'], connstr => "$connstr", on_error_stop => 0); - ok($ret == 0, $test_name); + is($ret, 0, $test_name); + + if (defined($params{expected_stdout})) + { + like($stdout, $params{expected_stdout}, "$test_name: matches"); + } } =pod -=item $node->connect_fails($connstr, $expected_stderr, $test_name) +=item $node->connect_fails($connstr, $test_name, %params) Attempt a connection with a custom connection string. This is expected -to fail with a message that matches the regular expression -$expected_stderr. +to fail. + +=over + +=item expected_stderr => B<value> + +If this regular expression is set, matches it with the output generated. + +=back =cut sub connect_fails { local $Test::Builder::Level = $Test::Builder::Level + 1; - my ($self, $connstr, $expected_stderr, $test_name) = @_; + my ($self, $connstr, $test_name, %params) = @_; + + # Never prompt for a password, any callers of this routine should + # have set up things properly, and this should not block. my ($ret, $stdout, $stderr) = $self->psql( 'postgres', "SELECT \$\$connected with $connstr\$\$", - connstr => "$connstr"); + extra_params => ['-w'], + connstr => "$connstr"); - ok($ret != 0, $test_name); - like($stderr, $expected_stderr, "$test_name: matches"); + isnt($ret, 0, $test_name); + + if (defined($params{expected_stderr})) + { + like($stderr, $params{expected_stderr}, "$test_name: matches"); + } } =pod |