mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-06 00:03:38 +00:00
Remove logging statement; refactor test scripts
This commit is contained in:
@@ -1,80 +1,17 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -x
|
|
||||||
get_abs_filename() {
|
|
||||||
# $1 : relative filename
|
|
||||||
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
|
|
||||||
}
|
|
||||||
DUPLICACY=$(get_abs_filename ../duplicacy_main)
|
|
||||||
|
|
||||||
TEST_ZONE=$HOME/DUPLICACY_TEST_ZONE
|
|
||||||
TEST_REPO=$TEST_ZONE/TEST_REPO
|
|
||||||
TEST_STORAGE=$TEST_ZONE/TEST_STORAGE
|
|
||||||
TEST_DOT_DUPLICACY=$TEST_ZONE/TEST_DOT_DUPLICACY
|
|
||||||
TEST_RESTORE_POINT=$TEST_ZONE/RESTORE_POINT
|
|
||||||
function fixture()
|
|
||||||
{
|
|
||||||
# clean TEST_RESTORE_POINT
|
|
||||||
rm -rf $TEST_RESTORE_POINT
|
|
||||||
mkdir -p $TEST_RESTORE_POINT
|
|
||||||
|
|
||||||
# clean TEST_STORAGE
|
|
||||||
rm -rf $TEST_STORAGE
|
|
||||||
mkdir -p $TEST_STORAGE
|
|
||||||
|
|
||||||
# clean TEST_DOT_DUPLICACY
|
|
||||||
rm -rf $TEST_DOT_DUPLICACY
|
|
||||||
mkdir -p $TEST_DOT_DUPLICACY
|
|
||||||
|
|
||||||
# Create test repository
|
|
||||||
rm -rf $TEST_REPO
|
|
||||||
mkdir -p $TEST_REPO
|
|
||||||
pushd $TEST_REPO
|
|
||||||
echo "file1" > file1
|
|
||||||
mkdir dir1
|
|
||||||
echo "file2 >dir1/file2"
|
|
||||||
popd
|
|
||||||
}
|
|
||||||
|
|
||||||
function init_repo()
|
|
||||||
{
|
|
||||||
pushd $TEST_REPO
|
|
||||||
$DUPLICACY init integration-tests $TEST_STORAGE
|
|
||||||
$DUPLICACY backup
|
|
||||||
popd
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function init_repo_pref_dir()
|
|
||||||
{
|
|
||||||
pushd $TEST_REPO
|
|
||||||
$DUPLICACY init -pref-dir "$TEST_ZONE/TEST_DOT_DUPLICACY" integration-tests $TEST_STORAGE
|
|
||||||
$DUPLICACY backup
|
|
||||||
popd
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function backup()
|
|
||||||
{
|
|
||||||
pushd $TEST_REPO
|
|
||||||
NOW=`date`
|
|
||||||
echo $NOW > "file-$NOW"
|
|
||||||
$DUPLICACY backup
|
|
||||||
popd
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function restore()
|
. ./test_functions.sh
|
||||||
{
|
|
||||||
pushd $TEST_REPO
|
|
||||||
$DUPLICACY restore -r 2 -delete
|
|
||||||
popd
|
|
||||||
}
|
|
||||||
|
|
||||||
fixture
|
fixture
|
||||||
init_repo_pref_dir
|
init_repo_pref_dir
|
||||||
|
|
||||||
backup
|
backup
|
||||||
|
add_file file3
|
||||||
backup
|
backup
|
||||||
|
add_file file4
|
||||||
backup
|
backup
|
||||||
|
add_file file5
|
||||||
restore
|
restore
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
103
integration_tests/test_functions.sh
Normal file
103
integration_tests/test_functions.sh
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
get_abs_filename() {
|
||||||
|
# $1 : relative filename
|
||||||
|
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
|
||||||
|
}
|
||||||
|
|
||||||
|
pushd () {
|
||||||
|
command pushd "$@" > /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
popd () {
|
||||||
|
command popd "$@" > /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Functions used to create integration tests suite
|
||||||
|
|
||||||
|
DUPLICACY=$(get_abs_filename ../duplicacy_main)
|
||||||
|
|
||||||
|
# Base directory where test repositories will be created
|
||||||
|
TEST_ZONE=$HOME/DUPLICACY_TEST_ZONE
|
||||||
|
# Test Repository
|
||||||
|
TEST_REPO=$TEST_ZONE/TEST_REPO
|
||||||
|
|
||||||
|
# Storage for test ( For now, only local path storage is supported by test suite)
|
||||||
|
TEST_STORAGE=$TEST_ZONE/TEST_STORAGE
|
||||||
|
|
||||||
|
# Preference directory ( for testing the -pref-dir option)
|
||||||
|
DUPLICACY_PREF_DIR=$TEST_ZONE/TEST_DUPLICACY_PREF_DIR
|
||||||
|
|
||||||
|
# Scratch pad for testing restore
|
||||||
|
TEST_RESTORE_POINT=$TEST_ZONE/RESTORE_POINT
|
||||||
|
|
||||||
|
# Make sure $TEST_ZONE is in know state
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function fixture()
|
||||||
|
{
|
||||||
|
# clean TEST_RESTORE_POINT
|
||||||
|
rm -rf $TEST_RESTORE_POINT
|
||||||
|
mkdir -p $TEST_RESTORE_POINT
|
||||||
|
|
||||||
|
# clean TEST_STORAGE
|
||||||
|
rm -rf $TEST_STORAGE
|
||||||
|
mkdir -p $TEST_STORAGE
|
||||||
|
|
||||||
|
# clean TEST_DOT_DUPLICACY
|
||||||
|
rm -rf $DUPLICACY_PREF_DIR
|
||||||
|
mkdir -p $DUPLICACY_PREF_DIR
|
||||||
|
|
||||||
|
# Create test repository
|
||||||
|
rm -rf ${TEST_REPO}
|
||||||
|
mkdir -p ${TEST_REPO}
|
||||||
|
pushd ${TEST_REPO}
|
||||||
|
echo "file1" > file1
|
||||||
|
mkdir dir1
|
||||||
|
echo "file2" > dir1/file2
|
||||||
|
popd
|
||||||
|
}
|
||||||
|
|
||||||
|
function init_repo()
|
||||||
|
{
|
||||||
|
pushd ${TEST_REPO}
|
||||||
|
${DUPLICACY} init integration-tests $TEST_STORAGE
|
||||||
|
${DUPLICACY} backup
|
||||||
|
popd
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function init_repo_pref_dir()
|
||||||
|
{
|
||||||
|
pushd ${TEST_REPO}
|
||||||
|
${DUPLICACY} init -pref-dir "${DUPLICACY_PREF_DIR}" integration-tests ${TEST_STORAGE}
|
||||||
|
${DUPLICACY} backup
|
||||||
|
popd
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_file()
|
||||||
|
{
|
||||||
|
FILE_NAME=$1
|
||||||
|
pushd ${TEST_REPO}
|
||||||
|
echo ${FILE_NAME} > "${FILE_NAME}"
|
||||||
|
popd
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function backup()
|
||||||
|
{
|
||||||
|
pushd ${TEST_REPO}
|
||||||
|
${DUPLICACY} backup
|
||||||
|
popd
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function restore()
|
||||||
|
{
|
||||||
|
pushd ${TEST_REPO}
|
||||||
|
${DUPLICACY} restore -r 2 -delete
|
||||||
|
popd
|
||||||
|
}
|
||||||
@@ -229,7 +229,6 @@ func configRepository(context *cli.Context, init bool) {
|
|||||||
|
|
||||||
preferencePath = path.Join(repository, duplicacy.DUPLICACY_DIRECTORY) // TOKEEP
|
preferencePath = path.Join(repository, duplicacy.DUPLICACY_DIRECTORY) // TOKEEP
|
||||||
}
|
}
|
||||||
duplicacy.LOG_INFO("PREF_PATH", "-pref-dir value: --|%s|-- ", preferencePath)
|
|
||||||
|
|
||||||
|
|
||||||
if stat, _ := os.Stat(path.Join(preferencePath, "preferences")); stat != nil {
|
if stat, _ := os.Stat(path.Join(preferencePath, "preferences")); stat != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user