You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-11-27 22:18:40 +02:00
Moved test and env modules to new directories to avoid namespace conflicts with common tests.
This commit is contained in:
125
test/lib/pgBackRestTest/Module/File/FileCommonTest.pm
Normal file
125
test/lib/pgBackRestTest/Module/File/FileCommonTest.pm
Normal file
@@ -0,0 +1,125 @@
|
||||
####################################################################################################################################
|
||||
# FileCommonTest.pm - Common code for File tests
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::File::FileCommonTest;
|
||||
use parent 'pgBackRestTest::Common::RunTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::Config::Config;
|
||||
use pgBackRest::FileCommon;
|
||||
use pgBackRest::Protocol::Common;
|
||||
use pgBackRest::Protocol::RemoteMaster;
|
||||
|
||||
use pgBackRestTest::Env::Host::HostBackupTest;
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# initModule
|
||||
#
|
||||
# Common objects and variables used by all tests.
|
||||
####################################################################################################################################
|
||||
sub initModule
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Create the repo path so the remote won't complain that it's missing
|
||||
my $strRepoPath = $self->testPath() . '/repo';
|
||||
|
||||
mkdir($strRepoPath, oct('0770'))
|
||||
or confess "Unable to create repo directory: ${strRepoPath}";
|
||||
|
||||
# Create local
|
||||
$self->{oLocal} = new pgBackRest::Protocol::Common(
|
||||
262144,
|
||||
1,
|
||||
OPTION_DEFAULT_COMPRESS_LEVEL_NETWORK,
|
||||
HOST_PROTOCOL_TIMEOUT);
|
||||
|
||||
# Create remote
|
||||
$self->{oRemote} = new pgBackRest::Protocol::RemoteMaster(
|
||||
BACKUP,
|
||||
OPTION_DEFAULT_CMD_SSH,
|
||||
$self->backrestExeOriginal() . ' --stanza=' . $self->stanza() .
|
||||
" --type=backup --repo-path=${strRepoPath} --no-config --command=test remote",
|
||||
262144,
|
||||
OPTION_DEFAULT_COMPRESS_LEVEL,
|
||||
OPTION_DEFAULT_COMPRESS_LEVEL_NETWORK,
|
||||
$self->host(),
|
||||
$self->backrestUser(),
|
||||
HOST_PROTOCOL_TIMEOUT);
|
||||
|
||||
rmdir($strRepoPath)
|
||||
or confess "Unable to remove repo directory: ${strRepoPath}";
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# cleanModule
|
||||
#
|
||||
# Close objects created for tests.
|
||||
####################################################################################################################################
|
||||
sub cleanModule
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
$self->remote()->close();
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# setup
|
||||
#
|
||||
# Setup directories for file tests.
|
||||
####################################################################################################################################
|
||||
sub setup
|
||||
{
|
||||
my $self = shift;
|
||||
my $bRemote = shift;
|
||||
my $bPrivate = shift;
|
||||
|
||||
# Remove the backrest private directory
|
||||
if (fileExists($self->testPath() . '/private'))
|
||||
{
|
||||
executeTest(
|
||||
'ssh ' . $self->backrestUser() . '\@' . $self->host() . ' rm -rf ' . $self->testPath() . '/private',
|
||||
{bSuppressStdErr => true});
|
||||
}
|
||||
|
||||
# Remove contents of the test directory
|
||||
executeTest('rm -rf ' . $self->testPath() . '/*');
|
||||
|
||||
# Create the private directories
|
||||
if (defined($bPrivate) && $bPrivate)
|
||||
{
|
||||
executeTest(
|
||||
'ssh ' . $self->backrestUser() . '\@' . $self->host() . ' mkdir -m 700 ' . $self->testPath() . '/backrest_private',
|
||||
{bSuppressStdErr => true});
|
||||
|
||||
executeTest('mkdir -m 700 ' . $self->testPath() . '/user_private');
|
||||
}
|
||||
|
||||
# Create the file object
|
||||
my $oFile = new pgBackRest::File
|
||||
(
|
||||
$self->stanza(),
|
||||
$self->testPath(),
|
||||
$bRemote ? $self->remote() : $self->local()
|
||||
);
|
||||
|
||||
return $oFile;
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# Getters
|
||||
####################################################################################################################################
|
||||
sub host {return '127.0.0.1'}
|
||||
sub local {return shift->{oLocal}}
|
||||
sub remote {return shift->{oRemote}}
|
||||
|
||||
1;
|
||||
101
test/lib/pgBackRestTest/Module/File/FileCompressTest.pm
Normal file
101
test/lib/pgBackRestTest/Module/File/FileCompressTest.pm
Normal file
@@ -0,0 +1,101 @@
|
||||
####################################################################################################################################
|
||||
# FileCompressTest.pm - Tests for File->compress()
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::File::FileCompressTest;
|
||||
use parent 'pgBackRestTest::Module::File::FileCommonTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::File;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
####################################################################################################################################
|
||||
sub run
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Loop through local/remote ??? enable remote tests and have them throw an error
|
||||
foreach my $bRemote (false)
|
||||
{
|
||||
# Loop through exists
|
||||
foreach my $bExists (false, true)
|
||||
{
|
||||
# Loop through error
|
||||
foreach my $bError (false, true)
|
||||
{
|
||||
if (!$self->begin("rmt ${bRemote}, exists ${bExists}, err ${bError}")) {next}
|
||||
|
||||
# Setup test directory and get file object
|
||||
my $oFile = $self->setup($bRemote, $bError);
|
||||
|
||||
my $strFile = $self->testPath() . '/test.txt';
|
||||
my $strSourceHash;
|
||||
my $iSourceSize;
|
||||
|
||||
if ($bError)
|
||||
{
|
||||
$strFile = $self->testPath() . '/' . ($bRemote ? 'user' : 'backrest') . '_private/test.txt';
|
||||
}
|
||||
elsif ($bExists)
|
||||
{
|
||||
executeTest("echo 'TESTDATA' > ${strFile}");
|
||||
($strSourceHash, $iSourceSize) = $oFile->hashSize(PATH_BACKUP_ABSOLUTE, $strFile);
|
||||
}
|
||||
|
||||
# Execute in eval in case of error
|
||||
eval
|
||||
{
|
||||
$oFile->compress(PATH_BACKUP_ABSOLUTE, $strFile);
|
||||
return true;
|
||||
}
|
||||
or do
|
||||
{
|
||||
if (!$bExists || $bError)
|
||||
{
|
||||
next;
|
||||
}
|
||||
|
||||
confess $EVAL_ERROR;
|
||||
};
|
||||
|
||||
if (!$bExists || $bError)
|
||||
{
|
||||
confess 'expected error';
|
||||
}
|
||||
|
||||
my $strDestinationFile = $strFile . '.gz';
|
||||
|
||||
if (-e $strFile)
|
||||
{
|
||||
confess 'source file still exists';
|
||||
}
|
||||
|
||||
unless (-e $strDestinationFile)
|
||||
{
|
||||
confess 'file was not compressed';
|
||||
}
|
||||
|
||||
executeTest("gzip -d ${strDestinationFile}");
|
||||
|
||||
my ($strDestinationHash, $iDestinationSize) = $oFile->hashSize(PATH_BACKUP_ABSOLUTE, $strFile);
|
||||
|
||||
if ($strSourceHash ne $strDestinationHash)
|
||||
{
|
||||
confess "source ${strSourceHash} and destination ${strDestinationHash} file hashes do not match";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
244
test/lib/pgBackRestTest/Module/File/FileCopyTest.pm
Normal file
244
test/lib/pgBackRestTest/Module/File/FileCopyTest.pm
Normal file
@@ -0,0 +1,244 @@
|
||||
####################################################################################################################################
|
||||
# FileCopyTest.pm - Tests for File->copy()
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::File::FileCopyTest;
|
||||
use parent 'pgBackRestTest::Module::File::FileCommonTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use pgBackRest::Common::Exception;
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::File;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
####################################################################################################################################
|
||||
sub run
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Loop through small/large
|
||||
for (my $iLarge = 0; $iLarge <= 3; $iLarge++)
|
||||
{
|
||||
# Loop through possible remotes
|
||||
foreach my $strRemote ($iLarge ? (undef, 'db') : (undef, 'backup', 'db'))
|
||||
{
|
||||
# Loop through source path types
|
||||
foreach my $strSourcePathType ($iLarge ? (PATH_BACKUP_ABSOLUTE) : (PATH_BACKUP_ABSOLUTE, PATH_DB_ABSOLUTE))
|
||||
{
|
||||
# Loop through destination path types
|
||||
foreach my $strDestinationPathType ($iLarge ? (PATH_DB_ABSOLUTE) : (PATH_BACKUP_ABSOLUTE, PATH_DB_ABSOLUTE))
|
||||
{
|
||||
# Loop through source missing/present
|
||||
foreach my $bSourceMissing ($iLarge ? (false) : (false, true))
|
||||
{
|
||||
# Loop through source ignore/require
|
||||
foreach my $bSourceIgnoreMissing ($bSourceMissing ? (false, true) : (false))
|
||||
{
|
||||
# Loop through checksum append
|
||||
foreach my $bChecksumAppend ($bSourceMissing || $iLarge ? (false) : (false, true))
|
||||
{
|
||||
# Loop through source compression
|
||||
foreach my $bSourceCompressed ($bSourceMissing ? (false) : (false, true))
|
||||
{
|
||||
# Loop through destination compression
|
||||
foreach my $bDestinationCompress ($bSourceMissing ? (false) : (false, true))
|
||||
{
|
||||
my $strSourcePath = $strSourcePathType eq PATH_DB_ABSOLUTE ? 'db' : 'backup';
|
||||
my $strDestinationPath = $strDestinationPathType eq PATH_DB_ABSOLUTE ? 'db' : 'backup';
|
||||
|
||||
if (!$self->begin(
|
||||
"lrg ${iLarge}, rmt " .
|
||||
(defined($strRemote) && ($strRemote eq $strSourcePath || $strRemote eq $strDestinationPath) ? 1 : 0) .
|
||||
', srcpth ' . (defined($strRemote) && $strRemote eq $strSourcePath ? 'rmt' : 'lcl') .
|
||||
":${strSourcePath}, srcmiss ${bSourceMissing}, srcignmiss ${bSourceIgnoreMissing}, srccmp $bSourceCompressed, " .
|
||||
'dstpth ' . (defined($strRemote) && $strRemote eq $strDestinationPath ? 'rmt' : 'lcl') .
|
||||
":${strDestinationPath}, chkapp ${bChecksumAppend}, dstcmp $bDestinationCompress")) {next}
|
||||
|
||||
# Setup test directory and get file object
|
||||
my $oFile = $self->setup(defined($strRemote), false);
|
||||
executeTest('mkdir ' . $self->testPath() . '/backup');
|
||||
executeTest('mkdir ' . $self->testPath() . '/db');
|
||||
|
||||
my $strSourceFile = $self->testPath() . "/${strSourcePath}/test-source";
|
||||
my $strDestinationFile = $self->testPath() . "/${strDestinationPath}/test-destination";
|
||||
|
||||
my $strCopyHash;
|
||||
my $iCopySize;
|
||||
|
||||
# Create the compressed or uncompressed test file
|
||||
my $strSourceHash;
|
||||
my $iSourceSize;
|
||||
|
||||
if (!$bSourceMissing)
|
||||
{
|
||||
if ($iLarge)
|
||||
{
|
||||
$strSourceFile .= '.bin';
|
||||
$strDestinationFile .= '.bin';
|
||||
|
||||
if ($iLarge < 3)
|
||||
{
|
||||
executeTest('cp ' . $self->dataPath() . "/filecopy.archive${iLarge}.bin ${strSourceFile}");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (my $iTableSizeIdx = 0; $iTableSizeIdx < 25; $iTableSizeIdx++)
|
||||
{
|
||||
executeTest('cat ' . $self->dataPath() . "/filecopy.table.bin >> ${strSourceFile}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$strSourceFile .= '.txt';
|
||||
$strDestinationFile .= '.txt';
|
||||
|
||||
system("echo 'TESTDATA' > ${strSourceFile}");
|
||||
}
|
||||
|
||||
if ($iLarge == 1)
|
||||
{
|
||||
$strSourceHash = '4518a0fdf41d796760b384a358270d4682589820';
|
||||
$iSourceSize = 16777216;
|
||||
}
|
||||
elsif ($iLarge == 2)
|
||||
{
|
||||
$strSourceHash = '1c7e00fd09b9dd11fc2966590b3e3274645dd031';
|
||||
$iSourceSize = 16777216;
|
||||
}
|
||||
elsif ($iLarge == 3)
|
||||
{
|
||||
$strSourceHash = 'b2055a6ba15bf44359c18fbbf23c68b50a670eb0';
|
||||
$iSourceSize = 26214400;
|
||||
}
|
||||
else
|
||||
{
|
||||
$strSourceHash = '06364afe79d801433188262478a76d19777ef351';
|
||||
$iSourceSize = 9;
|
||||
}
|
||||
|
||||
if ($bSourceCompressed)
|
||||
{
|
||||
system("gzip ${strSourceFile}");
|
||||
$strSourceFile .= '.gz';
|
||||
}
|
||||
}
|
||||
|
||||
if ($bDestinationCompress)
|
||||
{
|
||||
$strDestinationFile .= '.gz';
|
||||
}
|
||||
|
||||
# Run file copy in an eval block because some errors are expected
|
||||
my $bReturn;
|
||||
|
||||
eval
|
||||
{
|
||||
($bReturn, $strCopyHash, $iCopySize) =
|
||||
$oFile->copy($strSourcePathType, $strSourceFile,
|
||||
$strDestinationPathType, $strDestinationFile,
|
||||
$bSourceCompressed, $bDestinationCompress,
|
||||
$bSourceIgnoreMissing, undef, '0770', false, undef, undef,
|
||||
$bChecksumAppend);
|
||||
|
||||
return true;
|
||||
}
|
||||
# Check for errors after copy
|
||||
or do
|
||||
{
|
||||
my $oException = $EVAL_ERROR;
|
||||
|
||||
if (isException($oException))
|
||||
{
|
||||
if ($bSourceMissing && !$bSourceIgnoreMissing)
|
||||
{
|
||||
next;
|
||||
}
|
||||
|
||||
confess $oException;
|
||||
}
|
||||
|
||||
confess $oException;
|
||||
};
|
||||
|
||||
if ($bSourceMissing)
|
||||
{
|
||||
if ($bSourceIgnoreMissing)
|
||||
{
|
||||
if ($bReturn)
|
||||
{
|
||||
confess 'copy() returned ' . $bReturn . ' when ignore missing set';
|
||||
}
|
||||
|
||||
next;
|
||||
}
|
||||
|
||||
confess 'expected source file missing error';
|
||||
}
|
||||
|
||||
if (!defined($strCopyHash))
|
||||
{
|
||||
confess 'copy hash must be defined';
|
||||
}
|
||||
|
||||
if ($bChecksumAppend)
|
||||
{
|
||||
if ($bDestinationCompress)
|
||||
{
|
||||
$strDestinationFile =
|
||||
substr($strDestinationFile, 0, length($strDestinationFile) -3) . "-${strSourceHash}.gz";
|
||||
}
|
||||
else
|
||||
{
|
||||
$strDestinationFile .= '-' . $strSourceHash;
|
||||
}
|
||||
}
|
||||
|
||||
unless (-e $strDestinationFile)
|
||||
{
|
||||
confess "could not find destination file ${strDestinationFile}";
|
||||
}
|
||||
|
||||
my $strDestinationTest = $strDestinationFile;
|
||||
|
||||
if ($bDestinationCompress)
|
||||
{
|
||||
$strDestinationTest = substr($strDestinationFile, 0, length($strDestinationFile) - 3) . '.test';
|
||||
|
||||
system("gzip -dc ${strDestinationFile} > ${strDestinationTest}") == 0
|
||||
or die "could not decompress ${strDestinationFile}";
|
||||
}
|
||||
|
||||
my ($strDestinationHash, $iDestinationSize) = $oFile->hashSize(PATH_ABSOLUTE, $strDestinationTest);
|
||||
|
||||
if ($strSourceHash ne $strDestinationHash || $strSourceHash ne $strCopyHash)
|
||||
{
|
||||
confess
|
||||
"source ${strSourceHash}, copy ${strCopyHash} and destination ${strDestinationHash} file hashes do not match";
|
||||
}
|
||||
|
||||
if ($iSourceSize != $iDestinationSize || $iSourceSize != $iCopySize)
|
||||
{
|
||||
confess "source ${iSourceSize}, copy ${iCopySize} and destination ${iDestinationSize} sizes do not match";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
91
test/lib/pgBackRestTest/Module/File/FileExistsTest.pm
Normal file
91
test/lib/pgBackRestTest/Module/File/FileExistsTest.pm
Normal file
@@ -0,0 +1,91 @@
|
||||
####################################################################################################################################
|
||||
# FileExistsTest.pm - Tests for File->exists()
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::File::FileExistsTest;
|
||||
use parent 'pgBackRestTest::Module::File::FileCommonTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use pgBackRest::Common::Exception;
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::File;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
####################################################################################################################################
|
||||
sub run
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Loop through local/remote
|
||||
foreach my $bRemote (false, true)
|
||||
{
|
||||
# Loop through exists
|
||||
foreach my $bExists (false, true)
|
||||
{
|
||||
# Loop through exists
|
||||
foreach my $bError ($bExists ? (false, true) : (false))
|
||||
{
|
||||
if (!$self->begin("rmt ${bRemote}, err ${bError}, exists ${bExists}")) {next}
|
||||
|
||||
# Setup test directory and get file object
|
||||
my $oFile = $self->setup($bRemote, $bError);
|
||||
|
||||
my $strFile = $self->testPath() . '/test.txt';
|
||||
|
||||
if ($bError)
|
||||
{
|
||||
$strFile = $self->testPath() . '/private/test.txt';
|
||||
}
|
||||
elsif ($bExists)
|
||||
{
|
||||
executeTest("echo 'TESTDATA' > ${strFile}");
|
||||
}
|
||||
|
||||
# Execute in eval in case of error
|
||||
eval
|
||||
{
|
||||
if ($oFile->exists(PATH_BACKUP_ABSOLUTE, $strFile) != $bExists)
|
||||
{
|
||||
confess "bExists is set to ${bExists}, but exists() returned " . !$bExists;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
or do
|
||||
{
|
||||
my $oException = $@;
|
||||
my $iCode;
|
||||
my $strMessage;
|
||||
|
||||
if (isException($oException))
|
||||
{
|
||||
$iCode = $oException->code();
|
||||
$strMessage = $oException->message();
|
||||
}
|
||||
else
|
||||
{
|
||||
$strMessage = $oException;
|
||||
}
|
||||
|
||||
if ($bError)
|
||||
{
|
||||
next;
|
||||
}
|
||||
|
||||
confess 'error raised: ' . $strMessage . "\n";
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
100
test/lib/pgBackRestTest/Module/File/FileHashTest.pm
Normal file
100
test/lib/pgBackRestTest/Module/File/FileHashTest.pm
Normal file
@@ -0,0 +1,100 @@
|
||||
####################################################################################################################################
|
||||
# FileHashTest.pm - Tests for File->hash()
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::File::FileHashTest;
|
||||
use parent 'pgBackRestTest::Module::File::FileCommonTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::File;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
####################################################################################################################################
|
||||
sub run
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Loop through local/remote
|
||||
foreach my $bRemote (false, true)
|
||||
{
|
||||
# Loop through error
|
||||
foreach my $bError (false, true)
|
||||
{
|
||||
# Loop through exists
|
||||
foreach my $bExists (false, true)
|
||||
{
|
||||
# Loop through exists
|
||||
foreach my $bCompressed (false, true)
|
||||
{
|
||||
if (!$self->begin("rmt ${bRemote}, err ${bError}, exists ${bExists}, cmp ${bCompressed}")) {next}
|
||||
|
||||
# Setup test directory and get file object
|
||||
my $oFile = $self->setup($bRemote, $bError);
|
||||
|
||||
my $strFile = $self->testPath() . '/test.txt';
|
||||
|
||||
if ($bError)
|
||||
{
|
||||
$strFile = $self->testPath() . '/' . ($bRemote ? 'user' : 'backrest') . '_private/test.txt';
|
||||
}
|
||||
elsif (!$bExists)
|
||||
{
|
||||
$strFile = $self->testPath() . '/error.txt';
|
||||
}
|
||||
else
|
||||
{
|
||||
executeTest("echo 'TESTDATA' > ${strFile}");
|
||||
|
||||
if ($bCompressed && !$bRemote)
|
||||
{
|
||||
$oFile->compress(PATH_BACKUP_ABSOLUTE, $strFile);
|
||||
$strFile = $strFile . '.gz';
|
||||
}
|
||||
}
|
||||
|
||||
# Execute in eval in case of error
|
||||
my $strHash;
|
||||
my $iSize;
|
||||
my $bErrorExpected = !$bExists || $bError || $bRemote;
|
||||
|
||||
eval
|
||||
{
|
||||
($strHash, $iSize) = $oFile->hashSize(PATH_BACKUP_ABSOLUTE, $strFile, $bCompressed);
|
||||
return true;
|
||||
}
|
||||
or do
|
||||
{
|
||||
if ($bErrorExpected)
|
||||
{
|
||||
next;
|
||||
}
|
||||
|
||||
confess $EVAL_ERROR;
|
||||
};
|
||||
|
||||
if ($bErrorExpected)
|
||||
{
|
||||
confess 'error was expected';
|
||||
}
|
||||
|
||||
if ($strHash ne '06364afe79d801433188262478a76d19777ef351')
|
||||
{
|
||||
confess 'hashes do not match';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
58
test/lib/pgBackRestTest/Module/File/FileLinkTest.pm
Normal file
58
test/lib/pgBackRestTest/Module/File/FileLinkTest.pm
Normal file
@@ -0,0 +1,58 @@
|
||||
####################################################################################################################################
|
||||
# FileLinkTest.pm - Tests for FileCommon::fileLinkDestination
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::File::FileLinkTest;
|
||||
use parent 'pgBackRestTest::Module::File::FileCommonTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use Fcntl qw(:mode);
|
||||
use File::stat;
|
||||
|
||||
use pgBackRest::Common::Exception;
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::FileCommon;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
use pgBackRestTest::Common::RunTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
####################################################################################################################################
|
||||
sub run
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
################################################################################################################################
|
||||
if ($self->begin("FileCommon::fileLinkDestination()"))
|
||||
{
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
my $strTestLink = $self->testPath() . '/public_dir_link';
|
||||
|
||||
$self->testException(
|
||||
sub {fileLinkDestination($strTestLink)}, ERROR_FILE_MISSING,
|
||||
"unable to get destination for link ${strTestLink}: No such file or directory");
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
my $strTestPath = $self->testPath() . '/public_dir';
|
||||
filePathCreate($strTestPath);
|
||||
|
||||
$self->testException(
|
||||
sub {fileLinkDestination($strTestPath)}, ERROR_FILE_OPEN,
|
||||
"unable to get destination for link ${strTestPath}: Invalid argument");
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
symlink($strTestPath, $strTestLink)
|
||||
or confess &log(ERROR, "unable to create symlink from ${strTestPath} to ${strTestLink}");
|
||||
|
||||
$self->testResult(sub {fileLinkDestination($strTestLink)}, $strTestPath, 'get link destination');
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
124
test/lib/pgBackRestTest/Module/File/FileListTest.pm
Normal file
124
test/lib/pgBackRestTest/Module/File/FileListTest.pm
Normal file
@@ -0,0 +1,124 @@
|
||||
####################################################################################################################################
|
||||
# FileListTest.pm - Tests for File->list()
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::File::FileListTest;
|
||||
use parent 'pgBackRestTest::Module::File::FileCommonTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::File;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
####################################################################################################################################
|
||||
sub run
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Loop through local/remote
|
||||
foreach my $bRemote (false, true)
|
||||
{
|
||||
# Loop through sort
|
||||
foreach my $strSort ('reverse', undef)
|
||||
{
|
||||
# Loop through expression
|
||||
foreach my $strExpression (undef, "^test2\\..*\$", "^du\$")
|
||||
{
|
||||
# Loop through exists
|
||||
foreach my $bExists (false, true)
|
||||
{
|
||||
# Loop through ignore missing
|
||||
for (my $bIgnoreMissing = false; $bIgnoreMissing <= $bExists; $bIgnoreMissing++)
|
||||
{
|
||||
# Loop through error
|
||||
foreach my $bError (false, true)
|
||||
{
|
||||
if (!$self->begin(
|
||||
"rmt ${bRemote}, err ${bError}, exist ${bExists}, ignmis ${bIgnoreMissing}, " .
|
||||
'exp ' . (defined($strExpression) ? $strExpression : '[undef]') . ', ' .
|
||||
'srt ' . (defined($strSort) ? $strSort : '[undef]'))) {next}
|
||||
|
||||
# Setup test directory and get file object
|
||||
my $oFile = $self->setup($bRemote, $bError);
|
||||
|
||||
my $strPath = $self->testPath();
|
||||
|
||||
if ($bError)
|
||||
{
|
||||
$strPath = $self->testPath() . '/' . ($bRemote ? 'user' : 'backrest') . '_private';
|
||||
}
|
||||
elsif (!$bExists)
|
||||
{
|
||||
$strPath = $self->testPath() . '/error';
|
||||
}
|
||||
else
|
||||
{
|
||||
executeTest("echo 'TESTDATA' > ${strPath}/test.txt");
|
||||
executeTest("echo 'TESTDATA2' > ${strPath}/test2.txt");
|
||||
}
|
||||
|
||||
my @stryFileCompare = split(/\n/, "test.txt\ntest2.txt");
|
||||
|
||||
# Execute in eval in case of error
|
||||
my @stryFileList;
|
||||
my $bErrorExpected = (!$bExists && !$bIgnoreMissing) || $bError;
|
||||
|
||||
eval
|
||||
{
|
||||
@stryFileList = $oFile->list(
|
||||
PATH_BACKUP_ABSOLUTE, $strPath,
|
||||
{strExpression => $strExpression, strSortOrder => $strSort, bIgnoreMissing => $bIgnoreMissing});
|
||||
return true;
|
||||
}
|
||||
or do
|
||||
{
|
||||
if ($bErrorExpected)
|
||||
{
|
||||
next;
|
||||
}
|
||||
|
||||
confess $EVAL_ERROR;
|
||||
};
|
||||
|
||||
if ($bErrorExpected)
|
||||
{
|
||||
confess 'error was expected';
|
||||
}
|
||||
|
||||
# Validate the list
|
||||
if (defined($strExpression))
|
||||
{
|
||||
@stryFileCompare = grep(/$strExpression/i, @stryFileCompare);
|
||||
}
|
||||
|
||||
if (defined($strSort))
|
||||
{
|
||||
@stryFileCompare = sort {$b cmp $a} @stryFileCompare;
|
||||
}
|
||||
|
||||
my $strFileList = sprintf("@stryFileList");
|
||||
my $strFileCompare = sprintf("@stryFileCompare");
|
||||
|
||||
if ($strFileList ne $strFileCompare)
|
||||
{
|
||||
confess "list (${strFileList})[" . @stryFileList .
|
||||
"] does not match compare (${strFileCompare})[" . @stryFileCompare . ']';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
215
test/lib/pgBackRestTest/Module/File/FileManifestTest.pm
Normal file
215
test/lib/pgBackRestTest/Module/File/FileManifestTest.pm
Normal file
@@ -0,0 +1,215 @@
|
||||
####################################################################################################################################
|
||||
# FileManifestTest.pm - Tests for File->manifest()
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::File::FileManifestTest;
|
||||
use parent 'pgBackRestTest::Module::File::FileCommonTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use File::Basename qw(basename dirname);
|
||||
use IO::Socket::UNIX;
|
||||
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::Common::Exception;
|
||||
use pgBackRest::File;
|
||||
use pgBackRest::FileCommon;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
####################################################################################################################################
|
||||
sub run
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
################################################################################################################################
|
||||
if ($self->begin("FileCommon::fileManifestStat()"))
|
||||
{
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
my $strFile = $self->testPath() . '/test.txt';
|
||||
|
||||
$self->testResult(sub {pgBackRest::FileCommon::fileManifestStat($strFile)}, '[undef]', 'ignore missing file');
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
fileStringWrite($strFile, "TEST");
|
||||
utime(1111111111, 1111111111, $strFile);
|
||||
executeTest('chmod 1640 ' . $strFile);
|
||||
|
||||
$self->testResult(
|
||||
sub {pgBackRest::FileCommon::fileManifestStat($strFile)},
|
||||
'{group => ' . $self->group() .
|
||||
', mode => 1640, modification_time => 1111111111, size => 4, type => f, user => ' . $self->pgUser() . '}',
|
||||
'stat file');
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
my $strSocketFile = $self->testPath() . '/test.socket';
|
||||
|
||||
# Create a socket to test invalid files
|
||||
my $oSocket = IO::Socket::UNIX->new(Type => SOCK_STREAM(), Local => $strSocketFile, Listen => 1);
|
||||
|
||||
$self->testException(
|
||||
sub {pgBackRest::FileCommon::fileManifestStat($strSocketFile)}, ERROR_FILE_INVALID,
|
||||
"${strSocketFile} is not of type directory, file, or link");
|
||||
|
||||
# Cleanup socket
|
||||
$oSocket->close();
|
||||
fileRemove($strSocketFile);
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
my $strTestPath = $self->testPath() . '/public_dir';
|
||||
filePathCreate($strTestPath, '0750');
|
||||
|
||||
$self->testResult(
|
||||
sub {pgBackRest::FileCommon::fileManifestStat($strTestPath)},
|
||||
'{group => ' . $self->group() . ', mode => 0750, type => d, user => ' . $self->pgUser() . '}',
|
||||
'stat directory');
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
my $strTestLink = $self->testPath() . '/public_dir_link';
|
||||
|
||||
symlink($strTestPath, $strTestLink)
|
||||
or confess &log(ERROR, "unable to create symlink from ${strTestPath} to ${strTestLink}");
|
||||
|
||||
$self->testResult(
|
||||
sub {pgBackRest::FileCommon::fileManifestStat($strTestLink)},
|
||||
'{group => ' . $self->group() . ", link_destination => ${strTestPath}, type => l, user => " . $self->pgUser() . '}',
|
||||
'stat link');
|
||||
}
|
||||
|
||||
################################################################################################################################
|
||||
if ($self->begin("FileCommon::fileManifestList()"))
|
||||
{
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
my @stryFile = ('.', 'test.txt');
|
||||
|
||||
$self->testResult(
|
||||
sub {pgBackRest::FileCommon::fileManifestList($self->testPath(), \@stryFile)},
|
||||
'{. => {group => ' . $self->group() . ', mode => 0770, type => d, user => ' . $self->pgUser() . '}}',
|
||||
'skip missing file');
|
||||
}
|
||||
|
||||
################################################################################################################################
|
||||
if ($self->begin("FileCommon::fileManifestRecurse()"))
|
||||
{
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
my $strTestPath = $self->testPath() . '/public_dir';
|
||||
my $strTestFile = "${strTestPath}/test.txt";
|
||||
|
||||
$self->testException(
|
||||
sub {my $hManifest = {}; pgBackRest::FileCommon::fileManifestRecurse($strTestFile, undef, 0, $hManifest); $hManifest},
|
||||
ERROR_FILE_MISSING, "unable to stat ${strTestFile}: No such file or directory");
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
filePathCreate($strTestPath, '0750');
|
||||
|
||||
$self->testResult(
|
||||
sub {my $hManifest = {}; pgBackRest::FileCommon::fileManifestRecurse($strTestPath, undef, 0, $hManifest); $hManifest},
|
||||
'{. => {group => ' . $self->group() . ', mode => 0750, type => d, user => ' . $self->pgUser() . '}}',
|
||||
'empty directory manifest');
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
fileStringWrite($strTestFile, "TEST");
|
||||
utime(1111111111, 1111111111, $strTestFile);
|
||||
executeTest('chmod 0750 ' . $strTestFile);
|
||||
|
||||
filePathCreate("${strTestPath}/sub", '0750');
|
||||
|
||||
$self->testResult(
|
||||
sub {my $hManifest = {}; pgBackRest::FileCommon::fileManifestRecurse(
|
||||
$self->testPath(), basename($strTestPath), 1, $hManifest); $hManifest},
|
||||
'{public_dir => {group => ' . $self->group() . ', mode => 0750, type => d, user => ' . $self->pgUser() . '}, ' .
|
||||
'public_dir/sub => {group => ' . $self->group() . ', mode => 0750, type => d, user => ' . $self->pgUser() . '}, ' .
|
||||
'public_dir/' . basename($strTestFile) . ' => {group => ' . $self->group() .
|
||||
', mode => 0750, modification_time => 1111111111, size => 4, type => f, user => ' . $self->pgUser() . '}}',
|
||||
'directory and file manifest');
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
$self->testResult(
|
||||
sub {my $hManifest = {}; pgBackRest::FileCommon::fileManifestRecurse($strTestFile, undef, 0, $hManifest); $hManifest},
|
||||
'{' . basename($strTestFile) . ' => {group => ' . $self->group() .
|
||||
', mode => 0750, modification_time => 1111111111, size => 4, type => f, user => ' . $self->pgUser() . '}}',
|
||||
'single file manifest');
|
||||
}
|
||||
|
||||
# Loop through local/remote
|
||||
for (my $bRemote = false; $bRemote <= true; $bRemote++)
|
||||
{
|
||||
if (!$self->begin('File->manifest() => ' . ($bRemote ? 'remote' : 'local'))) {next}
|
||||
|
||||
# Create the file object
|
||||
my $oFile = new pgBackRest::File
|
||||
(
|
||||
$self->stanza(),
|
||||
$self->testPath(),
|
||||
$bRemote ? $self->remote() : $self->local()
|
||||
);
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
my $strMissingFile = $self->testPath() . '/missing';
|
||||
|
||||
$self->testException(
|
||||
sub {$oFile->manifest(PATH_BACKUP_ABSOLUTE, $strMissingFile)},
|
||||
ERROR_FILE_MISSING, "unable to stat ${strMissingFile}: No such file or directory");
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
# Setup test data
|
||||
executeTest('mkdir -m 750 ' . $self->testPath() . '/sub1');
|
||||
executeTest('mkdir -m 750 ' . $self->testPath() . '/sub1/sub2');
|
||||
|
||||
executeTest("echo 'TESTDATA' > " . $self->testPath() . '/test.txt');
|
||||
utime(1111111111, 1111111111, $self->testPath() . '/test.txt');
|
||||
executeTest('chmod 1640 ' . $self->testPath() . '/test.txt');
|
||||
|
||||
executeTest("echo 'TESTDATA_' > ". $self->testPath() . '/sub1/test-sub1.txt');
|
||||
utime(1111111112, 1111111112, $self->testPath() . '/sub1/test-sub1.txt');
|
||||
executeTest('chmod 0640 ' . $self->testPath() . '/sub1/test-sub1.txt');
|
||||
|
||||
executeTest("echo 'TESTDATA__' > " . $self->testPath() . '/sub1/sub2/test-sub2.txt');
|
||||
utime(1111111113, 1111111113, $self->testPath() . '/sub1/sub2/test-sub2.txt');
|
||||
executeTest('chmod 0646 ' . $self->testPath() . '/sub1/test-sub1.txt');
|
||||
|
||||
executeTest('ln ' . $self->testPath() . '/test.txt ' . $self->testPath() . '/sub1/test-hardlink.txt');
|
||||
executeTest('ln ' . $self->testPath() . '/test.txt ' . $self->testPath() . '/sub1/sub2/test-hardlink.txt');
|
||||
|
||||
executeTest('ln -s .. ' . $self->testPath() . '/sub1/test');
|
||||
executeTest('chmod 0700 ' . $self->testPath() . '/sub1/test');
|
||||
executeTest('ln -s ../.. ' . $self->testPath() . '/sub1/sub2/test');
|
||||
executeTest('chmod 0750 ' . $self->testPath() . '/sub1/sub2/test');
|
||||
|
||||
executeTest('chmod 0770 ' . $self->testPath());
|
||||
|
||||
$self->testResult(
|
||||
sub {$oFile->manifest(PATH_BACKUP_ABSOLUTE, $self->testPath())},
|
||||
'{. => {group => ' . $self->group() . ', mode => 0770, type => d, user => ' . $self->pgUser() . '}, ' .
|
||||
'sub1 => {group => ' . $self->group() . ', mode => 0750, type => d, user => ' . $self->pgUser() . '}, ' .
|
||||
'sub1/sub2 => {group => ' . $self->group() . ', mode => 0750, type => d, user => ' . $self->pgUser() . '}, ' .
|
||||
'sub1/sub2/test => {group => ' . $self->group() . ', link_destination => ../.., type => l, user => ' .
|
||||
$self->pgUser() . '}, ' .
|
||||
'sub1/sub2/test-hardlink.txt => ' .
|
||||
'{group => ' . $self->group() . ', mode => 1640, modification_time => 1111111111, size => 9, type => f, user => ' .
|
||||
$self->pgUser() . '}, ' .
|
||||
'sub1/sub2/test-sub2.txt => ' .
|
||||
'{group => ' . $self->group() . ', mode => 0666, modification_time => 1111111113, size => 11, type => f, user => ' .
|
||||
$self->pgUser() . '}, ' .
|
||||
'sub1/test => {group => ' . $self->group() . ', link_destination => .., type => l, user => ' . $self->pgUser() . '}, ' .
|
||||
'sub1/test-hardlink.txt => ' .
|
||||
'{group => ' . $self->group() . ', mode => 1640, modification_time => 1111111111, size => 9, type => f, user => ' .
|
||||
$self->pgUser() . '}, ' .
|
||||
'sub1/test-sub1.txt => ' .
|
||||
'{group => ' . $self->group() . ', mode => 0646, modification_time => 1111111112, size => 10, type => f, user => ' .
|
||||
$self->pgUser() . '}, ' .
|
||||
'test.txt => ' .
|
||||
'{group => ' . $self->group() . ', mode => 1640, modification_time => 1111111111, size => 9, type => f, user => ' .
|
||||
$self->pgUser() . '}}',
|
||||
'complete manifest');
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
107
test/lib/pgBackRestTest/Module/File/FileMoveTest.pm
Normal file
107
test/lib/pgBackRestTest/Module/File/FileMoveTest.pm
Normal file
@@ -0,0 +1,107 @@
|
||||
####################################################################################################################################
|
||||
# FileMoveTest.pm - Tests for File->move()
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::File::FileMoveTest;
|
||||
use parent 'pgBackRestTest::Module::File::FileCommonTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::File;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
####################################################################################################################################
|
||||
sub run
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Loop through local/remote ??? enable remote tests and have them throw an error
|
||||
for (my $bRemote = 0; $bRemote <= 0; $bRemote++)
|
||||
{
|
||||
# Loop through source exists
|
||||
for (my $bSourceExists = 0; $bSourceExists <= 1; $bSourceExists++)
|
||||
{
|
||||
# Loop through source errors
|
||||
for (my $bSourceError = 0; $bSourceError <= 1; $bSourceError++)
|
||||
{
|
||||
# Loop through destination exists
|
||||
for (my $bDestinationExists = 0; $bDestinationExists <= 1; $bDestinationExists++)
|
||||
{
|
||||
# Loop through source errors
|
||||
for (my $bDestinationError = 0; $bDestinationError <= 1; $bDestinationError++)
|
||||
{
|
||||
# Loop through create
|
||||
for (my $bCreate = 0; $bCreate <= $bDestinationExists; $bCreate++)
|
||||
{
|
||||
# Increment the run, log, and decide whether this unit test should be run
|
||||
if (!$self->begin(
|
||||
"src_exists ${bSourceExists}, src_error ${bSourceError}, " .
|
||||
", dst_exists ${bDestinationExists}, dst_error ${bDestinationError}, dst_create ${bCreate}")) {next}
|
||||
|
||||
# Setup test directory and get file object
|
||||
my $oFile = $self->setup($bRemote, $bSourceError || $bDestinationError);
|
||||
|
||||
my $strSourceFile = $self->testPath() . '/test.txt';
|
||||
my $strDestinationFile = $self->testPath() . '/test-dest.txt';
|
||||
|
||||
if ($bSourceError)
|
||||
{
|
||||
$strSourceFile = $self->testPath() . '/' . ($bRemote ? 'user' : 'backrest') . "_private/test.txt";
|
||||
}
|
||||
elsif ($bSourceExists)
|
||||
{
|
||||
executeTest("echo 'TESTDATA' > ${strSourceFile}");
|
||||
}
|
||||
|
||||
if ($bDestinationError)
|
||||
{
|
||||
$strDestinationFile = $self->testPath() . '/' . ($bRemote ? 'user' : 'backrest') . "_private/test.txt";
|
||||
}
|
||||
elsif (!$bDestinationExists)
|
||||
{
|
||||
$strDestinationFile = $self->testPath() . '/sub/test-dest.txt';
|
||||
}
|
||||
|
||||
# Execute in eval in case of error
|
||||
eval
|
||||
{
|
||||
$oFile->move(PATH_BACKUP_ABSOLUTE, $strSourceFile, PATH_BACKUP_ABSOLUTE, $strDestinationFile, $bCreate);
|
||||
return true;
|
||||
}
|
||||
or do
|
||||
{
|
||||
if (!$bSourceExists || (!$bDestinationExists && !$bCreate) || $bSourceError || $bDestinationError)
|
||||
{
|
||||
next;
|
||||
}
|
||||
|
||||
confess $EVAL_ERROR;
|
||||
};
|
||||
|
||||
if (!$bSourceExists || (!$bDestinationExists && !$bCreate) || $bSourceError || $bDestinationError)
|
||||
{
|
||||
confess 'error should have been raised';
|
||||
}
|
||||
|
||||
unless (-e $strDestinationFile)
|
||||
{
|
||||
confess 'file was not moved';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
105
test/lib/pgBackRestTest/Module/File/FileOwnerTest.pm
Normal file
105
test/lib/pgBackRestTest/Module/File/FileOwnerTest.pm
Normal file
@@ -0,0 +1,105 @@
|
||||
####################################################################################################################################
|
||||
# FileOwnerTest.pm - Tests for File->owner()
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::File::FileOwnerTest;
|
||||
use parent 'pgBackRestTest::Module::File::FileCommonTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use pgBackRest::Common::Exception;
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::File;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
use pgBackRestTest::Common::RunTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
####################################################################################################################################
|
||||
sub run
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Loop through local/remote
|
||||
foreach my $bRemote (false, true)
|
||||
{
|
||||
# Loop through exists
|
||||
foreach my $bExists (!$bRemote ? (false, true) : (false))
|
||||
{
|
||||
# Loop through exists
|
||||
foreach my $bError ($bExists && !$bRemote ? (false, true) : (false))
|
||||
{
|
||||
# Loop through users
|
||||
foreach my $strUser ($bExists && !$bError && !$bRemote ? ($self->pgUser(), BOGUS, undef) : ($self->pgUser()))
|
||||
{
|
||||
# Loop through group
|
||||
foreach my $strGroup (
|
||||
$bExists && !$bError && !$bRemote && defined($strUser) && $strUser ne BOGUS ? ($self->group(), BOGUS, undef) : ($self->group()))
|
||||
{
|
||||
if (!$self->begin(
|
||||
"rmt ${bRemote}, err ${bError}, exists ${bExists}, user " . (defined($strUser) ? $strUser : '[undef]') .
|
||||
", group " . (defined($strGroup) ? $strGroup : '[undef]'))) {next}
|
||||
|
||||
# Setup test directory and get file object
|
||||
my $oFile = $self->setup($bRemote, $bError);
|
||||
|
||||
# Create the test file
|
||||
my $strFile = $self->testPath() . '/test.txt';
|
||||
|
||||
if ($bExists)
|
||||
{
|
||||
executeTest("echo 'TESTDATA' > ${strFile}");
|
||||
|
||||
if ($bError)
|
||||
{
|
||||
executeTest("sudo chown root:root ${strFile}");
|
||||
}
|
||||
}
|
||||
|
||||
my $strFunction = sub {$oFile->owner(PATH_BACKUP_ABSOLUTE, $strFile, $strUser, $strGroup)};
|
||||
|
||||
# Remote operation not allowed
|
||||
if ($bRemote)
|
||||
{
|
||||
$self->testException($strFunction, ERROR_ASSERT, "pgBackRest::File->owner: remote operation not supported");
|
||||
}
|
||||
# Error on not exists
|
||||
elsif (!$bExists)
|
||||
{
|
||||
$self->testException($strFunction, ERROR_FILE_MISSING, "${strFile} does not exist");
|
||||
}
|
||||
# Else permission error
|
||||
elsif ($bError)
|
||||
{
|
||||
$self->testException(
|
||||
$strFunction, ERROR_FILE_OWNER, "unable to set ownership for '${strFile}': Operation not permitted");
|
||||
}
|
||||
# Else bogus user
|
||||
elsif (defined($strUser) && $strUser eq BOGUS)
|
||||
{
|
||||
$self->testException($strFunction, ERROR_USER_MISSING, "user '" . BOGUS . "' does not exist");
|
||||
}
|
||||
# Else bogus group
|
||||
elsif (defined($strGroup) && $strGroup eq BOGUS)
|
||||
{
|
||||
$self->testException($strFunction, ERROR_GROUP_MISSING, "group '" . BOGUS . "' does not exist");
|
||||
}
|
||||
# Else success
|
||||
else
|
||||
{
|
||||
$self->testResult($strFunction, '[undef]', 'success');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
115
test/lib/pgBackRestTest/Module/File/FilePathCreateTest.pm
Normal file
115
test/lib/pgBackRestTest/Module/File/FilePathCreateTest.pm
Normal file
@@ -0,0 +1,115 @@
|
||||
####################################################################################################################################
|
||||
# FilePathCreateTest.pm - Tests for File->pathCreate()
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::File::FilePathCreateTest;
|
||||
use parent 'pgBackRestTest::Module::File::FileCommonTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use Fcntl qw(:mode);
|
||||
use File::stat;
|
||||
|
||||
use pgBackRest::Common::Exception;
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::File;
|
||||
use pgBackRest::FileCommon;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
####################################################################################################################################
|
||||
sub run
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Loop through local/remote
|
||||
for (my $bRemote = 0; $bRemote <= 1; $bRemote++)
|
||||
{
|
||||
# Loop through error
|
||||
for (my $bError = 0; $bError <= 1; $bError++)
|
||||
{
|
||||
# Loop through mode (mode will be set on true)
|
||||
foreach my $strMode (undef, '0700')
|
||||
{
|
||||
my $strPathType = PATH_BACKUP_CLUSTER;
|
||||
|
||||
# Increment the run, log, and decide whether this unit test should be run
|
||||
if (!$self->begin("rmt ${bRemote}, err ${bError}, mode " . (defined($strMode) ? $strMode : 'undef'))) {next}
|
||||
|
||||
# Setup test directory and get file object
|
||||
my $oFile = $self->setup($bRemote, $bError);
|
||||
|
||||
filePathCreate($self->testPath() . '/backup', '770');
|
||||
filePathCreate($self->testPath() . '/backup/db', '770');
|
||||
|
||||
my $strPath = 'path';
|
||||
|
||||
# If not exists then set the path to something bogus
|
||||
if ($bError)
|
||||
{
|
||||
$strPath = $self->testPath() . '/' . ($bRemote ? 'user' : 'backrest') . "_private/path";
|
||||
|
||||
$strPathType = PATH_BACKUP_ABSOLUTE;
|
||||
}
|
||||
|
||||
# Execute in eval to catch errors
|
||||
my $bErrorExpected = $bError;
|
||||
|
||||
eval
|
||||
{
|
||||
$oFile->pathCreate($strPathType, $strPath, $strMode);
|
||||
return true;
|
||||
}
|
||||
# Check for errors
|
||||
or do
|
||||
{
|
||||
# Ignore errors if the path did not exist
|
||||
if ($bErrorExpected)
|
||||
{
|
||||
next;
|
||||
}
|
||||
|
||||
confess $EVAL_ERROR;
|
||||
};
|
||||
|
||||
if ($bErrorExpected)
|
||||
{
|
||||
confess 'error was expected';
|
||||
}
|
||||
|
||||
# Make sure the path was actually created
|
||||
my $strPathCheck = $oFile->pathGet($strPathType, $strPath);
|
||||
|
||||
unless (-e $strPathCheck)
|
||||
{
|
||||
confess 'path was not created';
|
||||
}
|
||||
|
||||
# Check that the mode was set correctly
|
||||
my $oStat = lstat($strPathCheck);
|
||||
|
||||
if (!defined($oStat))
|
||||
{
|
||||
confess "unable to stat ${strPathCheck}";
|
||||
}
|
||||
|
||||
if (defined($strMode))
|
||||
{
|
||||
if ($strMode ne sprintf('%04o', S_IMODE($oStat->mode)))
|
||||
{
|
||||
confess "mode was not set to {$strMode}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
112
test/lib/pgBackRestTest/Module/File/FileRemoveTest.pm
Normal file
112
test/lib/pgBackRestTest/Module/File/FileRemoveTest.pm
Normal file
@@ -0,0 +1,112 @@
|
||||
####################################################################################################################################
|
||||
# FileRemoveTest.pm - Tests for File->remove()
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::File::FileRemoveTest;
|
||||
use parent 'pgBackRestTest::Module::File::FileCommonTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::File;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
####################################################################################################################################
|
||||
sub run
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Loop through local/remote
|
||||
foreach my $bRemote (false, true)
|
||||
{
|
||||
# Loop through exists
|
||||
foreach my $bError (false, true)
|
||||
{
|
||||
# Loop through exists
|
||||
foreach my $bExists (false, true)
|
||||
{
|
||||
# Loop through temp
|
||||
foreach my $bTemp (false, true)
|
||||
{
|
||||
# Loop through ignore missing
|
||||
foreach my $bIgnoreMissing (false, true)
|
||||
{
|
||||
if (!$self->begin(
|
||||
"rmt ${bRemote}, err = ${bError}, exists ${bExists}, tmp ${bTemp}, ignmis ${bIgnoreMissing}")) {next}
|
||||
|
||||
# Setup test directory and get file object
|
||||
my $oFile = $self->setup($bRemote, $bError);
|
||||
|
||||
my $strFile = $self->testPath() . '/test.txt';
|
||||
|
||||
if ($bError)
|
||||
{
|
||||
$strFile = $self->testPath() . '/' . ($bRemote ? 'user' : 'backrest') . '_private/test.txt';
|
||||
}
|
||||
elsif (!$bExists)
|
||||
{
|
||||
$strFile = $self->testPath() . '/private/error.txt';
|
||||
}
|
||||
else
|
||||
{
|
||||
executeTest("echo 'TESTDATA' > ${strFile}" . ($bTemp ? '.pgbackrest.tmp' : ''));
|
||||
}
|
||||
|
||||
# Execute in eval in case of error
|
||||
my $bRemoved;
|
||||
|
||||
eval
|
||||
{
|
||||
$bRemoved = $oFile->remove(PATH_BACKUP_ABSOLUTE, $strFile, $bTemp, $bIgnoreMissing);
|
||||
return true;
|
||||
}
|
||||
or do
|
||||
{
|
||||
if ($bError || $bRemote)
|
||||
{
|
||||
next;
|
||||
}
|
||||
|
||||
if (!$bExists && !$bIgnoreMissing)
|
||||
{
|
||||
next;
|
||||
}
|
||||
|
||||
confess $EVAL_ERROR;
|
||||
};
|
||||
|
||||
if ($bError || $bRemote)
|
||||
{
|
||||
confess 'error should have been returned';
|
||||
}
|
||||
|
||||
if (!$bRemoved)
|
||||
{
|
||||
if (!$bExists && $bIgnoreMissing)
|
||||
{
|
||||
next;
|
||||
}
|
||||
|
||||
confess 'remove returned false, but something should have been removed';
|
||||
}
|
||||
|
||||
if (-e ($strFile . ($bTemp ? '.pgbackrest.tmp' : '')))
|
||||
{
|
||||
confess 'file still exists';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
64
test/lib/pgBackRestTest/Module/File/FileStatTest.pm
Normal file
64
test/lib/pgBackRestTest/Module/File/FileStatTest.pm
Normal file
@@ -0,0 +1,64 @@
|
||||
####################################################################################################################################
|
||||
# FileStatTest.pm - Tests for FileCommon::fileStat
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::File::FileStatTest;
|
||||
use parent 'pgBackRestTest::Module::File::FileCommonTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use Fcntl qw(:mode);
|
||||
use File::stat;
|
||||
|
||||
use pgBackRest::Common::Exception;
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::FileCommon;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
use pgBackRestTest::Common::RunTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
####################################################################################################################################
|
||||
sub run
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
################################################################################################################################
|
||||
if ($self->begin("FileCommon::fileStat()"))
|
||||
{
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
my $strFile = $self->testPath() . '/test.txt';
|
||||
|
||||
$self->testException(sub {fileStat($strFile)}, ERROR_FILE_MISSING, "unable to stat ${strFile}: No such file or directory");
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
$self->testResult(sub {fileStat($strFile, true)}, '[undef]', 'ignore missing file');
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
fileStringWrite($strFile);
|
||||
|
||||
$self->testResult(sub {fileStat($strFile)}, '[object]', 'stat file');
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
$self->testResult(sub {S_ISREG(fileStat($strFile)->mode)}, true, 'check stat file result');
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
my $strPrivateDir = $self->testPath() . '/private_dir';
|
||||
my $strPrivateFile = "${strPrivateDir}/test.txt";
|
||||
executeTest("sudo mkdir -m 700 ${strPrivateDir}");
|
||||
|
||||
$self->testException(
|
||||
sub {fileStat($strPrivateFile, true)}, ERROR_FILE_OPEN, "unable to stat ${strPrivateFile}: Permission denied");
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
$self->testResult(sub {S_ISDIR(fileStat($strPrivateDir)->mode)}, true, 'check stat directory result');
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
137
test/lib/pgBackRestTest/Module/File/FileUnitTest.pm
Normal file
137
test/lib/pgBackRestTest/Module/File/FileUnitTest.pm
Normal file
@@ -0,0 +1,137 @@
|
||||
####################################################################################################################################
|
||||
# FileUnitTest.pm - Unit tests for File module.
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::File::FileUnitTest;
|
||||
use parent 'pgBackRestTest::Module::File::FileCommonTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use pgBackRest::Common::Exception;
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::File;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
####################################################################################################################################
|
||||
sub run
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Increment the run, log, and decide whether this unit test should be run
|
||||
if (!$self->begin('unit')) {return}
|
||||
|
||||
# Setup test directory and get file object
|
||||
my $oLocalFile = $self->setup(false, false);
|
||||
|
||||
# Test File->pathTypeGet()
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
&log(INFO, " File->pathTypeGet()");
|
||||
|
||||
$self->testResult(sub {$oLocalFile->pathTypeGet(PATH_ABSOLUTE)}, PATH_ABSOLUTE, 'absolute path type');
|
||||
$self->testResult(sub {$oLocalFile->pathTypeGet(PATH_DB)}, PATH_DB, 'db path type');
|
||||
$self->testResult(sub {$oLocalFile->pathTypeGet(PATH_DB_ABSOLUTE)}, PATH_DB, 'db absolute path type');
|
||||
$self->testResult(sub {$oLocalFile->pathTypeGet(PATH_BACKUP)}, PATH_BACKUP, 'backup path type');
|
||||
$self->testResult(sub {$oLocalFile->pathTypeGet(PATH_BACKUP_ARCHIVE)}, PATH_BACKUP, 'backup archive path type');
|
||||
$self->testException(sub {$oLocalFile->pathTypeGet('bogus')}, ERROR_ASSERT, "no known path types in 'bogus'");
|
||||
}
|
||||
|
||||
# Test File->pathGet()
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
&log(INFO, " File->pathGet()");
|
||||
|
||||
# Test temp file errors
|
||||
$self->testException(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP, 'test', true)},
|
||||
ERROR_ASSERT, "temp file not supported for path type 'backup'");
|
||||
$self->testException(
|
||||
sub {$oLocalFile->pathGet(PATH_ABSOLUTE, undef, true)},
|
||||
ERROR_ASSERT, "strFile must be defined when temp file specified");
|
||||
$self->testException(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_ARCHIVE, undef, true)},
|
||||
ERROR_ASSERT, "strFile must be defined when temp file specified");
|
||||
$self->testException(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_ARCHIVE_OUT, undef, true)},
|
||||
ERROR_ASSERT, "strFile must be defined when temp file specified");
|
||||
$self->testException(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_TMP, undef, true)},
|
||||
ERROR_ASSERT, "strFile must be defined when temp file specified");
|
||||
|
||||
# Test absolute path
|
||||
$self->testException(
|
||||
sub {$oLocalFile->pathGet(PATH_ABSOLUTE)}, ERROR_ASSERT, "strFile must be defined for absolute path");
|
||||
$self->testException(
|
||||
sub {$oLocalFile->pathGet(PATH_ABSOLUTE, 'file')}, ERROR_ASSERT, "absolute path absolute:file must start with /");
|
||||
$self->testResult(sub {$oLocalFile->pathGet(PATH_ABSOLUTE, '/file', true)}, "/file.pgbackrest.tmp", 'absolute path temp');
|
||||
$self->testResult(sub {$oLocalFile->pathGet(PATH_ABSOLUTE, '/file')}, "/file", 'absolute path file');
|
||||
|
||||
# Test backup path
|
||||
$self->testResult(sub {$oLocalFile->pathGet(PATH_BACKUP, 'file')}, $self->testPath() . '/file', 'backup path file');
|
||||
$self->testResult(sub {$oLocalFile->pathGet(PATH_BACKUP, undef)}, $self->testPath(), 'backup path');
|
||||
|
||||
# Error when stanza not defined
|
||||
$self->testException(
|
||||
sub {(new pgBackRest::File(undef, $self->testPath(), $self->local()))->pathGet(PATH_BACKUP_TMP)},
|
||||
ERROR_ASSERT, "strStanza not defined");
|
||||
|
||||
# Test backup tmp path
|
||||
$self->testResult(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_TMP, 'file', true)}, $self->testPath() . '/temp/db.tmp/file.pgbackrest.tmp',
|
||||
'backup temp path temp file');
|
||||
$self->testResult(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_TMP, 'file')}, $self->testPath() . '/temp/db.tmp/file', 'backup temp path file');
|
||||
$self->testResult(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_TMP, undef)}, $self->testPath() . '/temp/db.tmp', 'backup temp path');
|
||||
|
||||
# Test archive path
|
||||
$self->testResult(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_ARCHIVE, undef)}, $self->testPath() . '/archive/db', 'archive path');
|
||||
$self->testResult(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_ARCHIVE, '9.3-1')}, $self->testPath() . '/archive/db/9.3-1', 'archive id path');
|
||||
$self->testResult(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_ARCHIVE, '9.3-1/000000010000000100000001')},
|
||||
$self->testPath() . '/archive/db/9.3-1/0000000100000001/000000010000000100000001',
|
||||
'archive path file');
|
||||
$self->testResult(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_ARCHIVE, '9.3-1/000000010000000100000001', true)},
|
||||
$self->testPath() . '/archive/db/9.3-1/0000000100000001/000000010000000100000001.pgbackrest.tmp',
|
||||
'archive path temp file');
|
||||
$self->testResult(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_ARCHIVE, '9.3-1/00000001.history')},
|
||||
$self->testPath() . '/archive/db/9.3-1/00000001.history',
|
||||
'archive path history file');
|
||||
$self->testResult(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_ARCHIVE, '9.3-1/00000001.history', true)},
|
||||
$self->testPath() . '/archive/db/9.3-1/00000001.history.pgbackrest.tmp',
|
||||
'archive path history temp file');
|
||||
|
||||
# Test archive out path
|
||||
$self->testResult(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_ARCHIVE_OUT, '000000010000000100000001')},
|
||||
$self->testPath() . '/archive/db/out/000000010000000100000001',
|
||||
'archive out path file');
|
||||
$self->testResult(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_ARCHIVE_OUT)}, $self->testPath() . '/archive/db/out', 'archive out path');
|
||||
$self->testResult(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_ARCHIVE_OUT, '000000010000000100000001', true)},
|
||||
$self->testPath() . '/archive/db/out/000000010000000100000001.pgbackrest.tmp',
|
||||
'archive out path temp file');
|
||||
|
||||
# Test backup cluster path
|
||||
$self->testResult(
|
||||
sub {$oLocalFile->pathGet(PATH_BACKUP_CLUSTER, 'file')}, $self->testPath() . '/backup/db/file', 'cluster path file');
|
||||
$self->testResult(sub {$oLocalFile->pathGet(PATH_BACKUP_CLUSTER)}, $self->testPath() . '/backup/db', 'cluster path');
|
||||
|
||||
# Test invalid path type
|
||||
$self->testException(sub {$oLocalFile->pathGet('bogus')}, ERROR_ASSERT, "no known path types in 'bogus'");
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
71
test/lib/pgBackRestTest/Module/File/FileWaitTest.pm
Normal file
71
test/lib/pgBackRestTest/Module/File/FileWaitTest.pm
Normal file
@@ -0,0 +1,71 @@
|
||||
####################################################################################################################################
|
||||
# FileWaitTest.pm - Tests for File->wait()
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::File::FileWaitTest;
|
||||
use parent 'pgBackRestTest::Module::File::FileCommonTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use POSIX qw(ceil);
|
||||
use Time::HiRes qw(gettimeofday usleep);
|
||||
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::File;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
####################################################################################################################################
|
||||
sub run
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Loop through local/remote
|
||||
for (my $bRemote = 0; $bRemote <= 1; $bRemote++)
|
||||
{
|
||||
my $lTimeBegin = gettimeofday();
|
||||
|
||||
if (!$self->begin("rmt ${bRemote}, begin ${lTimeBegin}")) {next}
|
||||
|
||||
# Setup test directory and get file object
|
||||
my $oFile = $self->setup($bRemote);
|
||||
|
||||
# If there is not enough time to complete the test then sleep
|
||||
if (ceil($lTimeBegin) - $lTimeBegin < .250)
|
||||
{
|
||||
my $lSleepMs = ceil(((int($lTimeBegin) + 1) - $lTimeBegin) * 1000);
|
||||
|
||||
usleep($lSleepMs * 1000);
|
||||
|
||||
&log(DEBUG, "slept ${lSleepMs}ms: begin ${lTimeBegin}, end " . gettimeofday());
|
||||
|
||||
$lTimeBegin = gettimeofday();
|
||||
}
|
||||
|
||||
# Run the test
|
||||
my $lTimeBeginCheck = $oFile->wait(PATH_DB_ABSOLUTE);
|
||||
|
||||
&log(DEBUG, "begin ${lTimeBegin}, check ${lTimeBeginCheck}, end " . time());
|
||||
|
||||
# Current time should have advanced by 1 second
|
||||
if (int(time()) == int($lTimeBegin))
|
||||
{
|
||||
confess "time was not advanced by 1 second";
|
||||
}
|
||||
|
||||
# lTimeBegin and lTimeBeginCheck should be equal
|
||||
if (int($lTimeBegin) != $lTimeBeginCheck)
|
||||
{
|
||||
confess 'time begin ' || int($lTimeBegin) || "and check ${lTimeBeginCheck} should be equal";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user