Skip to content

Commit

Permalink
[tests] fix return value when run_gantry is not the last command in t…
Browse files Browse the repository at this point in the history
…he call function.
  • Loading branch information
shizunge committed Feb 1, 2024
1 parent 63c4229 commit 91d63c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
16 changes: 12 additions & 4 deletions tests/gantry_login_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ Describe 'Login'
export GANTRY_REGISTRY_HOST="${REGISTRY}"
export GANTRY_REGISTRY_PASSWORD_FILE="${PASS_FILE}"
export GANTRY_REGISTRY_USER_FILE="${USER_FILE}"
local RETURN_VALUE=
run_gantry "${TEST_NAME}"
RETURN_VALUE="${?}"
rm "${USER_FILE}"
rm "${PASS_FILE}"
[ -d "${CONFIG}" ] && rm -r "${CONFIG}"
return 0
return "${RETURN_VALUE}"
}
Before "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
After "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
Expand Down Expand Up @@ -98,10 +100,12 @@ Describe 'Login'
echo "# Test comments: CONFIG REGISTRY USERNAME PASSWORD" >> "${CONFIGS_FILE}"
echo "${CONFIG} ${REGISTRY} ${USERNAME} ${PASSWORD}" >> "${CONFIGS_FILE}"
export GANTRY_REGISTRY_CONFIGS_FILE="${CONFIGS_FILE}"
local RETURN_VALUE=
run_gantry "${TEST_NAME}"
RETURN_VALUE="${?}"
rm "${CONFIGS_FILE}"
[ -d "${CONFIG}" ] && rm -r "${CONFIG}"
return 0
return "${RETURN_VALUE}"
}
Before "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
After "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
Expand Down Expand Up @@ -150,10 +154,12 @@ Describe 'Login'
# Add an extra item to the line.
echo "${CONFIG} ${REGISTRY} ${USERNAME} ${PASSWORD} Extra" >> "${CONFIGS_FILE}"
export GANTRY_REGISTRY_CONFIGS_FILE="${CONFIGS_FILE}"
local RETURN_VALUE=
run_gantry "${TEST_NAME}"
RETURN_VALUE="${?}"
rm "${CONFIGS_FILE}"
[ -d "${CONFIG}" ] && rm -r "${CONFIG}"
return 0
return "${RETURN_VALUE}"
}
Before "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
After "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
Expand Down Expand Up @@ -204,10 +210,12 @@ Describe 'Login'
# Missing an item from the line.
echo "${REGISTRY} ${USERNAME} ${PASSWORD}" >> "${CONFIGS_FILE}"
export GANTRY_REGISTRY_CONFIGS_FILE="${CONFIGS_FILE}"
local RETURN_VALUE=
run_gantry "${TEST_NAME}"
RETURN_VALUE="${?}"
rm "${CONFIGS_FILE}"
[ -d "${CONFIG}" ] && rm -r "${CONFIG}"
return
return "${RETURN_VALUE}"
}
Before "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
After "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
Expand Down
3 changes: 3 additions & 0 deletions tests/gantry_options_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ Describe 'Options'

LABEL_VALUE=$(_read_service_label "${SERVICE_NAME}" "${LABEL}")
echo "Before updating: LABEL_VALUE=${LABEL_VALUE}"
local RETURN_VALUE=
run_gantry "${TEST_NAME}"
RETURN_VALUE="${?}"
LABEL_VALUE=$(_read_service_label "${SERVICE_NAME}" "${LABEL}")
echo "After updating: LABEL_VALUE=${LABEL_VALUE}"
return "${RETURN_VALUE}"
}
Before "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
After "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
Expand Down
7 changes: 5 additions & 2 deletions tests/spec_gantry_test_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,14 @@ _run_gantry_container() {
fi
local SERVICE_NAME=
SERVICE_NAME="gantry-test-SUT-$(unique_id)"
docker service rm "${SERVICE_NAME}" >/dev/null 2>&1;
local MOUNT_OPTIONS=
MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${GANTRY_REGISTRY_CONFIG_FILE}")
MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${GANTRY_REGISTRY_CONFIGS_FILE}")
MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${GANTRY_REGISTRY_HOST_FILE}")
MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${GANTRY_REGISTRY_PASSWORD_FILE}")
MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${GANTRY_REGISTRY_USER_FILE}")
local CMD_OUTPUT=
docker service rm "${SERVICE_NAME}" >/dev/null 2>&1;
local RETURN_VALUE=
echo -n "Starting SUT service ${SERVICE_NAME} "
# SC2086 (info): Double quote to prevent globbing and word splitting.
# shellcheck disable=SC2086
Expand Down Expand Up @@ -540,10 +540,13 @@ _run_gantry_container() {
--env "TZ=${TZ}" \
"${SUT_REPO_TAG}" \
"${STACK}";
RETURN_VALUE="${?}"
docker service logs --raw "${SERVICE_NAME}"
local CMD_OUTPUT=
if ! CMD_OUTPUT=$(docker service rm "${SERVICE_NAME}" 2>&1); then
echo "Failed to remove service ${SERVICE_NAME}: ${CMD_OUTPUT}" >&2
fi
return "${RETURN_VALUE}"
}

run_gantry() {
Expand Down

0 comments on commit 91d63c5

Please sign in to comment.