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