forked from fabric8-analytics/fabric8-analytics-data-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntests.sh
executable file
·113 lines (83 loc) · 2.5 KB
/
runtests.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
106
107
108
109
110
111
112
113
#!/usr/bin/bash -ex
COVERAGE_THRESHOLD=90
export TERM=xterm
TERM=${TERM:-xterm}
# set up terminal colors
NORMAL=$(tput sgr0)
RED=$(tput bold && tput setaf 1)
GREEN=$(tput bold && tput setaf 2)
YELLOW=$(tput bold && tput setaf 3)
DOCKER_CMD="docker-compose -f docker-compose-tests.yml"
gc() {
retval=$?
if [[ $retval -ne 0 ]]; then
docker ps -a
echo '============ dynamodb logs ============'
$DOCKER_CMD logs dynamodb || :
echo
echo
echo '============ gremlin logs ============'
$DOCKER_CMD logs gremlin-http || :
fi
$DOCKER_CMD down -v || :
exit $retval
}
trap gc EXIT SIGINT
# Run local instances: dynamodb, gremlin, gremlin-http, worker-ingestion, pgsql
function start_services {
echo "Start Gremlin HTTP and Ingestion Workers ..."
$DOCKER_CMD down
$DOCKER_CMD up -d gremlin-http
sleep 5
$DOCKER_CMD up -d worker-ingestion
}
function setup_virtualenv {
echo "Create Virtualenv for Python deps ..."
virtualenv --python /usr/bin/python2.7 env-test
if [ $? -ne 0 ]
then
printf "%sPython virtual environment can't be initialized%s" "${RED}" "${NORMAL}"
exit 1
fi
printf "%sPython virtual environment initialized%s\n" "${YELLOW}" "${NORMAL}"
source env-test/bin/activate
pip install -U pip
pip install -r requirements.txt
# Install profiling module
pip install pytest-profiling
# Install pytest-coverage module
pip install pytest-cov
}
function destroy_virtualenv {
echo "Remove Virtualenv ..."
rm -rf env-test/
}
echo JAVA_OPTIONS value: "$JAVA_OPTIONS"
start_services
setup_virtualenv
source env-test/bin/activate
PYTHONPATH=$(pwd)/src
export PYTHONPATH
export BAYESIAN_PGBOUNCER_SERVICE_HOST="localhost"
echo "*****************************************"
echo "*** Cyclomatic complexity measurement ***"
echo "*****************************************"
radon cc -s -a -i venv src
echo "*****************************************"
echo "*** Maintainability Index measurement ***"
echo "*****************************************"
radon mi -s -i venv src
echo "*****************************************"
echo "*** Unit tests ***"
echo "*****************************************"
echo "Check for sanity of the connections..."
if python sanitycheck.py
then
python populate_schema.py
py.test --cov=src/ --cov-report term-missing --cov-fail-under=$COVERAGE_THRESHOLD -vv -s test/
else
echo "Sanity checks failed"
fi
printf "%stests passed%s\n\n" "${GREEN}" "${NORMAL}"
deactivate
destroy_virtualenv