-
Notifications
You must be signed in to change notification settings - Fork 13
/
run_local_tests.sh
executable file
·105 lines (81 loc) · 2.69 KB
/
run_local_tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
set -e
echo "+ Running: cargo fmt"
cargo fmt --all -- --check
echo "+ Running: cargo clippy"
cargo clippy --all-targets --all-features -- -D warnings -A clippy::derive_partial_eq_without_eq
SIMPLE_KBS_DIR="$(dirname $0)/../db"
export KBS_DB_TYPE=mysql
export KBS_DB_HOST=127.0.0.1
export KBS_DB_USER=root
export KBS_DB_PW=root
#export KBS_DB=simple_kbs
export KBS_DB=simple_kbs_test
echo "+ Starting kbs-db-mysql DB server container..."
docker run --detach --rm \
-p 3306:3306 \
--name kbs-db \
--env MARIADB_ROOT_PASSWORD=$KBS_DB_PW \
mariadb:latest
sleep 5
echo -n "+ Trying to connect to mysql DB server..."
while true ; do
echo -n '.'
if mysql --silent -u${KBS_DB_USER} -p${KBS_DB_PW} -h ${KBS_DB_HOST} -e "SELECT 1;" > /dev/null 2>&1 ; then
echo " Success!"
break
fi
sleep 1
done
echo "+ Creating mysql database ${KBS_DB}"
mysql -u${KBS_DB_USER} -p${KBS_DB_PW} -h ${KBS_DB_HOST} -e "CREATE DATABASE ${KBS_DB};"
mysql -u${KBS_DB_USER} -p${KBS_DB_PW} -h ${KBS_DB_HOST} ${KBS_DB} < "${SIMPLE_KBS_DIR}/db-mysql.sql"
echo "+ Running: cargo test for mysql using mariadb:latest"
cargo test
echo "+ Stopping kbs-db-mysql DB server container..."
docker stop kbs-db
export KBS_DB_USER=postgres
export KBS_DB_PW=root
#export KBS_DB=simple_kbs
export KBS_DB_TYPE=postgres
export POSTGRES_PASSWORD=$KBS_DB_PW \
export POSTGRES_USER=$KBS_DB_USER \
export PGPASSWORD=$KBS_DB_PW \
echo "+ Starting kbs-db-postgres DB server container..."
docker run --detach --rm \
-p 5432:5432 \
--name kbs-db-postgres \
--env POSTGRES_PASSWORD=$KBS_DB_PW \
--env POSTGRES_USER=$KBS_DB_USER \
--env PGPASSWORD=$KBS_DB_PW \
postgres:latest
sleep 5
echo -n "+ Trying to connect to postgres DB server..."
while true ; do
echo -n '.'
if psql -U ${KBS_DB_USER} -h ${KBS_DB_HOST} -c "SELECT 1;" > /dev/null 2>&1 ; then
echo " Success!"
break
fi
sleep 1
done
echo "+ Creating postgres database ${KBS_DB}"
psql -U ${KBS_DB_USER} -h ${KBS_DB_HOST} -c "CREATE DATABASE ${KBS_DB};"
psql -U ${KBS_DB_USER} -h ${KBS_DB_HOST} ${KBS_DB} < "${SIMPLE_KBS_DIR}/db-postgres.sql"
echo "+ Running: cargo test for kbs-db-postgres"
cargo test
echo "+ Stopping kbs-db-postgres DB server container..."
docker stop kbs-db-postgres
export KBS_DB_HOST=127.0.0.1
export KBS_DB_USER=dummy
export KBS_DB_PW=dummy
export KBS_DB=simple-kbs-test.sqlite
export KBS_DB_TYPE=sqlite
echo "+ Creating sqlite database ${KBS_DB}"
rm -f ${KBS_DB} ${KBS_DB}-*
sqlite3 ${KBS_DB} < "${SIMPLE_KBS_DIR}/db-sqlite.sql"
echo "+ Running: cargo test for sqlite"
cargo test
echo "+ Erasing sqlite database ${KBS_DB}"
rm -f ${KBS_DB} ${KBS_DB}-*
echo "+ Done"