From d60828fc157f0b9d797964de088cd8f02e0a2b95 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Wed, 6 Aug 2014 20:09:51 +0200 Subject: [PATCH] Add dirdiff to tests --- cmd/khepri/cmd_restore.go | 12 ++++++------ test/run.sh | 22 +++++++++++----------- test/test-backup.sh | 8 +++++--- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/cmd/khepri/cmd_restore.go b/cmd/khepri/cmd_restore.go index ff647776b..0f90ab470 100644 --- a/cmd/khepri/cmd_restore.go +++ b/cmd/khepri/cmd_restore.go @@ -68,7 +68,7 @@ func restore_dir(repo *khepri.Repository, id khepri.ID, target string) error { nodepath := path.Join(target, name) if node.Mode.IsDir() { - err = os.MkdirAll(nodepath, 0700) + err = os.Mkdir(nodepath, 0700) if err != nil { return err } @@ -83,16 +83,16 @@ func restore_dir(repo *khepri.Repository, id khepri.ID, target string) error { return err } + err = restore_dir(repo, node.Content, nodepath) + if err != nil { + return err + } + err = os.Chtimes(nodepath, node.AccessTime, node.ModTime) if err != nil { return err } - err = restore_dir(repo, node.Content, nodepath) - - if err != nil { - return err - } } else { err = restore_file(repo, node, nodepath) if err != nil { diff --git a/test/run.sh b/test/run.sh index 77ca7d75b..e4d197b4d 100755 --- a/test/run.sh +++ b/test/run.sh @@ -3,13 +3,10 @@ set -e export khepri="${1:-khepri}"; shift +export dirdiff="${1:-dirdiff}"; shift export dir=$(dirname "$0") export fake_data_file="${dir}/fake-data.tar.gz" -k() { - "${khepri}" "$@" -} - prepare() { export BASE="$(mktemp --tmpdir --directory khepri-testsuite-XXXXXX)" export KHEPRI_REPOSITORY="${BASE}/khepri-backup" @@ -33,6 +30,14 @@ cleanup() { unset KHEPRI_REPOSITORY } +khepri() { + "${khepri}" "$@" +} + +dirdiff() { + "${dirdiff}" "$@" +} + msg() { printf "%s: %s\n" "$(basename "$0" .sh)" "$*" } @@ -64,7 +69,7 @@ run() { fi } -export -f k prepare cleanup msg debug pass err fail run +export -f khepri dirdiff prepare cleanup msg debug pass err fail run if [ ! -x "$khepri" ]; then fail khepri binary not found! @@ -81,10 +86,5 @@ echo "testfiles: $testfiles" for testfile in "$testfiles"; do current=$(basename "${testfile}" .sh) - bash "${testfile}" - if [ "$?" != "0" ]; then - err "${current} failed!" - else - pass "${current} pass" - fi + bash "${testfile}" && pass "${current} pass" || err "${current} failed!" done diff --git a/test/test-backup.sh b/test/test-backup.sh index 72d4a29b4..510f5764e 100755 --- a/test/test-backup.sh +++ b/test/test-backup.sh @@ -1,5 +1,7 @@ +set -e + prepare -run k backup "${BASE}/fake-data" -run k restore "$(k list ref)" "${BASE}/fake-data-restore" -diff -aur "${BASE}/fake-data" "${BASE}/fake-data-restore" +run khepri backup "${BASE}/fake-data" +run khepri restore "$(khepri list ref)" "${BASE}/fake-data-restore" +dirdiff "${BASE}/fake-data" "${BASE}/fake-data-restore" cleanup