forked from asyrjasalo/RESTinstance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest
executable file
·99 lines (79 loc) · 2.84 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
#!/usr/bin/env bash
# https://github.com/asyrjasalo/restinstance
# https://hub.docker.com/r/asyrjasalo/restinstance
set -e
### globals ####################################################################
this_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
### settings ###################################################################
: ${BUILD_ARGS=""}
: ${BUILD_NAME="restinstance"}
: ${MB_PORT:=2525} # this is your host machine's port
: ${MR_ARGS:="--loglevel info"}
: ${MR_IMAGE_LABEL:="asyrjasalo/mounterest"}
: ${MR_IMAGE_TAG:="0.1.2"}
: ${MR_NETWORK:="testapi_default"}
: ${MR_PORT:=8273} # this is your host machine's port
: ${RF_ARGS:=""}
### helpers ####################################################################
exit_docker_not_installed() {
if ! which docker >/dev/null ; then
echo "### Please install Docker for the testenv:"
echo "https://www.docker.com/community-edition#/download"
exit 1
fi
}
cleanup_mounterest() {
docker rm --force mounterest 1>/dev/null
}
start_or_reset_mounterest() {
if [ "$MR_NETWORK" != "host" ]; then
docker network create --driver bridge $MR_NETWORK 2>/dev/null || true
fi
if docker exec mounterest true 2>/dev/null ; then
_reset_mounterest
else
docker run -d -t --name mounterest \
-e HOST_UID=$(id -u) -e HOST_GID=$(id -g) \
--network=$MR_NETWORK -p $MB_PORT:2525 -p $MR_PORT:8273 \
"$MR_IMAGE_LABEL:$MR_IMAGE_TAG" $MR_ARGS
echo "### Waiting for the API to start"
if ! _portable_timeout 60 bash -c _wait_mounterest_ready 2>/dev/null; then
echo "Error: API starting timeouted, exiting."
cleanup_mounterest
exit 124 # same as GNU coreutils `timeout` exit status
fi
echo "... ready for the tests"
fi
}
_reset_mounterest() {
docker run --rm -t -i --network=$MR_NETWORK \
alpine/httpie delete http://mounterest:$MR_PORT/state 1>/dev/null && \
echo "### Mounterest state cleaned" || true
}
_portable_timeout() {
perl -e 'alarm shift; exec @ARGV' "$@";
}
_wait_mounterest_ready() {
local done_msg="\[http:8273.*\] Open for business"
while ! docker logs mounterest | grep "$done_msg" >/dev/null; do
echo -n '.'
sleep 0.2
done
}
export -f _wait_mounterest_ready
### main #######################################################################
exit_docker_not_installed
# https://github.com/asyrjasalo/mounterest
trap "cleanup_mounterest &" SIGINT SIGTERM
start_or_reset_mounterest
if [ "$(uname -s)" == 'Darwin' ]; then
RF_ARGS="$RF_ARGS --variable PROXY_URL:host.docker.internal"
else
RF_ARGS="$RF_ARGS --variable PROXY_URL:localhost"
fi
# https://github.com/asyrjasalo/rfdocker
BUILD_NAME="$BUILD_NAME" \
BUILD_ARGS="$BUILD_ARGS" \
RUN_ARGS="--network=$MR_NETWORK -e MB_PORT=$MB_PORT -e MR_PORT=$MR_PORT" \
"$this_path/rfdocker" \
$RF_ARGS "${@:-tests}"