-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·135 lines (116 loc) · 2.65 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·135 lines (116 loc) · 2.65 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
set -euo pipefail
export COMPOSE_PROJECT_NAME=hazebot_test
function usage() {
echo "Usage:"
echo " ./test.sh Run all tests."
echo " ./test.sh path.to.module Run tests for the given module."
echo ""
echo "Options:"
echo " -b --build Rebuild containers before running tests."
echo " -d --down Stop test containers."
echo " -h --help Display this message."
exit
}
build=false
down=false
module=''
is_first=true
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
usage
;;
-b|--build)
build=true
shift
;;
-d|--down)
down=true
shift
;;
*)
if $is_first; then
module=$key
shift
else
usage
fi
;;
esac
is_first=false
done
if $build && $down; then
echo "You cannot specify the -b and -d options together."
exit
fi
containers=`docker ps`
if echo $containers | grep hazebot_test &> /dev/null; then
running=true
else
running=false
fi
if $down; then
if $running; then
echo "Stopping containers"
docker-compose \
-f docker-compose.yml \
-f docker-compose.test.yml \
down
echo "All done"
else
echo "Containers are not running"
fi
exit
fi
if ! $running; then
cmd="docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d"
if $build; then
cmd+=" --build"
echo "Rebuilding images and volumes from scratch"
docker volume rm hazebot_test_pgdata &> /dev/null || true
fi
eval $cmd
printf "Waiting for server"
attempt_counter=0
max_attempts=20
until $(curl --output /dev/null --silent --head --fail http://localhost:8080); do
if [ ${attempt_counter} -eq ${max_attempts} ]; then
echo "[Fatal] Server failed to start in time.\n"
echo "Dumping logs:\n"
echo ""
docker-compose logs
exit 1
fi
printf '.'
attempt_counter=$(($attempt_counter+1))
sleep 1
done
echo ""
docker-compose \
-f docker-compose.yml \
-f docker-compose.test.yml \
exec \
-T \
-e SKIP_FORCE_REBUILD=1 \
app python3 -m unittest tests.test_sync.SyncTestCase.test_sync
fi
if [ "$module" ]; then
echo "Running tests for ${module}"
docker-compose \
-f docker-compose.yml \
-f docker-compose.test.yml \
exec \
-T \
app python3 -m unittest ${module}
else
echo "Running all tests"
docker-compose \
-f docker-compose.yml \
-f docker-compose.test.yml \
exec \
-T \
app python3 -m unittest discover
fi
exit $?