-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·78 lines (63 loc) · 2.08 KB
/
test.sh
File metadata and controls
executable file
·78 lines (63 loc) · 2.08 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
#!/bin/bash
set -eo pipefail
if [ -z "$TEST_PROXY_IMAGE" ]; then
TEST_PROXY_IMAGE="webhare/proxy:devbuild"
fi
DOCKERBASENAME="testproxy$RANDOM"
if ! docker run -l webharecitype=testdocker --rm -i --name "$DOCKERBASENAME" \
-e WEBHAREPROXY_CERTBOT_OPTIONS=--staging \
"$TEST_PROXY_IMAGE" \
/opt/container/launch-and-run-tests.sh ; then
echo 'TESTS FAILED!'
exit 1
fi
function cleanup()
{
docker rm --force $DOCKERBASENAME 2> /dev/null
docker rm --force "$DOCKERBASENAME-testscript" 2> /dev/null
}
trap cleanup EXIT
cleanup
if ! docker create -l webharecitype=testdocker --rm --name $DOCKERBASENAME -e WEBHAREPROXY_CERTBOT_OPTIONS=--staging -e WEBHAREPROXY_ADMINHOSTNAME=admin.example.com "$TEST_PROXY_IMAGE"; then
echo "Test failed"
exit 1
fi
docker start $DOCKERBASENAME
docker logs -f $DOCKERBASENAME &
PROXYIP=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $DOCKERBASENAME)
export PROXYIP
if [[ $OSTYPE == 'darwin'* ]]; then
# mac Docker Desktop can't directly route to docker containers, it sees the gateway ip addr as remote IP
EXPECTSEENCONNECTIP=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.Gateway}}{{end}}' $DOCKERBASENAME)
export EXPECTSEENCONNECTIP
fi
export PROXYKEY;
for _ in {1..60}; do
PROXYKEY=$(docker exec $DOCKERBASENAME /root/get-proxy-key.sh || true)
if [ -n "$PROXYKEY" ]; then
break
fi
sleep 1
done
if [ -z "$PROXYKEY" ]; then
echo "Could not retrieve proxy key"
fi
# Create a node docker to run the data
if ! docker create --rm -w /tests --name "$DOCKERBASENAME-testscript" \
-e PROXYIP="$PROXYIP" \
-e PROXYKEY="$PROXYKEY" \
node /tests/runtest.sh ; then
echo "Setup node runner failed"
exit 1
fi
TESTDIR=${BASH_SOURCE%/*}/tests/
# Copy the tests directory to the container, mounts are too impossible in a DIND scenario
if ! docker cp "$TESTDIR/" "$DOCKERBASENAME-testscript:/"; then
echo "Copy failed"
exit 1
fi
echo "** running testscript"
docker start "$DOCKERBASENAME-testscript"
docker logs -f $DOCKERBASENAME &
docker wait $DOCKERBASENAME-testscript
echo "** all tests succeeded"