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)
|
if (!-e $strTestLogPath)
|
||||||
{
|
{
|
||||||
mkdir($strTestLogPath) or
|
mkdir($strTestLogPath, 0750) or
|
||||||
confess "unable to create expect log path ${strTestLogPath}";
|
confess "unable to create expect log path ${strTestLogPath}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,8 +143,8 @@ sub BackRestTestCommon_Drop
|
|||||||
# Remove the backrest private directory
|
# Remove the backrest private directory
|
||||||
BackRestTestCommon_DropRepo();
|
BackRestTestCommon_DropRepo();
|
||||||
|
|
||||||
# Remove the test directory
|
# Remove contents of the test directory
|
||||||
BackRestTestCommon_PathRemove(BackRestTestCommon_TestPathGet());
|
executeTest('rm -rf ' . BackRestTestCommon_TestPathGet() . '/*');
|
||||||
}
|
}
|
||||||
|
|
||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
@ -152,8 +152,8 @@ sub BackRestTestCommon_Drop
|
|||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
sub BackRestTestCommon_Create
|
sub BackRestTestCommon_Create
|
||||||
{
|
{
|
||||||
# Create the test directory
|
# 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
|
||||||
BackRestTestCommon_PathCreate(BackRestTestCommon_TestPathGet(), '0770');
|
# test init needs to be done when refactoring.
|
||||||
}
|
}
|
||||||
|
|
||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
|
@ -19,6 +19,7 @@ use Scalar::Util qw(blessed);
|
|||||||
|
|
||||||
use pgBackRest::Common::Ini;
|
use pgBackRest::Common::Ini;
|
||||||
use pgBackRest::Common::Log;
|
use pgBackRest::Common::Log;
|
||||||
|
use pgBackRest::Common::String;
|
||||||
use pgBackRest::FileCommon;
|
use pgBackRest::FileCommon;
|
||||||
|
|
||||||
use pgBackRestTest::Common::ExecuteTest;
|
use pgBackRestTest::Common::ExecuteTest;
|
||||||
@ -120,7 +121,7 @@ sub containerWrite
|
|||||||
my $bForce = shift;
|
my $bForce = shift;
|
||||||
|
|
||||||
# Write the image
|
# Write the image
|
||||||
fileStringWrite("${strTempPath}/${strImageName}", "$strImage\n", false);
|
fileStringWrite("${strTempPath}/${strImageName}", trim($strImage) . "\n", false);
|
||||||
executeTest('docker build' . (defined($bForce) && $bForce ? ' --no-cache' : '') .
|
executeTest('docker build' . (defined($bForce) && $bForce ? ' --no-cache' : '') .
|
||||||
" -f ${strTempPath}/${strImageName} -t backrest/${strImageName} ${strTempPath}",
|
" -f ${strTempPath}/${strImageName} -t backrest/${strImageName} ${strTempPath}",
|
||||||
{bSuppressStdErr => true});
|
{bSuppressStdErr => true});
|
||||||
@ -500,7 +501,7 @@ sub containerBuild
|
|||||||
|
|
||||||
# Install Perl packages
|
# Install Perl packages
|
||||||
$strImage .=
|
$strImage .=
|
||||||
"\n\n" . perlInstall($strOS) . "\n";
|
"\n\n" . perlInstall($strOS);
|
||||||
|
|
||||||
# Make PostgreSQL home group readable
|
# Make PostgreSQL home group readable
|
||||||
$strImage .=
|
$strImage .=
|
||||||
|
@ -47,14 +47,11 @@ sub BackRestTestFile_Setup
|
|||||||
system("ssh ${strUserBackRest}\@${strHost} 'rm -rf ${strTestPath}/private'");
|
system("ssh ${strUserBackRest}\@${strHost} 'rm -rf ${strTestPath}/private'");
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove the test directory
|
# Remove contents of the test directory
|
||||||
system("rm -rf ${strTestPath}") == 0 or die 'unable to drop test path';
|
system("rm -rf ${strTestPath}/*") == 0 or die 'unable to drop test path';
|
||||||
|
|
||||||
if (!defined($bDropOnly) || !$bDropOnly)
|
if (!defined($bDropOnly) || !$bDropOnly)
|
||||||
{
|
{
|
||||||
# Create the test directory
|
|
||||||
mkdir($strTestPath, oct('0770')) or confess 'Unable to create test directory';
|
|
||||||
|
|
||||||
# Create the backrest private directory
|
# Create the backrest private directory
|
||||||
if (defined($bPrivate) && $bPrivate)
|
if (defined($bPrivate) && $bPrivate)
|
||||||
{
|
{
|
||||||
@ -102,8 +99,7 @@ sub BackRestTestFile_Test
|
|||||||
#-------------------------------------------------------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------------------------------------------------------
|
||||||
# Create remotes
|
# Create remotes
|
||||||
#-------------------------------------------------------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------------------------------------------------------
|
||||||
mkdir($strTestPath, oct('0770')) or confess 'Unable to create test directory';
|
mkdir($strTestPath . '/backrest', oct('0770')) or confess 'Unable to create backrest directory';
|
||||||
mkdir($strTestPath . '/backrest', oct('0770')) or confess 'Unable to create test directory';
|
|
||||||
|
|
||||||
my $oRemote = new pgBackRest::Protocol::RemoteMaster
|
my $oRemote = new pgBackRest::Protocol::RemoteMaster
|
||||||
(
|
(
|
||||||
|
46
test/test.pl
46
test/test.pl
@ -27,6 +27,7 @@ use pgBackRest::Common::Log;
|
|||||||
use pgBackRest::Common::String;
|
use pgBackRest::Common::String;
|
||||||
use pgBackRest::Common::Wait;
|
use pgBackRest::Common::Wait;
|
||||||
use pgBackRest::Db;
|
use pgBackRest::Db;
|
||||||
|
use pgBackRest::FileCommon;
|
||||||
use pgBackRest::Version;
|
use pgBackRest::Version;
|
||||||
|
|
||||||
use lib dirname($0) . '/lib';
|
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';
|
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
|
# Build Docker containers
|
||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
@ -485,6 +492,9 @@ eval
|
|||||||
push(@{$oyProcess}, undef);
|
push(@{$oyProcess}, undef);
|
||||||
executeTest("docker rm -f test-${iProcessIdx}", {bSuppressError => true});
|
executeTest("docker rm -f test-${iProcessIdx}", {bSuppressError => true});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
executeTest("sudo rm -rf ${strTestPath}/*");
|
||||||
|
filePathCreate($strTestPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bDryRun)
|
if ($bDryRun)
|
||||||
@ -539,7 +549,11 @@ eval
|
|||||||
|
|
||||||
if (!$bNoCleanup)
|
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;
|
$$oyProcess[$iProcessIdx] = undef;
|
||||||
@ -579,12 +593,22 @@ eval
|
|||||||
&log($bDryRun && !$bVmOut || $bShowOutputAsync ? INFO : DEBUG, "${strTest}" .
|
&log($bDryRun && !$bVmOut || $bShowOutputAsync ? INFO : DEBUG, "${strTest}" .
|
||||||
($bVmOut || $bShowOutputAsync ? "\n" : ''));
|
($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)
|
if (!$bDryRun || $bVmOut)
|
||||||
{
|
{
|
||||||
|
# Create host test directory
|
||||||
|
filePathCreate($strHostTestPath, '0770');
|
||||||
|
|
||||||
executeTest("docker run -itd -h $$oTest{os}-test --name=${strImage}" .
|
executeTest("docker run -itd -h $$oTest{os}-test --name=${strImage}" .
|
||||||
|
" -v ${strHostTestPath}:${strVmTestPath}" .
|
||||||
" -v /backrest:/backrest backrest/$$oTest{os}-test-${strDbVersion}");
|
" -v /backrest:/backrest backrest/$$oTest{os}-test-${strDbVersion}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Build up command line for the individual test
|
||||||
$strCommandLine =~ s/\-\-os\=\S*//g;
|
$strCommandLine =~ s/\-\-os\=\S*//g;
|
||||||
$strCommandLine =~ s/\-\-test-path\=\S*//g;
|
$strCommandLine =~ s/\-\-test-path\=\S*//g;
|
||||||
$strCommandLine =~ s/\-\-module\=\S*//g;
|
$strCommandLine =~ s/\-\-module\=\S*//g;
|
||||||
@ -592,19 +616,25 @@ eval
|
|||||||
$strCommandLine =~ s/\-\-run\=\S*//g;
|
$strCommandLine =~ s/\-\-run\=\S*//g;
|
||||||
$strCommandLine =~ s/\-\-db\-version\=\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 =
|
||||||
" --vm=none --module=$$oTest{module} --test=$$oTest{test}" .
|
"docker exec -i -u vagrant ${strImage} $0 ${strCommandLine} --test-path=${strVmTestPath}" .
|
||||||
(defined($$oTest{run}) ? " --run=$$oTest{run}" : '') .
|
" --vm=none --module=$$oTest{module} --test=$$oTest{test}" .
|
||||||
(defined($$oTest{thread}) ? " --thread-max=$$oTest{thread}" : '') .
|
(defined($$oTest{run}) ? " --run=$$oTest{run}" : '') .
|
||||||
(defined($$oTest{db}) ? " --db-version=$$oTest{db}" : '') .
|
(defined($$oTest{thread}) ? " --thread-max=$$oTest{thread}" : '') .
|
||||||
($bDryRun ? " --dry-run" : '') .
|
(defined($$oTest{db}) ? " --db-version=$$oTest{db}" : '') .
|
||||||
" --no-cleanup --vm-out";
|
($bDryRun ? " --dry-run" : '') .
|
||||||
|
" --no-cleanup --vm-out";
|
||||||
|
|
||||||
&log(DEBUG, $strCommand);
|
&log(DEBUG, $strCommand);
|
||||||
|
|
||||||
if (!$bDryRun || $bVmOut)
|
if (!$bDryRun || $bVmOut)
|
||||||
{
|
{
|
||||||
my $fTestStartTime = gettimeofday();
|
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(
|
my $oExec = new pgBackRestTest::Common::ExecuteTest(
|
||||||
$strCommand,
|
$strCommand,
|
||||||
{bSuppressError => true, bShowOutputAsync => $bShowOutputAsync});
|
{bSuppressError => true, bShowOutputAsync => $bShowOutputAsync});
|
||||||
|
Reference in New Issue
Block a user