-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.sh
executable file
·46 lines (39 loc) · 1 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
VERSION="3.7"
ok() { echo " [OK]"; }
fail() {
if [ -z "$1" ]; then clean; fi
echo " [FAIL]"; exit 1;
}
clean() {
if [[ "${CONTAINER_ID}" ]]; then
echo -n "Shutting down container"
docker kill "${CONTAINER_ID}" >/dev/null &&
ok || fail 1
fi
if [[ "${IMAGE_ID}" ]]; then
echo -n "Cleaning up image"
docker image rm "${IMAGE_ID}" >/dev/null &&
ok || fail 1
fi
}
# Prepare test container
echo -n "Building test image"
IMAGE_ID="$(docker build --build-arg VERSION="${VERSION}" --quiet .)" &&
ok || fail
echo -n "Starting container"
CONTAINER_ID="$(docker run --detach --tty --rm "${IMAGE_ID}")" &&
ok || fail
# Run test suite
echo "Running test suite"
docker exec --interactive --tty "${CONTAINER_ID}" pytest
echo -n "Retrieving coverage report"
docker cp ${CONTAINER_ID}:/root/coverage.xml ./ >/dev/null &&
ok || fail
# Drop into a shell if requested
if [[ -n "$1" ]]; then
docker exec --interactive --tty "${CONTAINER_ID}" /bin/bash ||
fail
fi
# Clean up
clean
exit 0