-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
test
executable file
·123 lines (105 loc) · 2.5 KB
/
test
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
#!/bin/bash
COMPOSE="docker-compose"
teardown()
{
rm -rf .tox
$COMPOSE -f fig-test-env.yml stop
}
wait_for_env()
{
local url=$1
echo "Checking for $url availability"
for ((i=0;i<300;i++))
do
if [[ "$(curl -s ${url}/ping)" = "pong" ]]; then
if [[ "$i" = "1" ]]; then
echo "Environment at ${url} did not come up"
fi
break
else
if [[ "$i" -eq "299" ]]; then
echo "Env did not start"
exit 1
fi
sleep 1
fi
done
}
get_port()
{
local id=$1
echo $(docker inspect -f '{{ (index (index .NetworkSettings.Ports "8080/tcp") 0).HostPort }}' \
$id)
}
get_url()
{
local port=$1
echo "http://${DOCKER_IP}:${port}"
}
setup()
{
local server=$1
local url=$2
ID=$(fig_get_id $server)
PORT=$(get_port $ID)
export $url=$(get_url $PORT)
eval url=\$$url
wait_for_env $url
}
if [ -x /usr/local/bin/wrapdocker ]; then
wrapdocker > /tmp/docker.log 2>&1
WRAPPED="true"
fi
if [ "$(uname -s)" == "Linux" ]; then
export DOCKER_IP=$(ip addr show eth0 |grep inet|grep -v inet6|cut -d' ' -f6|cut -d'/' -f1)
fi
if [ $(command -v boot2docker) ]; then
export DOCKER_IP=$(boot2docker ip)
fi
if [ $(command -v docker-machine) ]; then
machine=$(docker-machine active)
export DOCKER_IP=$(docker-machine ip ${machine})
fi
cd $(dirname $0)/..
pushd ./server > /dev/null
TAG=dev ./build-image.sh
popd > /dev/null
# Just doing server for now.
pushd ./tests/server > /dev/null
export CATTLE_DB_CATTLE_MYSQL_HOST=$DOCKER_IP
$COMPOSE -f fig-test-env.yml build
$COMPOSE -f fig-test-env.yml up -d
fig_get_id()
{
echo $($COMPOSE -f fig-test-env.yml ps -q $1)
}
trap teardown EXIT
for db_case in "h2dbcattle" "mysqllinkscattle" "mysqlmanualcattle" "localmysqlcattle"; do
echo $db_case
case $db_case in
h2dbcattle)
setup $db_case "CATTLE_H2DB_TEST_URL"
;;
mysqllinkscattle)
setup $db_case "CATTLE_MYSQL_LINK_TEST_URL"
;;
localmysqlcattle)
setup $db_case "CATTLE_MYSQL_LOCAL_TEST_URL"
;;
mysqlmanualcattle)
setup $db_case "CATTLE_MYSQL_MANUAL_TEST_URL"
;;
*)
echo "No tests setup for $db_case"
;;
esac
done
popd > /dev/null
if [[ "$WRAPPED" == "true" ]]; then
cp -r ./tests /scratch
pushd /scratch > /dev/null
fi
pushd tests/server >/dev/null
rm -rf .tox
printenv
tox