Skip to content
Snippets Groups Projects
Verified Commit e58b96e6 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: example unit tests

parent fb0397d9
Branches
Tags
No related merge requests found
......@@ -32,14 +32,14 @@ function fail() {
UNITTEST_DATABASE=${UNITTEST_DATABASE-_caosdb_schema_unit_tests};
# options: [--drop-after] [--rebuild]
# options: [--fresh]
function runtests() {
DATABASE_NAME=$UNITTEST_DATABASE;
_setup_mytap
_install_unit_test_database
_install_unit_test_database $@
_execute_tests
_execute_tests || ( echo "[FAILURE]" && exit 1 )
# drop test database
#drop "$UNITTEST_DATABASE"
......@@ -47,26 +47,33 @@ function runtests() {
function _execute_tests () {
pushd tests
TESTS=$(find ./ -type f -iname "test*.sql");
TESTS="./test*.sql"
echo $TESTS
for tfile in "$TESTS" ; do
rm -f .TEST_RESULTS
for tfile in $TESTS ; do
echo "Running $tfile"
cat $tfile | $SQL --disable-pager --batch --raw --skip-column-names --unbuffered
echo "----- $tfile -----" >> .TEST_RESULTS
cat $tfile | $SQL --disable-pager --batch --raw --skip-column-names --unbuffered >> .TEST_RESULTS
done;
popd
cat tests/.TEST_RESULTS
grep -c -i "failed" tests/.TEST_RESULTS > /dev/null && return 1
return 0
}
# install/reset database for unit tests.
# options: [--fresh]
function _install_unit_test_database () {
if _db_exists "$SQL" "$DATABASE_NAME"; then
#drop "$DATABASE_NAME" ;
#sed "s/db_2_0/$UNITTEST_DATABASE/g" "$INSTALL_SQL_FILE" | $SQL
return 0 ;
if [[ "$1" == "--fresh" ]] ; then
drop "$DATABASE_NAME" ;
else
sed "s/db_2_0/$UNITTEST_DATABASE/g" "$INSTALL_SQL_FILE" | $SQL
return 0;
fi
fi
sed "s/db_2_0/$UNITTEST_DATABASE/g" "$INSTALL_SQL_FILE" | $SQL
# crate test user
grant
......@@ -214,7 +221,7 @@ SQL="$MYSQL_CMD $MYSQL_CONNECTION"
case $1 in
"drop") drop $2 ;;
"grant") grant $2 ;;
"test") runtests ;;
"test") shift ; runtests $@ ;;
"test-connection") test-connection ;;
"install_db") install_db ;;
"restore_db") restore_db $2 ;;
......
......@@ -58,4 +58,4 @@ drop-%:
.PHONY: test
test:
./make_db test
./make_db test --fresh
......@@ -5,7 +5,7 @@ BEGIN;
SELECT tap.plan(1);
-- Run the tests.
SELECT tap.fail( 'Hello, world!' );
SELECT tap.fail( 'Oh, no!' );
-- Finish the tests and clean up.
CALL tap.finish();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment