forked from amiv-eth/amivapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_with_db.sh
More file actions
executable file
·44 lines (35 loc) · 1.45 KB
/
test_with_db.sh
File metadata and controls
executable file
·44 lines (35 loc) · 1.45 KB
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
#!/bin/bash -i
# Use alternate port for less interaction with existing mongo servers.
MONGO_PORT=27099
# Create a mongodb server.
mkdir /tmp/test_db
mongod --dbpath /tmp/test_db --port $MONGO_PORT >/tmp/mongo.log &
# Now is a good time to run flake8, so it can run during the mongo startup.
flake8 /api/amivapi || { echo 'Please fix the flake8 errors :)' >&2; exit 1; }
echo "Waiting for mongodb to start..."
grep -q "waiting for connections on port" <(tail -f /tmp/mongo.log)
# Create DB user.
mongo test_amivapi --port=$MONGO_PORT --eval \
'db.createUser({user:"test_user",pwd:"test_pw",roles:["readWrite"]})'
# Create amivapi config.
echo > /tmp/amivconfig.py 'MONGO_HOST = "localhost"'
echo >>/tmp/amivconfig.py "MONGO_PORT = $MONGO_PORT"
# Start tests. Use amivapi/tests as default argument
if [ $# -eq 0 ]; then
args="amivapi/tests"
else
args=$@
fi
AMIVAPI_CONFIG=/tmp/amivconfig.py pytest $args &
PYTEST_PID=$!
# When running in docker, Ctrl-C will send a SIGINT to the shell running this
# script (PID 1), not the pytest subprocess. Bash does not handle signals while
# a process is running in the foreground, so we have to run the tests in the
# background, handle SIGINT here and forward it to the pytest process to make
# Ctrl-C work.
trap 'kill -INT $PYTEST_PID' INT
wait $PYTEST_PID
# This is needed to give enough time for output to be sent to the terminal.
# Without it the docker container is killed before the test results are
# flushed.
sleep 3