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
e58b96e6
Verified
Commit
e58b96e6
authored
5 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
WIP: example unit tests
parent
fb0397d9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
make_db
+20
-13
20 additions, 13 deletions
make_db
makefile
+1
-1
1 addition, 1 deletion
makefile
tests/test_failure.sql
+1
-1
1 addition, 1 deletion
tests/test_failure.sql
with
22 additions
and
15 deletions
make_db
+
20
−
13
View file @
e58b96e6
...
@@ -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
$TES
TS
rm
-f
.TEST_RESUL
TS
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
;;
...
...
This diff is collapsed.
Click to expand it.
makefile
+
1
−
1
View file @
e58b96e6
...
@@ -58,4 +58,4 @@ drop-%:
...
@@ -58,4 +58,4 @@ drop-%:
.PHONY
:
test
.PHONY
:
test
test
:
test
:
./make_db
test
./make_db
test
--fresh
This diff is collapsed.
Click to expand it.
tests/test_failure.sql
+
1
−
1
View file @
e58b96e6
...
@@ -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
();
...
...
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