Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-mysqlbackend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-mysqlbackend
Commits
63926c8c
Commit
63926c8c
authored
5 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
TST: add a test that checks utils
parent
1eb3290c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_utils.sh
+101
-0
101 additions, 0 deletions
tests/test_utils.sh
with
101 additions
and
0 deletions
tests/test_utils.sh
0 → 100755
+
101
−
0
View file @
63926c8c
#!/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]'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment