1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-11-06 08:49:29 +02:00

More work on unit tests.

This commit is contained in:
David Steele
2014-06-22 10:54:31 -04:00
parent 0b597d8da9
commit 3c748c4b10
5 changed files with 59 additions and 57 deletions

View File

@@ -222,7 +222,7 @@ elsif (defined(config_load(CONFIG_SECTION_STANZA, CONFIG_KEY_HOST)))
{ {
confess &log(ERROR, 'db and backup cannot both be configured as remote'); confess &log(ERROR, 'db and backup cannot both be configured as remote');
} }
$strRemote = REMOTE_DB; $strRemote = REMOTE_DB;
} }
else else

View File

@@ -34,7 +34,7 @@ our @EXPORT = qw(PATH_ABSOLUTE PATH_DB PATH_DB_ABSOLUTE PATH_BACKUP PATH_BACKUP_
COMMAND_ERR_LINK_READ COMMAND_ERR_PATH_MISSING COMMAND_ERR_PATH_CREATE COMMAND_ERR_PARAM COMMAND_ERR_LINK_READ COMMAND_ERR_PATH_MISSING COMMAND_ERR_PATH_CREATE COMMAND_ERR_PARAM
PIPE_STDIN PIPE_STDOUT PIPE_STDERR PIPE_STDIN PIPE_STDOUT PIPE_STDERR
REMOTE_DB REMOTE_BACKUP REMOTE_NONE REMOTE_DB REMOTE_BACKUP REMOTE_NONE
OP_FILE_LIST OP_FILE_EXISTS OP_FILE_HASH OP_FILE_REMOVE OP_FILE_MANIFEST OP_FILE_COMPRESS OP_FILE_LIST OP_FILE_EXISTS OP_FILE_HASH OP_FILE_REMOVE OP_FILE_MANIFEST OP_FILE_COMPRESS

View File

@@ -16,8 +16,9 @@ use File::Basename;
use Cwd 'abs_path'; use Cwd 'abs_path';
use Exporter qw(import); use Exporter qw(import);
our @EXPORT = qw(BackRestCommonTestSetup BackRestCommonStanzaGet BackRestCommonCommandRemoteGet BackRestCommonHostGet our @EXPORT = qw(BackRestTestCommon_Setup BackRestTestCommon_StanzaGet BackRestTestCommon_CommandRemoteGet
BackRestCommonUserGet BackRestCommonGroupGet BackRestCommonUserBackRestGet BackRestCommonTestPathGet); BackRestTestCommon_HostGet BackRestTestCommon_UserGet BackRestTestCommon_GroupGet
BackRestTestCommon_UserBackRestGet BackRestTestCommon_TestPathGet);
my $strCommonStanza; my $strCommonStanza;
my $strCommonCommandRemote; my $strCommonCommandRemote;
@@ -28,9 +29,9 @@ my $strCommonUserBackRest;
my $strCommonTestPath; my $strCommonTestPath;
#################################################################################################################################### ####################################################################################################################################
# BackRestCommonTestSetup # BackRestTestCommon_Setup
#################################################################################################################################### ####################################################################################################################################
sub BackRestCommonTestSetup sub BackRestTestCommon_Setup
{ {
$strCommonStanza = "db"; $strCommonStanza = "db";
$strCommonCommandRemote = "/Users/dsteele/pg_backrest/bin/pg_backrest_remote.pl"; $strCommonCommandRemote = "/Users/dsteele/pg_backrest/bin/pg_backrest_remote.pl";
@@ -44,37 +45,37 @@ sub BackRestCommonTestSetup
#################################################################################################################################### ####################################################################################################################################
# Get Methods # Get Methods
#################################################################################################################################### ####################################################################################################################################
sub BackRestCommonStanzaGet sub BackRestTestCommon_StanzaGet
{ {
return $strCommonStanza; return $strCommonStanza;
} }
sub BackRestCommonCommandRemoteGet sub BackRestTestCommon_CommandRemoteGet
{ {
return $strCommonCommandRemote; return $strCommonCommandRemote;
} }
sub BackRestCommonHostGet sub BackRestTestCommon_HostGet
{ {
return $strCommonHost; return $strCommonHost;
} }
sub BackRestCommonUserGet sub BackRestTestCommon_UserGet
{ {
return $strCommonUser; return $strCommonUser;
} }
sub BackRestCommonGroupGet sub BackRestTestCommon_GroupGet
{ {
return $strCommonGroup; return $strCommonGroup;
} }
sub BackRestCommonUserBackRestGet sub BackRestTestCommon_UserBackRestGet
{ {
return $strCommonUserBackRest; return $strCommonUserBackRest;
} }
sub BackRestCommonTestPathGet sub BackRestTestCommon_TestPathGet
{ {
return $strCommonTestPath; return $strCommonTestPath;
} }

View File

@@ -18,33 +18,28 @@ use File::stat;
use Fcntl ':mode'; use Fcntl ':mode';
use Scalar::Util 'blessed'; use Scalar::Util 'blessed';
#use lib dirname($0) . "/../lib";
use BackRestTest::CommonTest;
use lib dirname($0) . "/../lib"; use lib dirname($0) . "/../lib";
use BackRest::Utility; use BackRest::Utility;
use BackRest::File; use BackRest::File;
use BackRest::Remote; use BackRest::Remote;
use BackRestTest::CommonTest;
use Exporter qw(import); use Exporter qw(import);
our @EXPORT = qw(BackRestFileTest); our @EXPORT = qw(BackRestTestFile_Test);
# my $strTestPath; my $strTestPath;
# my $strHost; my $strHost;
# my $strUserBackRest; my $strUserBackRest;
#################################################################################################################################### ####################################################################################################################################
# BackRestFileTestSetup # BackRestTestFile_Setup
#################################################################################################################################### ####################################################################################################################################
sub BackRestFileTestSetup sub BackRestTestFile_Setup
{ {
my $bPrivate = shift; my $bPrivate = shift;
my $bDropOnly = shift; my $bDropOnly = shift;
my $strTestPath = BackRestCommonTestPathGet();
my $strUserBackRest = BackRestCommonUserBackRestGet();
my $strHost = BackRestCommonHostGet();
# Remove the backrest private directory # Remove the backrest private directory
if (-e "${strTestPath}/private") if (-e "${strTestPath}/private")
{ {
@@ -68,11 +63,12 @@ sub BackRestFileTestSetup
} }
#################################################################################################################################### ####################################################################################################################################
# BackRestFileTest # BackRestTestFile_Test
#################################################################################################################################### ####################################################################################################################################
sub BackRestFileTest sub BackRestTestFile_Test
{ {
my $strTest = shift; my $strTest = shift;
my $iTestRun = shift;
# If no test was specified, then run them all # If no test was specified, then run them all
if (!defined($strTest)) if (!defined($strTest))
@@ -82,13 +78,12 @@ sub BackRestFileTest
# Setup test variables # Setup test variables
my $iRun; my $iRun;
my $strTestPath = BackRestCommonTestPathGet(); $strTestPath = BackRestTestCommon_TestPathGet();
my $strStanza = BackRestCommonStanzaGet(); my $strStanza = BackRestTestCommon_StanzaGet();
my $strUser = BackRestCommonUserGet(); my $strUser = BackRestTestCommon_UserGet();
my $strGroup = BackRestCommonGroupGet(); my $strGroup = BackRestTestCommon_GroupGet();
$strHost = BackRestTestCommon_HostGet();
# $strHost = "127.0.0.1"; $strUserBackRest = BackRestTestCommon_UserBackRestGet();
# $strUserBackRest = 'backrest';
# Print test parameters # Print test parameters
&log(INFO, "FILE MODULE ********************************************************************"); &log(INFO, "FILE MODULE ********************************************************************");
@@ -98,9 +93,9 @@ sub BackRestFileTest
#------------------------------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------------------------------
my $oRemote = BackRest::Remote->new my $oRemote = BackRest::Remote->new
( (
strHost => BackRestCommonHostGet(), strHost => $strHost,
strUser => $strUser, strUser => $strUser,
strCommand => BackRestCommonCommandRemoteGet(), strCommand => BackRestTestCommon_CommandRemoteGet(),
); );
#------------------------------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------------------------------
@@ -137,11 +132,16 @@ sub BackRestFileTest
$iRun++; $iRun++;
if (defined($iTestRun) && $iTestRun != $iRun)
{
next;
}
&log(INFO, "run ${iRun} - " . &log(INFO, "run ${iRun} - " .
"remote ${bRemote}, exists ${bExists}, error ${bError}, permission ${bPermission}"); "remote ${bRemote}, exists ${bExists}, error ${bError}, permission ${bPermission}");
# Setup test directory # Setup test directory
BackRestFileTestSetup($bError); BackRestTestFile_Setup($bError);
mkdir("$strTestPath/backup") or confess "Unable to create test/backup directory"; mkdir("$strTestPath/backup") or confess "Unable to create test/backup directory";
mkdir("$strTestPath/backup/db") or confess "Unable to create test/backup/db directory"; mkdir("$strTestPath/backup/db") or confess "Unable to create test/backup/db directory";
@@ -153,13 +153,6 @@ sub BackRestFileTest
if ($bPermission) if ($bPermission)
{ {
$strPermission = "0700"; $strPermission = "0700";
# # Make sure that we are not testing with the default permission
# if ($strPermission eq $oFile->{strDefaultPathPermission})
# {
# confess 'cannot set test permission ${strPermission} equal to default permission' .
# $oFile->{strDefaultPathPermission};
# }
} }
# If not exists then set the path to something bogus # If not exists then set the path to something bogus
@@ -271,7 +264,7 @@ sub BackRestFileTest
", dst_exists $bDestinationExists, dst_error $bDestinationError, dst_create $bCreate"); ", dst_exists $bDestinationExists, dst_error $bDestinationError, dst_create $bCreate");
# Setup test directory # Setup test directory
BackRestFileTestSetup($bSourceError || $bDestinationError); BackRestTestFile_Setup($bSourceError || $bDestinationError);
my $strSourceFile = "${strTestPath}/test.txt"; my $strSourceFile = "${strTestPath}/test.txt";
my $strDestinationFile = "${strTestPath}/test-dest.txt"; my $strDestinationFile = "${strTestPath}/test-dest.txt";
@@ -359,7 +352,7 @@ sub BackRestFileTest
"remote $bRemote, exists $bExists, error $bError"); "remote $bRemote, exists $bExists, error $bError");
# Setup test directory # Setup test directory
BackRestFileTestSetup($bError); BackRestTestFile_Setup($bError);
my $strFile = "${strTestPath}/test.txt"; my $strFile = "${strTestPath}/test.txt";
my $strSourceHash; my $strSourceHash;
@@ -463,7 +456,7 @@ sub BackRestFileTest
"remote $bRemote, error $bError, exists $bExists"); "remote $bRemote, error $bError, exists $bExists");
# Setup test directory # Setup test directory
BackRestFileTestSetup($bError); BackRestTestFile_Setup($bError);
# Setup test data # Setup test data
system("mkdir -m 750 ${strTestPath}/sub1") == 0 or confess "Unable to create test directory"; system("mkdir -m 750 ${strTestPath}/sub1") == 0 or confess "Unable to create test directory";
@@ -633,7 +626,7 @@ sub BackRestFileTest
"sort " . (defined($strSort) ? $strSort : "[undef]")); "sort " . (defined($strSort) ? $strSort : "[undef]"));
# Setup test directory # Setup test directory
BackRestFileTestSetup($bError); BackRestTestFile_Setup($bError);
my $strPath = "${strTestPath}"; my $strPath = "${strTestPath}";
@@ -742,7 +735,7 @@ sub BackRestFileTest
", ignore missing ${bIgnoreMissing}"); ", ignore missing ${bIgnoreMissing}");
# Setup test directory # Setup test directory
BackRestFileTestSetup($bError); BackRestTestFile_Setup($bError);
my $strFile = "${strTestPath}/test.txt"; my $strFile = "${strTestPath}/test.txt";
@@ -840,7 +833,7 @@ sub BackRestFileTest
"remote $bRemote, error $bError, exists $bExists"); "remote $bRemote, error $bError, exists $bExists");
# Setup test directory # Setup test directory
BackRestFileTestSetup($bError); BackRestTestFile_Setup($bError);
my $strFile = "${strTestPath}/test.txt"; my $strFile = "${strTestPath}/test.txt";
@@ -922,7 +915,7 @@ sub BackRestFileTest
"remote $bRemote, exists $bExists, error ${bError}"); "remote $bRemote, exists $bExists, error ${bError}");
# Setup test directory # Setup test directory
BackRestFileTestSetup($bError); BackRestTestFile_Setup($bError);
my $strFile = "${strTestPath}/test.txt"; my $strFile = "${strTestPath}/test.txt";
@@ -1044,7 +1037,7 @@ sub BackRestFileTest
":${strDestinationPath}, dstcmp $bDestinationCompress"); ":${strDestinationPath}, dstcmp $bDestinationCompress");
# Setup test directory # Setup test directory
BackRestFileTestSetup(false); BackRestTestFile_Setup(false);
system("mkdir ${strTestPath}/backup") == 0 or confess "Unable to create test/backup directory"; system("mkdir ${strTestPath}/backup") == 0 or confess "Unable to create test/backup directory";
system("mkdir ${strTestPath}/db") == 0 or confess "Unable to create test/db directory"; system("mkdir ${strTestPath}/db") == 0 or confess "Unable to create test/db directory";
@@ -1151,7 +1144,7 @@ sub BackRestFileTest
} }
} }
BackRestFileTestSetup(false, true); BackRestTestFile_Setup(false, true);
} }
1; 1;

View File

@@ -27,10 +27,12 @@ use BackRestTest::FileTest;
my $strLogLevel = 'off'; # Log level for tests my $strLogLevel = 'off'; # Log level for tests
my $strModule = 'all'; my $strModule = 'all';
my $strModuleTest = 'all'; my $strModuleTest = 'all';
my $iModuleTestRun = undef;
GetOptions ("log-level=s" => \$strLogLevel, GetOptions ("log-level=s" => \$strLogLevel,
"module=s" => \$strModule, "module=s" => \$strModule,
"module-test=s" => \$strModuleTest) "module-test=s" => \$strModuleTest,
"module-test-run=s" => \$iModuleTestRun)
or die("Error in command line arguments\n"); or die("Error in command line arguments\n");
#################################################################################################################################### ####################################################################################################################################
@@ -47,7 +49,13 @@ if ($strModuleTest ne 'all' && $strModule eq 'all')
confess "--module must be provided for test \"${strModuleTest}\""; confess "--module must be provided for test \"${strModuleTest}\"";
} }
BackRestCommonTestSetup(); if (defined($iModuleTestRun) && $strModuleTest eq 'all')
{
confess "--module-test must be provided for run \"${iModuleTestRun}\"";
}
BackRestTestCommon_Setup();
#################################################################################################################################### ####################################################################################################################################
# Clean whitespace # Clean whitespace
@@ -88,7 +96,7 @@ if (!$bMatch)
if ($strModule eq 'all' || $strModule eq "file") if ($strModule eq 'all' || $strModule eq "file")
{ {
BackRestFileTest($strModuleTest); BackRestTestFile_Test($strModuleTest, $iModuleTestRun);
} }
&log(ASSERT, "TESTS COMPLETED SUCCESSFULLY (DESPITE ANY ERROR MESSAGES YOU SAW)"); &log(ASSERT, "TESTS COMPLETED SUCCESSFULLY (DESPITE ANY ERROR MESSAGES YOU SAW)");