forked from fabric8-analytics/fabric8-gemini-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests.sh
executable file
·122 lines (95 loc) · 3.28 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
114
115
116
117
118
119
120
121
122
#!/usr/bin/bash -ex
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
pushd "${SCRIPT_DIR}/.." > /dev/null
COVERAGE_THRESHOLD=80
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)
printf "%sShutting down docker-compose ..." "${NORMAL}"
check_python_version() {
python3 tools/check_python_version.py 3 6
}
gc() {
retval=$?
docker-compose -f docker-compose.yml down -v || :
exit $retval
}
trap gc EXIT SIGINT
check_python_version
# Enter local-setup/ directory
# Run local instances for: dynamodb, gremlin-websocket, gremlin-http
function start_gemini_service {
#pushd local-setup/
echo "Invoke Docker Compose services"
docker-compose -f docker-compose.yml up --force-recreate -d
#popd
}
start_gemini_service
PYTHONPATH=$(pwd)/src
export PYTHONPATH
printf "%sCreate Virtualenv for Python deps ..." "${NORMAL}"
function prepare_venv() {
VIRTUALENV=$(which virtualenv)
if [ $? -eq 1 ]
then
# python36 which is in CentOS does not have virtualenv binary
VIRTUALENV=$(which virtualenv-3)
fi
${VIRTUALENV} -p python3 venv && source venv/bin/activate
if [ $? -ne 0 ]
then
printf "%sPython virtual environment can't be initialized%s" "${RED}" "${NORMAL}"
exit 1
fi
}
prepare_venv
# now we are surely in the Python virtual environment
pip3 install -r tests/requirements.txt
export DEPLOYMENT_PREFIX="${USER}"
export WORKER_ADMINISTRATION_REGION=api
export SENTRY_DSN=''
export PYTHONDONTWRITEBYTECODE=1
export POSTGRESQL_USER='coreapi'
export POSTGRESQL_PASSWORD='coreapipostgres'
export POSTGRESQL_DATABASE='coreapi'
export PGBOUNCER_SERVICE_HOST='0.0.0.0'
export DISABLE_AUTHENTICATION=1
export BAYESIAN_JWT_AUDIENCE='a,b'
export BAYESIAN_FETCH_PUBLIC_KEY='test'
export FABRIC8_AUTH_URL='https://auth.openshift.io'
export REPORT_BUCKET_NAME="not-set"
export AWS_S3_ACCESS_KEY_ID="not-set"
export AWS_S3_SECRET_ACCESS_KEY="not-set"
export AWS_S3_REGION="not-set"
psql_conn_str="postgres://${POSTGRESQL_USER}:${POSTGRESQL_PASSWORD}@${PGBOUNCER_SERVICE_HOST}:${5432}/${POSTGRESQL_DATABASE}"
for i in {1..60}
do
printf "%sWaiting for Postgres: %s/60 %s\n" "${YELLOW}" "${i}" "${NORMAL}"
rc=$(psql -q "${psql_conn_str}" -c ''; echo $?)
[ "$rc" == "0" ] && break
sleep 1
done
echo "*****************************************"
echo "*** Cyclomatic complexity measurement ***"
echo "*****************************************"
radon cc -s -a -i venv .
printf "%sCyclomatic complexity measurement passed%s\n\n" "${GREEN}" "${NORMAL}"
echo "*****************************************"
echo "*** Maintainability Index measurement ***"
echo "*****************************************"
radon mi -s -i venv .
printf "%sMaintainability Index measurement passed%s\n\n" "${GREEN}" "${NORMAL}"
echo "*****************************************"
echo "*** Unit tests ***"
echo "*****************************************"
python3 "$(which pytest)" --cov=src/ --cov-report term-missing --cov-fail-under=$COVERAGE_THRESHOLD -vv tests/
printf "%stests passed%s\n\n" "${GREEN}" "${NORMAL}"
codecov --token=357eac20-296a-434e-abca-0fdd7b3ccbdb
# deactivate virtual env before deleting it
deactivate
rm -rf venv/
popd > /dev/null