tests: Add imag-store tests

This commit is contained in:
Matthias Beyer 2016-01-31 18:03:49 +01:00
parent 10fa3e3daf
commit 7a403c7f93
2 changed files with 110 additions and 0 deletions

View file

@ -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 <<EOS
---
[imag]
links = []
version = "0.1.0"
---
EOS
)
imag-store create -p /test-std-header
local result=$(cat ${STORE}/test-std-header)
if [[ "$expected" == "$result" ]]; then
out "Expected store entry == result"
else
err "${STORE}/test differs from expected"
return 1
fi
}
invoke_tests \
test_call \
test_mkstore \
test_std_header \
test_std_header_plus_custom

61
imag-store/tests/utils.sh Normal file
View file

@ -0,0 +1,61 @@
#!/usr/bin/env bash
COLOR_OFF='\e[0m' # Text Reset
RED='\e[0;31m' # Red
YELLOW='\e[0;33m' # Yellow
GREEN='\e[0;32m' # Green
RUNTIME="/tmp"
STORE="${RUNTIME}/store"
out() {
echo -e "${YELLOW}:: $*${COLOR_OFF}"
}
success() {
echo -e "${GREEN}>> $*${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
}