Commit 642bafa0 authored by Peter Eisentraut's avatar Peter Eisentraut

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>
parent 74594842
...@@ -26,9 +26,52 @@ use Test::More; ...@@ -26,9 +26,52 @@ use Test::More;
use Exporter 'import'; use Exporter 'import';
our @EXPORT = qw( 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 # Copy a set of files, taking into account wildcards
sub copy_files sub copy_files
{ {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment