forked from RedHatInsights/vulnerability-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.sh
executable file
·79 lines (68 loc) · 2.65 KB
/
run_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
#!/bin/bash
rc=0
# Check database Dockerfile consistency
dockerfile=database/Dockerfile
sed \
-e "s/docker.io\/centos\/postgresql-12-centos7/registry.redhat.io\/rhscl\/postgresql-12-rhel7/" \
"$dockerfile".centos | diff "$dockerfile" -
diff_rc=$?
if [ $diff_rc -gt 0 ]; then
echo "$dockerfile and $dockerfile.centos are too different!"
else
echo "$dockerfile and $dockerfile.centos are OK"
fi
rc=$(($rc+$diff_rc))
# Check for python deps updates.
CYAN='\033[0;36m'
NO_COLOR='\033[0m'
echo -e "${CYAN}Dependency updates checking...${NO_COLOR}"
pipenv run pip freeze > /tmp/req.txt
pipenv run pur -r /tmp/req.txt -o /dev/null | grep "Updated" | sed -e "s/Updated/You can update:/g"
echo -e "${CYAN}------------------------------${NO_COLOR}"
# Make sure there is __init__.py in each dir containing python scripts
find . -name '*.py' | xargs dirname | sort | uniq | xargs -I {} bash -c "test -f {}/__init__.py || ( echo {} directory does not have __init__.py! && false )"
rc=$(($rc+$?))
# Simple test to compare variables used in code and specified in conf/*.env files, allows to set ignored variables
not_configurable="CW_AWS_ACCESS_KEY_ID\|CW_AWS_SECRET_ACCESS_KEY"
not_in_code="API_URLS"
configurable_variables=$(cat conf/*.env | grep -o "^.*=" | sed 's/.$//g' | sort -u | grep -v "$not_in_code")
code_variables=$(find . -name '*.py' -not -path './scripts/*' -not -path './tests/*' -not -path './database/upgrade/*' -exec grep -o "os\.getenv.*\|os\.environ\.get.*" {} \; | awk -F"['\"]" '{print $2}' | sort -u | grep -v "$not_configurable")
diff <(echo "$configurable_variables") <(echo "$code_variables")
diff_rc=$?
if [ $diff_rc -gt 0 ]; then
echo "Some variables in code or conf/*.env are missing!"
else
echo "Variables in code and conf/*.env are OK"
fi
rc=$(($rc+$diff_rc))
echo ""
# Are there duplicated configuration variables?
duplicates=$(cat conf/*.env | grep -o "^.*=.*" | sort | uniq -d)
duplicate_cnt=0
for dup in $duplicates
do
echo "$dup"
duplicate_cnt=$(($duplicate_cnt+1))
done
if [ $duplicate_cnt -gt 0 ]; then
echo "Duplicated variables were found!"
rc=$(($rc+1))
else
echo "Variables are unique."
fi
echo ""
# Run pylint
for testdir in advisor_listener common database listener evaluator manager taskomatic tests vmaas_sync metrics
do
echo "Running pylint on module: $testdir"
pipenv run pylint --rcfile=./pylintrc $testdir --output-format=colorized
rc=$(($rc+$?))
echo "Running flake8 on module: $testdir"
pipenv run flake8 --append-config=setup.cfg $testdir
rc=$(($rc+$?))
done
# Run unit tests
echo "Running unit tests:"
pipenv run pytest -vvv --cov-report term --cov --color=yes --durations=1
rc=$(($rc+$?))
exit $rc