mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
Refactor routine to test connection to SSL server
Move the sub-routines wrappers to check if a connection to a server is fine or not into the test main module. This is useful for other tests willing to check connectivity into a server. Author: Michael Paquier <michael@paquier.xyz>
This commit is contained in:
@ -26,9 +26,52 @@ use Test::More;
|
||||
|
||||
use Exporter 'import';
|
||||
our @EXPORT = qw(
|
||||
configure_test_server_for_ssl switch_server_cert
|
||||
configure_test_server_for_ssl
|
||||
run_test_psql
|
||||
switch_server_cert
|
||||
test_connect_fails
|
||||
test_connect_ok
|
||||
);
|
||||
|
||||
# Define a couple of helper functions to test connecting to the server.
|
||||
|
||||
# Attempt connection to server with given connection string.
|
||||
sub run_test_psql
|
||||
{
|
||||
my $connstr = $_[0];
|
||||
my $logstring = $_[1];
|
||||
|
||||
my $cmd = [
|
||||
'psql', '-X', '-A', '-t', '-c', "SELECT 'connected with $connstr'",
|
||||
'-d', "$connstr" ];
|
||||
|
||||
my $result = run_log($cmd);
|
||||
return $result;
|
||||
}
|
||||
|
||||
#
|
||||
# The first argument is a base connection string to use for connection.
|
||||
# The second argument is a complementary connection string, and it's also
|
||||
# printed out as the test case name.
|
||||
sub test_connect_ok
|
||||
{
|
||||
my $common_connstr = $_[0];
|
||||
my $connstr = $_[1];
|
||||
|
||||
my $result =
|
||||
run_test_psql("$common_connstr $connstr", "(should succeed)");
|
||||
ok($result, $connstr);
|
||||
}
|
||||
|
||||
sub test_connect_fails
|
||||
{
|
||||
my $common_connstr = $_[0];
|
||||
my $connstr = $_[1];
|
||||
|
||||
my $result = run_test_psql("$common_connstr $connstr", "(should fail)");
|
||||
ok(!$result, "$connstr (should fail)");
|
||||
}
|
||||
|
||||
# Copy a set of files, taking into account wildcards
|
||||
sub copy_files
|
||||
{
|
||||
|
Reference in New Issue
Block a user