-
Notifications
You must be signed in to change notification settings - Fork 19
/
test.sh
executable file
·68 lines (55 loc) · 1.61 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
#!/usr/bin/env bash
set -exo pipefail
# Usage: ./test.sh <make target>
# Execute a makefile target inside a Docker environment
MAKE_TARGET="test-coverage-all-codeclimate"
if [[ -n "$1" ]]; then
MAKE_TARGET="$1"
fi
NO_CLEANUP=0
if [[ "$2" == "--no-cleanup" ]]; then
NO_CLEANUP=1
fi
cleanup() {
echo "Starting cleanup"
container_name="$1"
docker stop commander-int-ssh-server || true
docker rm commander-int-ssh-server || true
docker network rm commander_test
}
start_ssh_conatiner() {
local ssh_container_name="commander-int-ssh-server"
if [[ ! $(docker ps | grep $ssh_container_name) ]]; then
echo "Starting SSH server"
docker run -d \
--rm \
--ip=172.28.0.2 \
--network commander_test \
--name "$ssh_container_name" \
"$ssh_container_name"
fi
}
if [[ ! "$(docker ps -a | grep -w commander-int-test)" ]]; then
docker build -t commander-int-test -f integration/containers/test/Dockerfile .
fi
if [[ ! "$(docker ps -a | grep commander-int-ssh-server)" ]]; then
docker build -t commander-int-ssh-server -f integration/containers/ssh/Dockerfile .
fi
if [[ ! "$(docker network ls | grep commander_test)" ]]; then
docker network create --driver=bridge --subnet=172.28.0.0/16 commander_test
fi
start_ssh_conatiner
echo "Starting tests"
docker run \
--rm \
-v /var/run/docker.sock:/var/run/docker.sock \
--network commander_test \
--name commander-integration-go-test \
--env CC_TEST_REPORTER_ID="${CC_TEST_REPORTER_ID}" \
commander-int-test \
make "$MAKE_TARGET"
status_code="$?"
if [[ "$NO_CLEANUP" -eq "0" ]]; then
cleanup
fi
exit $status_code