Skip to content

Commit d66aefe

Browse files
authored
Improve exit code handling for Docker tests
Refactor exit code retrieval for Docker container.
1 parent 0c2ddbe commit d66aefe

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

docker_compose_test/docker_compose_test.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ trap cleanup EXIT
6969
docker_compose_up_cmd="$docker_compose_bin -f $ABSOLUTE_COMPOSE_FILE_PATH up --exit-code-from $DOCKER_COMPOSE_TEST_CONTAINER $EXTRA_DOCKER_COMPOSE_UP_ARGS"
7070
echo "running: $docker_compose_up_cmd"
7171
echo "$docker_compose_up_cmd" | bash
72-
result=$?
7372

7473
# Figure out the exit code of the test container incase it never actually started.
75-
EXIT_CODE=$(docker inspect $($docker_compose_bin -f $ABSOLUTE_COMPOSE_FILE_PATH ps -qa $DOCKER_COMPOSE_TEST_CONTAINER) --format='{{.State.ExitCode}}' 2>/dev/null)
74+
docker_inspect_cmd="$(docker inspect $($docker_compose_bin -f $ABSOLUTE_COMPOSE_FILE_PATH ps -qa $DOCKER_COMPOSE_TEST_CONTAINER) --format='{{.State.ExitCode}}' 2>/dev/null)"
75+
echo "running: $docker_inspect_cmd"
76+
echo "$docker_inspect_cmd" | bash
77+
EXIT_CODE=$?
7678
if [ "$EXIT_CODE" != "0" ] || [ -z "$EXIT_CODE" ]; then
7779
echo "Error: $DOCKER_COMPOSE_TEST_CONTAINER container failed or never started!"
7880
exit 1

0 commit comments

Comments
 (0)