From 1361b553ac561bf7435c7405882eda53321e9457 Mon Sep 17 00:00:00 2001 From: Etienne Charlier Date: Thu, 8 Jun 2017 22:21:57 +0200 Subject: [PATCH] Remove logging statement; refactor test scripts --- integration_tests/test.sh | 73 ++------------------ integration_tests/test_functions.sh | 103 ++++++++++++++++++++++++++++ main/duplicacy_main.go | 1 - 3 files changed, 108 insertions(+), 69 deletions(-) create mode 100644 integration_tests/test_functions.sh diff --git a/integration_tests/test.sh b/integration_tests/test.sh index de945b2..4cfee56 100755 --- a/integration_tests/test.sh +++ b/integration_tests/test.sh @@ -1,80 +1,17 @@ #!/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() -{ - pushd $TEST_REPO - $DUPLICACY restore -r 2 -delete - popd -} +. ./test_functions.sh fixture init_repo_pref_dir backup +add_file file3 backup +add_file file4 backup +add_file file5 restore + diff --git a/integration_tests/test_functions.sh b/integration_tests/test_functions.sh new file mode 100644 index 0000000..0739411 --- /dev/null +++ b/integration_tests/test_functions.sh @@ -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 +} \ No newline at end of file diff --git a/main/duplicacy_main.go b/main/duplicacy_main.go index 8b005b8..fb7f430 100644 --- a/main/duplicacy_main.go +++ b/main/duplicacy_main.go @@ -229,7 +229,6 @@ func configRepository(context *cli.Context, init bool) { 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 {