From 7a403c7f93ebaddcfd9f38c7d3ca1ac1014b23cf Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 31 Jan 2016 18:03:49 +0100 Subject: [PATCH] tests: Add imag-store tests --- imag-store/tests/001-create_test.sh | 49 +++++++++++++++++++++++ imag-store/tests/utils.sh | 61 +++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 imag-store/tests/001-create_test.sh create mode 100644 imag-store/tests/utils.sh diff --git a/imag-store/tests/001-create_test.sh b/imag-store/tests/001-create_test.sh new file mode 100644 index 00000000..b7d641b6 --- /dev/null +++ b/imag-store/tests/001-create_test.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +source $(dirname ${BASH_SOURCE[0]})/utils.sh + +test_call() { + imag-store create -p /test-call + if [[ ! $? -eq 0 ]]; then + err "Return value should be zero, was non-zero" + return 1; + fi +} + +test_mkstore() { + imag-store create -p /test-mkstore || { err "Calling imag failed"; return 1; } + if [[ -d ${STORE} ]]; then + out "Store exists." + else + err "No store created" + return 1 + fi +} + +test_std_header() { + local expected=$(cat <> $*${COLOR_OFF}" +} + +err() { + echo -e "${RED}!! $*${COLOR_OFF}" +} + +imag-store() { + local searchdir=$(dirname ${BASH_SOURCE[0]})/../target/debug/ + [[ -d $searchdir ]] || { err "FATAL: No directory $searchdir"; exit 1; } + local bin=$(find $searchdir -iname imag-store -type f -executable) + local flags="--debug --rtp $RUNTIME" + out "Calling '$bin $flags $*'" + $bin $flags $* +} + +reset_store() { + rm -r "${STORE}" +} + +call_test() { + out "-- TESTING: '$1' --" + $1 + result=$? + if [[ -z "$DONT_RESET_STORE" ]]; then + out "Reseting store" + reset_store + out "Store reset done" + fi + [[ $result -eq 0 ]] || { err "-- FAILED: '$1'. Exiting."; exit 1; } + success "-- SUCCESS: '$1' --" +} + +invoke_tests() { + out "Invoking tests." + if [[ ! -z "$INVOKE_TEST" ]]; then + out "Invoking only $INVOKE_TEST" + call_test "$INVOKE_TEST" + else + out "Invoking $*" + for t in $*; do + call_test "$t" + done + fi +} +