2014-06-22 17:30:17 +03:00
|
|
|
####################################################################################################################################
|
|
|
|
# CommonTest.pm - Common globals used for testing
|
|
|
|
####################################################################################################################################
|
2016-04-14 15:30:54 +02:00
|
|
|
package pgBackRestTest::CommonTest;
|
2014-06-22 17:30:17 +03:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
2015-03-03 07:57:20 +02:00
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
2014-06-22 17:30:17 +03:00
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
use Cwd qw(abs_path);
|
2015-06-14 00:25:49 +02:00
|
|
|
use Exporter qw(import);
|
2016-06-24 14:12:58 +02:00
|
|
|
our @EXPORT = qw();
|
|
|
|
use File::Basename qw(dirname);
|
|
|
|
|
2016-04-14 15:30:54 +02:00
|
|
|
use pgBackRest::Common::Ini;
|
|
|
|
use pgBackRest::Common::Log;
|
2015-10-08 17:43:56 +02:00
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
use pgBackRestTest::Common::LogTest;
|
2014-06-22 17:30:17 +03:00
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Module variables
|
|
|
|
####################################################################################################################################
|
2014-08-11 04:22:17 +03:00
|
|
|
my $strPgSqlBin;
|
2014-06-22 21:51:28 +03:00
|
|
|
my $strCommonCommandMain;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $strCommonBasePath;
|
2014-06-22 17:30:17 +03:00
|
|
|
my $strCommonTestPath;
|
2014-07-13 16:13:19 +03:00
|
|
|
my $strCommonDataPath;
|
2015-03-12 18:15:19 +02:00
|
|
|
my $strCommonRepoPath;
|
2014-06-22 21:51:28 +03:00
|
|
|
my $strCommonDbPath;
|
|
|
|
my $strCommonDbCommonPath;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $iModuleTestRunOnly;
|
2014-07-16 05:32:41 +03:00
|
|
|
my $bDryRun;
|
|
|
|
my $bNoCleanup;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $bLogForce;
|
2014-07-16 05:32:41 +03:00
|
|
|
|
|
|
|
####################################################################################################################################
|
2016-06-24 14:12:58 +02:00
|
|
|
# testRun
|
2014-07-16 05:32:41 +03:00
|
|
|
####################################################################################################################################
|
2016-06-24 14:12:58 +02:00
|
|
|
sub testRun
|
2014-07-16 05:32:41 +03:00
|
|
|
{
|
|
|
|
my $iRun = shift;
|
|
|
|
my $strLog = shift;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $strModuleParam = shift;
|
|
|
|
my $strModuleTestParam = shift;
|
2015-10-08 17:43:56 +02:00
|
|
|
my $oLogTestRef = shift;
|
2015-05-05 19:08:48 +02:00
|
|
|
|
2015-10-08 17:43:56 +02:00
|
|
|
# Save the previous test log
|
|
|
|
if (defined($$oLogTestRef))
|
2014-07-16 05:32:41 +03:00
|
|
|
{
|
2016-06-24 14:12:58 +02:00
|
|
|
$$oLogTestRef->logWrite($strCommonBasePath, $strCommonTestPath);
|
2015-10-08 17:43:56 +02:00
|
|
|
$$oLogTestRef = undef;
|
2014-07-16 05:32:41 +03:00
|
|
|
}
|
|
|
|
|
2015-10-08 17:43:56 +02:00
|
|
|
# Return if this test should not be run
|
2016-01-14 05:43:26 +02:00
|
|
|
if (defined($iModuleTestRunOnly) && $iModuleTestRunOnly != $iRun)
|
2014-07-16 05:32:41 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-08 17:43:56 +02:00
|
|
|
# Output information about test to run
|
|
|
|
&log(INFO, 'run ' . sprintf('%03d', $iRun) . ' - ' . $strLog);
|
2015-05-05 19:08:48 +02:00
|
|
|
|
2016-01-14 05:43:26 +02:00
|
|
|
if ($bDryRun)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-08 17:43:56 +02:00
|
|
|
# If the module is defined then create a LogTest object
|
|
|
|
if (defined($strModuleParam))
|
|
|
|
{
|
2016-06-24 14:12:58 +02:00
|
|
|
$$oLogTestRef = new pgBackRestTest::Common::LogTest(
|
|
|
|
$strModuleParam, $strModuleTestParam, $iRun, $bLogForce, $strLog, $strCommonCommandMain, $strPgSqlBin,
|
|
|
|
$strCommonTestPath, $strCommonRepoPath);
|
2015-10-08 17:43:56 +02:00
|
|
|
}
|
2015-05-05 19:08:48 +02:00
|
|
|
|
2014-07-16 05:32:41 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
push(@EXPORT, qw(testRun));
|
|
|
|
|
2014-07-16 05:32:41 +03:00
|
|
|
####################################################################################################################################
|
2016-06-24 14:12:58 +02:00
|
|
|
# testCleanup
|
2014-07-16 05:32:41 +03:00
|
|
|
####################################################################################################################################
|
2016-06-24 14:12:58 +02:00
|
|
|
sub testCleanup
|
2014-07-16 05:32:41 +03:00
|
|
|
{
|
2015-10-08 17:43:56 +02:00
|
|
|
my $oLogTestRef = shift;
|
2014-07-03 01:58:38 +03:00
|
|
|
|
2015-10-08 17:43:56 +02:00
|
|
|
# Save the previous test log
|
|
|
|
if (defined($$oLogTestRef))
|
2014-07-03 01:58:38 +03:00
|
|
|
{
|
2016-06-24 14:12:58 +02:00
|
|
|
$$oLogTestRef->logWrite($strCommonBasePath, $strCommonTestPath);
|
2015-10-08 17:43:56 +02:00
|
|
|
$$oLogTestRef = undef;
|
2014-08-10 22:02:14 +03:00
|
|
|
}
|
2015-06-14 00:25:49 +02:00
|
|
|
|
2015-10-08 17:43:56 +02:00
|
|
|
# Return false if there is no cleanup or if this was a test run (this prevents cleanup from being run)
|
|
|
|
return !$bNoCleanup && !$bDryRun;
|
2014-06-22 18:56:01 +03:00
|
|
|
}
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
push(@EXPORT, qw(testCleanup));
|
2015-01-22 01:37:49 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
2016-06-24 14:12:58 +02:00
|
|
|
# testSetup
|
2015-01-22 17:54:02 +02:00
|
|
|
####################################################################################################################################
|
2016-06-24 14:12:58 +02:00
|
|
|
sub testSetup
|
2015-01-22 17:54:02 +02:00
|
|
|
{
|
2014-08-11 04:22:17 +03:00
|
|
|
my $strTestPathParam = shift;
|
|
|
|
my $strPgSqlBinParam = shift;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $iModuleTestRunOnlyParam = shift;
|
2014-07-16 05:32:41 +03:00
|
|
|
my $bDryRunParam = shift;
|
|
|
|
my $bNoCleanupParam = shift;
|
2015-05-05 19:08:48 +02:00
|
|
|
my $bLogForceParam = shift;
|
2014-07-16 05:32:41 +03:00
|
|
|
|
2015-05-05 19:08:48 +02:00
|
|
|
$strCommonBasePath = dirname(dirname(abs_path($0)));
|
2014-07-27 21:03:21 +03:00
|
|
|
|
2014-08-11 04:22:17 +03:00
|
|
|
$strPgSqlBin = $strPgSqlBinParam;
|
|
|
|
|
|
|
|
if (defined($strTestPathParam))
|
|
|
|
{
|
|
|
|
$strCommonTestPath = $strTestPathParam;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-11 23:16:35 +02:00
|
|
|
$strCommonTestPath = cwd() . "/test";
|
2014-08-11 04:22:17 +03:00
|
|
|
}
|
|
|
|
|
2015-05-05 19:08:48 +02:00
|
|
|
$strCommonDataPath = "${strCommonBasePath}/test/data";
|
2015-03-12 18:15:19 +02:00
|
|
|
$strCommonRepoPath = "${strCommonTestPath}/backrest";
|
2016-06-24 14:12:58 +02:00
|
|
|
$strCommonDbPath = "${strCommonTestPath}/db-master/db";
|
|
|
|
$strCommonDbCommonPath = "${strCommonDbPath}/common";
|
|
|
|
|
|
|
|
$strCommonCommandMain = $strCommonBasePath . '/bin/pgbackrest';
|
|
|
|
|
2015-05-05 19:08:48 +02:00
|
|
|
$iModuleTestRunOnly = $iModuleTestRunOnlyParam;
|
2014-07-16 05:32:41 +03:00
|
|
|
$bDryRun = $bDryRunParam;
|
|
|
|
$bNoCleanup = $bNoCleanupParam;
|
2015-05-05 19:08:48 +02:00
|
|
|
$bLogForce = $bLogForceParam;
|
2015-04-01 21:58:33 +02:00
|
|
|
|
2015-06-14 16:12:36 +02:00
|
|
|
return true;
|
2015-04-01 21:58:33 +02:00
|
|
|
}
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
push(@EXPORT, qw(testSetup));
|
2015-04-01 21:58:33 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
2016-06-24 14:12:58 +02:00
|
|
|
# testIniSave
|
2015-04-01 21:58:33 +02:00
|
|
|
####################################################################################################################################
|
2016-06-24 14:12:58 +02:00
|
|
|
sub testIniSave
|
2015-04-01 21:58:33 +02:00
|
|
|
{
|
|
|
|
my $strFileName = shift;
|
|
|
|
my $oIniRef = shift;
|
2015-06-14 00:25:49 +02:00
|
|
|
my $bChecksum = shift;
|
2015-04-01 21:58:33 +02:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
# Calculate a new checksum if requested
|
|
|
|
if (defined($bChecksum) && $bChecksum)
|
|
|
|
{
|
|
|
|
delete($$oIniRef{&INI_SECTION_BACKREST}{&INI_KEY_CHECKSUM});
|
|
|
|
|
|
|
|
my $oSHA = Digest::SHA->new('sha1');
|
|
|
|
my $oJSON = JSON::PP->new()->canonical()->allow_nonref();
|
|
|
|
$oSHA->add($oJSON->encode($oIniRef));
|
|
|
|
|
|
|
|
$$oIniRef{&INI_SECTION_BACKREST}{&INI_KEY_CHECKSUM} = $oSHA->hexdigest();
|
|
|
|
}
|
|
|
|
|
|
|
|
iniSave($strFileName, $oIniRef);
|
2015-01-23 02:04:55 +02:00
|
|
|
}
|
2015-03-04 04:21:07 +02:00
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
push(@EXPORT, qw(testIniSave));
|
2014-06-22 21:51:28 +03:00
|
|
|
|
2014-06-22 17:30:17 +03:00
|
|
|
####################################################################################################################################
|
|
|
|
# Get Methods
|
|
|
|
####################################################################################################################################
|
2016-06-24 14:12:58 +02:00
|
|
|
sub testDataPath
|
2014-07-13 16:13:19 +03:00
|
|
|
{
|
|
|
|
return $strCommonDataPath;
|
|
|
|
}
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
push(@EXPORT, qw(testDataPath));
|
2015-04-01 21:58:33 +02:00
|
|
|
|
2014-06-22 17:30:17 +03:00
|
|
|
1;
|