Skip to content
Snippets Groups Projects
Commit 63926c8c authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

TST: add a test that checks utils

parent 1eb3290c
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2020 Henrik tom Wörden <h.tomwoerden@indiscale.com>
# Copyright (C) 2020 IndiScale <info@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Dump a database with all procedures, permissions, structure and data
set -e
if [ -z "$UTILSPATH" ]; then
UTILSPATH="$(realpath $(dirname $(dirname $0)))/utils"
export UTILSPATH
fi
MAX_ENTITIES=500
# Load settings from .config and defaults #####################################
. $UTILSPATH/load_settings.sh
# load useful functions #######################################################
. $UTILSPATH/helpers.sh
# Test mysql connection
echo -n 'testing connection... '
$UTILSPATH/make_db test-connection > /dev/null
echo '[Ok]'
echo -n 'size of database... '
# check size of database
num=$(mysql_execute "SELECT COUNT(*) FROM entities" | sed 's/COUNT(\*)//')
if [ $num -gt $MAX_ENTITIES ]; then
echo "There are more than $MAX_ENTITIES entities..."\
"Do not run this on a production instance!"
exit 1
elif [ $num -lt 5 ]; then
echo "There are less than 5 entities..."\
"Please use this with a database with some example content!"
exit 1
fi
echo '[Ok]'
###############################################################################
# Below we create a dump, then run tests, and create a dump again. Afterwards
# the dumps are checked if they are not empty and whether they differ.
# This should make sure that tests interfere somehow with the real database.
# This also provides a very basic test that sql dumps work.
###############################################################################
# creating a dump of current db
backupdir=$(realpath 'tmp_backup')
if [ -e "$backupdir" ]; then
echo "Temporary directory $backupdir already exists. Please remove it"
exit 1
fi
echo -n 'creating initial dump... '
BACKUPDIR=$backupdir $UTILSPATH/backup.sh > /dev/null
echo '[Ok]'
# run normal tests
echo -n 'running sql tests... '
$UTILSPATH/make_db test > /dev/null
echo '[Ok]'
echo -n 'creating secondary dump... '
BACKUPDIR=$backupdir $UTILSPATH/backup.sh > /dev/null
echo '[Ok]'
#compare dumps
pushd $backupdir > /dev/null
echo -n 'checking dumps... '
for filename in "./*.sql"; do
# assures entities table is created, i.e. there is content
cat $filename | grep "CREATE TABLE .entities." > /dev/null
# remove time stamp
sed -i '/Dump completed on/d' $filename
done
echo '[Ok]'
echo -n 'comparing dumps... '
if [ ! -z "$(diff *)" ]; then
echo $(diff *)
echo "The second dump differs from the first one. This possibly means that tests changed the real database."
exit 1
fi
echo '[Ok]'
popd > /dev/null
rm -r $backupdir
echo '[Completed]'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment