This repository has been archived by the owner on Jul 6, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest.sh
executable file
·95 lines (81 loc) · 2.24 KB
/
test.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
# !/bin/bash
HOST_OSTYPE=$(uname)
UID=1001
GID=1001
if [ "$HOST_OSTYPE" == "Linux"]; then
UID=$(id -u)
GID=$(id -g)
fi
[ -n "${SUITE}" ] || SUITE=$1 && shift 1
if [ -z "$SUITE" ];
then
echo "Test suite argument is missing. Please choose canary or stable"
usage
exit 1
fi
COMPOSE_FILE="docker-compose.yml"
if [ "$SUITE" == "canary" ]; then
COMPOSE_FILE="docker-compose.canary.yml"
fi
function setup {
echo "# Copying the sample configuration files"
cp docker/api-gateway.env.sample docker/api-gateway.env
cp docker/auth.env.sample docker/auth.env
cp docker/syncing-server-js.env.sample docker/syncing-server-js.env
cp docker/mock-event-publisher.env.sample docker/mock-event-publisher.env
cp docker/files.env.sample docker/files.env
echo "# Installing project dependecies (Host Machine)"
yarn install --immutable
yarn build
}
function cleanup {
local output_logs=$1
if [ $output_logs == 1 ]
then
echo "Outputing last 100 lines of logs"
docker compose -f $COMPOSE_FILE logs --tail=100
fi
echo "# Killing all containers"
docker compose -f $COMPOSE_FILE kill
echo "# Removing all containers"
docker compose -f $COMPOSE_FILE rm -vf
}
function startContainers {
echo "# Running Test Suite in $SUITE mode. Using $COMPOSE_FILE compose file."
echo "# Pulling latest versions"
docker compose -f $COMPOSE_FILE pull
echo "# Building Docker images"
docker compose -f $COMPOSE_FILE build \
--build-arg UID=$UID \
--build-arg GID=$GID
echo "# Starting all containers for Test Suite"
docker compose -f $COMPOSE_FILE up -d
}
function waitForServices {
attempt=0
while [ $attempt -le 90 ]; do
attempt=$(( $attempt + 1 ))
echo "# Waiting for all services to be up (attempt: $attempt) ..."
result=$(docker compose -f $COMPOSE_FILE logs api-gateway)
if grep -q 'Server started on port' <<< $result ; then
sleep 2 # for warmup
echo "# All services are up!"
break
fi
sleep 2
done
}
setup
cleanup 0
startContainers
waitForServices
echo "# Starting test suite ..."
npx mocha-headless-chrome --timeout 1200000 -f http://localhost:9001/packages/snjs/mocha/test.html
test_result=$?
cleanup $test_result
if [ $test_result == 0 ]
then
exit 0
else
exit 1
fi