You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-06-27 00:21:08 +02:00
Test directories are now located on the host VM rather than in the Docker container.
This change allows for easier testing since all files are local on the host VM and can be easily accessed without using `docker exec`. In addition, this change is required to allow multiple Docker containers per test case which is coming soon.
This commit is contained in:
@ -222,7 +222,7 @@ sub logWrite
|
||||
|
||||
if (!-e $strTestLogPath)
|
||||
{
|
||||
mkdir($strTestLogPath) or
|
||||
mkdir($strTestLogPath, 0750) or
|
||||
confess "unable to create expect log path ${strTestLogPath}";
|
||||
}
|
||||
|
||||
|
@ -143,8 +143,8 @@ sub BackRestTestCommon_Drop
|
||||
# Remove the backrest private directory
|
||||
BackRestTestCommon_DropRepo();
|
||||
|
||||
# Remove the test directory
|
||||
BackRestTestCommon_PathRemove(BackRestTestCommon_TestPathGet());
|
||||
# Remove contents of the test directory
|
||||
executeTest('rm -rf ' . BackRestTestCommon_TestPathGet() . '/*');
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
@ -152,8 +152,8 @@ sub BackRestTestCommon_Drop
|
||||
####################################################################################################################################
|
||||
sub BackRestTestCommon_Create
|
||||
{
|
||||
# Create the test directory
|
||||
BackRestTestCommon_PathCreate(BackRestTestCommon_TestPathGet(), '0770');
|
||||
# Test directory is now created in parent VM so nothing to do here. Leaving as a place holder for a while in case any other
|
||||
# test init needs to be done when refactoring.
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
|
@ -19,6 +19,7 @@ use Scalar::Util qw(blessed);
|
||||
|
||||
use pgBackRest::Common::Ini;
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::Common::String;
|
||||
use pgBackRest::FileCommon;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
@ -120,7 +121,7 @@ sub containerWrite
|
||||
my $bForce = shift;
|
||||
|
||||
# Write the image
|
||||
fileStringWrite("${strTempPath}/${strImageName}", "$strImage\n", false);
|
||||
fileStringWrite("${strTempPath}/${strImageName}", trim($strImage) . "\n", false);
|
||||
executeTest('docker build' . (defined($bForce) && $bForce ? ' --no-cache' : '') .
|
||||
" -f ${strTempPath}/${strImageName} -t backrest/${strImageName} ${strTempPath}",
|
||||
{bSuppressStdErr => true});
|
||||
@ -500,7 +501,7 @@ sub containerBuild
|
||||
|
||||
# Install Perl packages
|
||||
$strImage .=
|
||||
"\n\n" . perlInstall($strOS) . "\n";
|
||||
"\n\n" . perlInstall($strOS);
|
||||
|
||||
# Make PostgreSQL home group readable
|
||||
$strImage .=
|
||||
|
@ -47,14 +47,11 @@ sub BackRestTestFile_Setup
|
||||
system("ssh ${strUserBackRest}\@${strHost} 'rm -rf ${strTestPath}/private'");
|
||||
}
|
||||
|
||||
# Remove the test directory
|
||||
system("rm -rf ${strTestPath}") == 0 or die 'unable to drop test path';
|
||||
# Remove contents of the test directory
|
||||
system("rm -rf ${strTestPath}/*") == 0 or die 'unable to drop test path';
|
||||
|
||||
if (!defined($bDropOnly) || !$bDropOnly)
|
||||
{
|
||||
# Create the test directory
|
||||
mkdir($strTestPath, oct('0770')) or confess 'Unable to create test directory';
|
||||
|
||||
# Create the backrest private directory
|
||||
if (defined($bPrivate) && $bPrivate)
|
||||
{
|
||||
@ -102,8 +99,7 @@ sub BackRestTestFile_Test
|
||||
#-------------------------------------------------------------------------------------------------------------------------------
|
||||
# Create remotes
|
||||
#-------------------------------------------------------------------------------------------------------------------------------
|
||||
mkdir($strTestPath, oct('0770')) or confess 'Unable to create test directory';
|
||||
mkdir($strTestPath . '/backrest', oct('0770')) or confess 'Unable to create test directory';
|
||||
mkdir($strTestPath . '/backrest', oct('0770')) or confess 'Unable to create backrest directory';
|
||||
|
||||
my $oRemote = new pgBackRest::Protocol::RemoteMaster
|
||||
(
|
||||
|
34
test/test.pl
34
test/test.pl
@ -27,6 +27,7 @@ use pgBackRest::Common::Log;
|
||||
use pgBackRest::Common::String;
|
||||
use pgBackRest::Common::Wait;
|
||||
use pgBackRest::Db;
|
||||
use pgBackRest::FileCommon;
|
||||
use pgBackRest::Version;
|
||||
|
||||
use lib dirname($0) . '/lib';
|
||||
@ -190,6 +191,12 @@ if (defined($iThreadMax) && ($iThreadMax < 1 || $iThreadMax > 32))
|
||||
confess 'thread-max must be between 1 and 32';
|
||||
}
|
||||
|
||||
# Set test path if not expicitly set
|
||||
if (!defined($strTestPath))
|
||||
{
|
||||
$strTestPath = cwd() . '/test';
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# Build Docker containers
|
||||
####################################################################################################################################
|
||||
@ -485,6 +492,9 @@ eval
|
||||
push(@{$oyProcess}, undef);
|
||||
executeTest("docker rm -f test-${iProcessIdx}", {bSuppressError => true});
|
||||
}
|
||||
|
||||
executeTest("sudo rm -rf ${strTestPath}/*");
|
||||
filePathCreate($strTestPath);
|
||||
}
|
||||
|
||||
if ($bDryRun)
|
||||
@ -539,7 +549,11 @@ eval
|
||||
|
||||
if (!$bNoCleanup)
|
||||
{
|
||||
executeTest("docker rm -f test-${iProcessIdx}");
|
||||
my $strImage = 'test-' . $iProcessIdx;
|
||||
my $strHostTestPath = "${strTestPath}/${strImage}";
|
||||
|
||||
executeTest("docker rm -f ${strImage}");
|
||||
executeTest("sudo rm -rf ${strHostTestPath}");
|
||||
}
|
||||
|
||||
$$oyProcess[$iProcessIdx] = undef;
|
||||
@ -579,12 +593,22 @@ eval
|
||||
&log($bDryRun && !$bVmOut || $bShowOutputAsync ? INFO : DEBUG, "${strTest}" .
|
||||
($bVmOut || $bShowOutputAsync ? "\n" : ''));
|
||||
|
||||
my $strVmTestPath = "/home/vagrant/test/${strImage}";
|
||||
my $strHostTestPath = "${strTestPath}/${strImage}";
|
||||
|
||||
# Don't create the container if this is a dry run unless output from the VM is required. Ouput can be requested
|
||||
# to get more information about the specific tests that will be run.
|
||||
if (!$bDryRun || $bVmOut)
|
||||
{
|
||||
# Create host test directory
|
||||
filePathCreate($strHostTestPath, '0770');
|
||||
|
||||
executeTest("docker run -itd -h $$oTest{os}-test --name=${strImage}" .
|
||||
" -v ${strHostTestPath}:${strVmTestPath}" .
|
||||
" -v /backrest:/backrest backrest/$$oTest{os}-test-${strDbVersion}");
|
||||
}
|
||||
|
||||
# Build up command line for the individual test
|
||||
$strCommandLine =~ s/\-\-os\=\S*//g;
|
||||
$strCommandLine =~ s/\-\-test-path\=\S*//g;
|
||||
$strCommandLine =~ s/\-\-module\=\S*//g;
|
||||
@ -592,7 +616,8 @@ eval
|
||||
$strCommandLine =~ s/\-\-run\=\S*//g;
|
||||
$strCommandLine =~ s/\-\-db\-version\=\S*//g;
|
||||
|
||||
my $strCommand = "docker exec -i -u vagrant ${strImage} $0 ${strCommandLine} --test-path=/home/vagrant/test" .
|
||||
my $strCommand =
|
||||
"docker exec -i -u vagrant ${strImage} $0 ${strCommandLine} --test-path=${strVmTestPath}" .
|
||||
" --vm=none --module=$$oTest{module} --test=$$oTest{test}" .
|
||||
(defined($$oTest{run}) ? " --run=$$oTest{run}" : '') .
|
||||
(defined($$oTest{thread}) ? " --thread-max=$$oTest{thread}" : '') .
|
||||
@ -605,6 +630,11 @@ eval
|
||||
if (!$bDryRun || $bVmOut)
|
||||
{
|
||||
my $fTestStartTime = gettimeofday();
|
||||
|
||||
# Set permissions on the Docker test directory. This can be removed once users/groups are sync'd between
|
||||
# Docker and the host VM.
|
||||
executeTest("docker exec ${strImage} chown vagrant:postgres -R ${strVmTestPath}");
|
||||
|
||||
my $oExec = new pgBackRestTest::Common::ExecuteTest(
|
||||
$strCommand,
|
||||
{bSuppressError => true, bShowOutputAsync => $bShowOutputAsync});
|
||||
|
Reference in New Issue
Block a user