-
Notifications
You must be signed in to change notification settings - Fork 46
/
run-docker-tests.sh
executable file
·111 lines (97 loc) · 3.25 KB
/
run-docker-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
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
#!/usr/bin/env bash
########################################################################################################################
# This script executed on host machine.
# You can optionally pass parameters:
# -p : version of PHP without dots. Currently supported 56, 70, 71, 72, 73, 74
# -m : version of MongoDB without dots. Currently supported 24, 26, 30, 32, 33, 34, 36, 40, 41
# -t : path to concrete test file, relative to ./tests/
# For example:
# $ ./run-docker-tests.sh -p 56 -m 32 -t CursorTest.php
#
# Actual list of supported versions may be found in docker's compose (./docker/compose.yml)
########################################################################################################################
PROJECT_DIR=$(dirname $(readlink -f $0))
# init php version
phpVersions=()
phpVersionsCount=0
# init mongo version
mongoVersions=()
mongoVersionsCount=0
# test pattern
testPath=""
testFilter=""
# docker command pattern
dockerRunTestCommand="bash /phpmongo/docker/php/run-tests.sh"
# get php and mongo versions from input arguments
while [[ $# -gt 1 ]]
do
key="$1"
value="$2"
case $key in
-p|--php)
phpVersions[$phpVersionsCount]=${value}
phpVersionsCount=$(( ${phpVersionsCount} + 1 ))
shift
;;
-m|--mongo)
mongoVersions[$mongoVersionsCount]=$value
mongoVersionsCount=$(( ${mongoVersionsCount} + 1 ))
shift
;;
-t|--test)
testPath=${value}
shift
;;
-f|--filter)
testFilter=${value}
shift
;;
*)
;;
esac
shift
done
# if php versions not passed, fill default
if [[ -z $phpVersions ]]
then
phpVersions=("56" "70" "71" "72" "73" "74")
fi
# if versions not passed, fill default
if [[ -z $mongoVersions ]]
then
mongoVersions=("24" "26" "30" "32" "33" "34" "36" "40" "41")
fi
# add path to test file
if [[ ! -z $testPath ]]
then
dockerRunTestCommand="${dockerRunTestCommand} -t ${testPath}"
fi
# add path to test file
if [[ ! -z $testFilter ]]
then
dockerRunTestCommand="${dockerRunTestCommand} -f ${testFilter}"
fi
# start bunch of tests
for phpVersion in ${phpVersions[@]}; do
docker-compose -f ${PROJECT_DIR}/docker/compose.yml up -d php${phpVersion}
# wait for container initialised
# see docker/php/init.sh for details
SHARE_DIR=${PROJECT_DIR}/docker/share/${phpVersion:0:1}.${phpVersion:1:1}
echo "Waiting for docker container initialisation ..."
while [[ ! -d ${SHARE_DIR} ]]; do
echo -n .
sleep 1
done
for mongoVersion in ${mongoVersions[@]}; do
echo -e "\n\033[1;37m\033[42mTest MongoDB ${mongoVersion} on PHP ${phpVersion}\033[0m\n"
docker-compose -f ${PROJECT_DIR}/docker/compose.yml up -d mongodb${mongoVersion}
until docker exec -it phpmongo_mongo${mongoVersion} mongo --eval "print(\"waited for connection\")" > /dev/null
do
echo -n .
sleep 1
done
docker exec -it phpmongo_php${phpVersion} $dockerRunTestCommand -m $mongoVersion
docker-compose -f ${PROJECT_DIR}/docker/compose.yml stop mongodb${mongoVersion}
done
docker-compose -f ${PROJECT_DIR}/docker/compose.yml stop php${phpVersion}
done