Created
July 2, 2019 09:11
-
-
Save chrismaes87/7297d34d356b07a00a5da5f8e425326c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
me=$(basename $0) | |
function print_help { | |
echo "$me - wrapper for docker-compose --exit-code-from <test-service>" | |
echo | |
echo "SYNOPSIS" | |
echo " docker-compose --exit-code-from implies --abort-on-container-exit." | |
echo " This has a nasty side-effect: docker-compose will exit with code 0 if another container than test exits early." | |
echo " $me tries to work around this issue." | |
echo " The goal is that exit code 0 means that the tests really ran an returned 0." | |
echo | |
echo "OPTIONS" | |
echo " -h | --help" | |
echo " show this help summary" | |
} | |
# fail even when option parsing fails | |
set -e | |
# option parsing | |
REARRANGED_OPTIONS=$(getopt -o h --long help -- "$@") | |
eval set -- "$REARRANGED_OPTIONS" | |
while true | |
do | |
case "$1" in | |
-h | --help ) print_help; exit;; | |
-- ) | |
shift; # skip -- | |
if [ $# -ne 1 ] | |
then | |
echo "$me requires exactly one argument: the name of the test-service." | |
exit 1 | |
fi | |
TEST_SERVICE=$1 | |
break;; | |
* ) echo "Unexpected options: \"$@\" . exiting."; exit 1 ;; | |
esac | |
done | |
TMP=$(mktemp /tmp/$me-XXXXXXXXX) | |
function cleanup { | |
rm -rf $TMP | |
docker-compose down -v | |
} | |
trap cleanup EXIT | |
set -x | |
docker-compose down -v | |
docker-compose pull | |
docker-compose up --build --exit-code-from $TEST_SERVICE > >(tee $TMP) 2>&1 | |
# exit with failure if tests didn't really run and finish with code 0 | |
grep -q "_${TEST_SERVICE}_1 exited with code 0" $TMP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment