-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
test-nts.sh
executable file
·61 lines (50 loc) · 2.09 KB
/
test-nts.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
#!/bin/bash
#
# A simple script to start a Docker container
# and run Testinfra in it
# Original script: https://gist.github.com/renatomefi/bbf44d4e8a2614b1390416c6189fbb8e
# Author: @renatomefi https://github.com/renatomefi
#
set -eEuo pipefail
# The first parameter is a Docker tag or image id
declare -r DOCKER_TAG="$1"
declare TEST_SUITE
TEST_SUITE="php_$IMAGE_ARCH"
if [[ $DOCKER_TAG == *"-dev"* && $IMAGE_BASE_VERSION != *"alpha"* && $IMAGE_BASE_VERSION != *"beta"* && $IMAGE_BASE_VERSION != *"rc"* && $IMAGE_BASE_VERSION != *"ALPHA"* && $IMAGE_BASE_VERSION != *"BETA"* && $IMAGE_BASE_VERSION != *"RC"* ]]; then
TEST_SUITE="php_nts or php_dev"
else
TEST_SUITE="php_nts or php_no_dev and not php_dev"
fi
if [[ $DOCKER_TAG == *"-slim"* ]]; then
TEST_SUITE="php_slim or php_slim_$IMAGE_ARCH or $TEST_SUITE"
else
if [[ $IMAGE_BASE_VERSION != *"alpha"* && $IMAGE_BASE_VERSION != *"beta"* && $IMAGE_BASE_VERSION != *"rc"* && $IMAGE_BASE_VERSION != *"ALPHA"* && $IMAGE_BASE_VERSION != *"BETA"* && $IMAGE_BASE_VERSION != *"RC"* ]]; then
TEST_SUITE="$TEST_SUITE"
else
TEST_SUITE="php_not_slim and php_not_slim_$IMAGE_ARCH or $TEST_SUITE"
fi
fi
if [[ $DOCKER_TAG == *"-root"* ]]; then
TEST_SUITE="php_root or $TEST_SUITE"
else
TEST_SUITE="php_app or $TEST_SUITE"
fi
printf "Starting a container for '%s'\\n" "$DOCKER_TAG"
DOCKER_CONTAINER=$(docker run --rm -v "$(pwd)/test:/tests" -t -d "$DOCKER_TAG" php)
readonly DOCKER_CONTAINER
# Let's register a trap function, if our tests fail, finish or the script gets
# interrupted, we'll still be able to remove the running container
function tearDown {
docker rm -f "$DOCKER_CONTAINER" &>/dev/null &
}
trap tearDown EXIT TERM ERR
# Finally, run the tests!
echo "Running test suite: $TEST_SUITE"
docker run --rm -t \
-v "$(pwd)/test:/tests" \
-v "$(pwd)/tmp/test-results:/results" \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
renatomefi/docker-testinfra:5 \
-m "$TEST_SUITE" --junitxml="/results/php-nts-$DOCKER_TAG.xml" \
--disable-pytest-warnings \
--verbose --hosts="docker://$DOCKER_CONTAINER"