2014-07-17 06:38:38 +03:00
|
|
|
#!/usr/bin/perl
|
|
|
|
####################################################################################################################################
|
|
|
|
# BackupTest.pl - Unit Tests for BackRest::File
|
|
|
|
####################################################################################################################################
|
|
|
|
package BackRestTest::UtilityTest;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Carp;
|
|
|
|
|
|
|
|
use File::Basename;
|
|
|
|
|
2014-09-18 19:37:14 +03:00
|
|
|
use lib dirname($0) . '/../lib';
|
2014-07-17 06:38:38 +03:00
|
|
|
use BackRest::Utility;
|
2014-07-27 21:03:21 +03:00
|
|
|
use BackRest::File;
|
2014-07-17 06:38:38 +03:00
|
|
|
|
|
|
|
use BackRestTest::CommonTest;
|
|
|
|
|
|
|
|
use Exporter qw(import);
|
|
|
|
our @EXPORT = qw(BackRestTestUtility_Test);
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestUtility_Drop
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestUtility_Drop
|
|
|
|
{
|
|
|
|
# Remove the test directory
|
|
|
|
system('rm -rf ' . BackRestTestCommon_TestPathGet()) == 0
|
|
|
|
or die 'unable to remove ' . BackRestTestCommon_TestPathGet() . 'path';
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestUtility_Create
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestUtility_Create
|
|
|
|
{
|
|
|
|
# Drop the old test directory
|
|
|
|
BackRestTestUtility_Drop();
|
|
|
|
|
|
|
|
# Create the test directory
|
|
|
|
mkdir(BackRestTestCommon_TestPathGet(), oct('0770'))
|
|
|
|
or confess 'Unable to create ' . BackRestTestCommon_TestPathGet() . ' path';
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# BackRestTestUtility_Test
|
|
|
|
####################################################################################################################################
|
|
|
|
sub BackRestTestUtility_Test
|
|
|
|
{
|
|
|
|
my $strTest = shift;
|
|
|
|
|
|
|
|
# Setup test variables
|
|
|
|
my $iRun;
|
|
|
|
my $bCreate;
|
|
|
|
my $strTestPath = BackRestTestCommon_TestPathGet();
|
|
|
|
|
|
|
|
# Print test banner
|
2014-09-18 19:37:14 +03:00
|
|
|
&log(INFO, 'UTILITY MODULE ******************************************************************');
|
2014-07-17 06:38:38 +03:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Test config
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($strTest eq 'all' || $strTest eq 'config')
|
|
|
|
{
|
|
|
|
$iRun = 0;
|
|
|
|
$bCreate = true;
|
2014-07-27 21:03:21 +03:00
|
|
|
my $oFile = BackRest::File->new();
|
2014-07-17 06:38:38 +03:00
|
|
|
|
|
|
|
&log(INFO, "Test config\n");
|
|
|
|
|
|
|
|
# Increment the run, log, and decide whether this unit test should be run
|
2014-09-18 19:37:14 +03:00
|
|
|
if (BackRestTestCommon_Run(++$iRun, 'base'))
|
2014-07-17 06:38:38 +03:00
|
|
|
{
|
|
|
|
# Create the test directory
|
|
|
|
if ($bCreate)
|
|
|
|
{
|
|
|
|
BackRestTestUtility_Create();
|
|
|
|
|
|
|
|
$bCreate = false;
|
|
|
|
}
|
|
|
|
|
2014-07-27 21:03:21 +03:00
|
|
|
# Generate a test config
|
2014-07-17 06:38:38 +03:00
|
|
|
my %oConfig;
|
|
|
|
|
|
|
|
$oConfig{test1}{key1} = 'value';
|
|
|
|
$oConfig{test1}{key2} = 'value';
|
|
|
|
|
|
|
|
$oConfig{test2}{key1} = 'value';
|
|
|
|
|
|
|
|
$oConfig{test3}{key1} = 'value';
|
|
|
|
$oConfig{test3}{key2}{sub1} = 'value';
|
|
|
|
$oConfig{test3}{key2}{sub2} = 'value';
|
|
|
|
|
2014-07-27 21:03:21 +03:00
|
|
|
# Save the test config
|
|
|
|
my $strFile = "${strTestPath}/config.cfg";
|
2014-12-16 00:20:42 +02:00
|
|
|
ini_save($strFile, \%oConfig);
|
2014-07-27 21:03:21 +03:00
|
|
|
|
|
|
|
my $strConfigHash = $oFile->hash(PATH_ABSOLUTE, $strFile);
|
|
|
|
|
|
|
|
# Reload the test config
|
|
|
|
my %oConfigTest;
|
2014-07-17 06:38:38 +03:00
|
|
|
|
2014-12-16 00:20:42 +02:00
|
|
|
ini_load($strFile, \%oConfigTest);
|
2014-07-17 06:38:38 +03:00
|
|
|
|
2014-07-27 21:03:21 +03:00
|
|
|
# Resave the test config and compare hashes
|
|
|
|
my $strFileTest = "${strTestPath}/config-test.cfg";
|
2014-12-16 00:20:42 +02:00
|
|
|
ini_save($strFileTest, \%oConfigTest);
|
2014-07-27 21:03:21 +03:00
|
|
|
|
|
|
|
my $strConfigTestHash = $oFile->hash(PATH_ABSOLUTE, $strFileTest);
|
|
|
|
|
|
|
|
if ($strConfigHash ne $strConfigTestHash)
|
2014-07-17 06:38:38 +03:00
|
|
|
{
|
2014-07-27 21:03:21 +03:00
|
|
|
confess "config hash ${strConfigHash} != ${strConfigTestHash}";
|
2014-07-17 06:38:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (BackRestTestCommon_Cleanup())
|
|
|
|
{
|
|
|
|
&log(INFO, 'cleanup');
|
|
|
|
BackRestTestUtility_Drop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|