Skip to content

Commit

Permalink
[tests] update checks for ADDING_OPTIONS. fix using subprocess variab…
Browse files Browse the repository at this point in the history
…les in login tests.
  • Loading branch information
shizunge committed Feb 18, 2024
1 parent 7b8ee71 commit c1a21ba
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/lib-gantry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ _inspect_image() {
fi
local DOCKER_CONFIG=
DOCKER_CONFIG=$(_get_config_from_service "${SERVICE}")
[ -n "${DOCKER_CONFIG}" ] && log DEBUG "Adding options \"${DOCKER_CONFIG}\" to docker commands."
[ -n "${DOCKER_CONFIG}" ] && log DEBUG "Adding options \"${DOCKER_CONFIG}\" to docker commands for ${SERVICE_NAME}."
local IMAGE_INFO=
if ! IMAGE_INFO=$(_get_image_info "${MANIFEST_CMD}" "${IMAGE}" "${DOCKER_CONFIG}"); then
log DEBUG "Skip updating ${SERVICE_NAME} because there is a failure to obtain the manifest from the registry of image ${IMAGE}."
Expand Down
4 changes: 2 additions & 2 deletions tests/gantry_cleanup_images_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Describe 'cleanup-images'
The stderr should satisfy spec_expect_no_message "${NO_IMAGES_TO_REMOVE}"
The stderr should satisfy spec_expect_message "${REMOVING_NUM_IMAGES}"
The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--incorrect-option"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--incorrect-option.*"
The stderr should satisfy spec_expect_message "Failed.*--incorrect-option"
The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}"
The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}"
Expand Down Expand Up @@ -141,7 +141,7 @@ Describe 'cleanup-images'
The stderr should satisfy spec_expect_no_message "${NO_IMAGES_TO_REMOVE}"
The stderr should satisfy spec_expect_message "${REMOVING_NUM_IMAGES}"
The stderr should satisfy spec_expect_no_message "${SKIP_REMOVING_IMAGES}"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--container-label=test"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--container-label=test.*"
The stderr should satisfy spec_expect_no_message "Failed.*--container-label=test"
The stderr should satisfy spec_expect_message "${REMOVED_IMAGE}.*${IMAGE_WITH_TAG}"
The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*${IMAGE_WITH_TAG}"
Expand Down
51 changes: 29 additions & 22 deletions tests/gantry_login_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ Describe 'login'
TEST_NAME="test_login_config"
IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}")
SERVICE_NAME="gantry-test-$(unique_id)"
CONFIG="C$(unique_id)"
TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1
test_login_config() {
local TEST_NAME=${1}
local SERVICE_NAME=${2}
local REGISTRY=${3}
local USERNAME=${4}
local PASSWORD=${5}
local CONFIG=${3}
local REGISTRY=${4}
local USERNAME=${5}
local PASSWORD=${6}
if [ -z "${REGISTRY}" ] || [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]; then
echo "No REGISTRY, USERNAME or PASSWORD provided." >&2
return 1
fi
local LABEL="gantry.auth.config"
CONFIG="C$(unique_id)"
local USER_FILE PASS_FILE
USER_FILE=$(mktemp)
PASS_FILE=$(mktemp)
docker service update --quiet --label-add "${LABEL}=${CONFIG}" "${SERVICE_NAME}"
Expand All @@ -58,7 +60,7 @@ Describe 'login'
BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
It 'run_test'
When run test_login_config "${TEST_NAME}" "${SERVICE_NAME}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}"
When run test_login_config "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}"
The status should be success
The stdout should satisfy display_output
The stderr should satisfy display_output
Expand All @@ -69,7 +71,7 @@ Describe 'login'
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}"
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_NO_NEW_IMAGES}"
The stderr should satisfy spec_expect_message "${NUM_SERVICES_UPDATING}"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${CONFIG}"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_message "${UPDATED}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_no_message "${ROLLING_BACK}.*${SERVICE_NAME}"
Expand All @@ -90,19 +92,21 @@ Describe 'login'
TEST_NAME="test_login_REGISTRY_CONFIGS_FILE"
IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}")
SERVICE_NAME="gantry-test-$(unique_id)"
CONFIG="C$(unique_id)"
TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1
test_login_REGISTRY_CONFIGS_FILE() {
local TEST_NAME=${1}
local SERVICE_NAME=${2}
local REGISTRY=${3}
local USERNAME=${4}
local PASSWORD=${5}
local CONFIG=${3}
local REGISTRY=${4}
local USERNAME=${5}
local PASSWORD=${6}
if [ -z "${REGISTRY}" ] || [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]; then
echo "No REGISTRY, USERNAME or PASSWORD provided." >&2
return 1
fi
local LABEL="gantry.auth.config"
CONFIG="C$(unique_id)"
local CONFIGS_FILE=
CONFIGS_FILE=$(mktemp)
docker service update --quiet --label-add "${LABEL}=${CONFIG}" "${SERVICE_NAME}"
echo "# Test comments: CONFIG REGISTRY USERNAME PASSWORD" >> "${CONFIGS_FILE}"
Expand All @@ -126,7 +130,7 @@ Describe 'login'
BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
It 'run_test'
When run test_login_REGISTRY_CONFIGS_FILE "${TEST_NAME}" "${SERVICE_NAME}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}"
When run test_login_REGISTRY_CONFIGS_FILE "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}"
The status should be success
The stdout should satisfy display_output
The stderr should satisfy display_output
Expand All @@ -137,7 +141,7 @@ Describe 'login'
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}"
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_NO_NEW_IMAGES}"
The stderr should satisfy spec_expect_message "${NUM_SERVICES_UPDATING}"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${CONFIG}"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_message "${UPDATED}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_no_message "${ROLLING_BACK}.*${SERVICE_NAME}"
Expand All @@ -158,19 +162,21 @@ Describe 'login'
TEST_NAME="test_login_REGISTRY_CONFIGS_FILE_bad_format"
IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}")
SERVICE_NAME="gantry-test-$(unique_id)"
CONFIG="C$(unique_id)"
TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1
test_login_REGISTRY_CONFIGS_FILE_bad_format() {
local TEST_NAME=${1}
local SERVICE_NAME=${2}
local REGISTRY=${3}
local USERNAME=${4}
local PASSWORD=${5}
local CONFIG=${3}
local REGISTRY=${4}
local USERNAME=${5}
local PASSWORD=${6}
if [ -z "${REGISTRY}" ] || [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]; then
echo "No REGISTRY, USERNAME or PASSWORD provided." >&2
return 1
fi
local LABEL="gantry.auth.config"
CONFIG="C$(unique_id)"
local CONFIGS_FILE=
CONFIGS_FILE=$(mktemp)
docker service update --quiet --label-add "${LABEL}=${CONFIG}" "${SERVICE_NAME}"
# Add an extra item to the line.
Expand All @@ -189,7 +195,7 @@ Describe 'login'
BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
It 'run_test'
When run test_login_REGISTRY_CONFIGS_FILE_bad_format "${TEST_NAME}" "${SERVICE_NAME}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}"
When run test_login_REGISTRY_CONFIGS_FILE_bad_format "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}"
The status should be failure
The stdout should satisfy display_output
The stderr should satisfy display_output
Expand Down Expand Up @@ -224,19 +230,20 @@ Describe 'login'
TEST_NAME="test_login_file_not_exist"
IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}")
SERVICE_NAME="gantry-test-$(unique_id)"
CONFIG="C$(unique_id)"
TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1
test_login_file_not_exist() {
local TEST_NAME=${1}
local SERVICE_NAME=${2}
local REGISTRY=${3}
local USERNAME=${4}
local PASSWORD=${5}
local CONFIG=${3}
local REGISTRY=${4}
local USERNAME=${5}
local PASSWORD=${6}
if [ -z "${REGISTRY}" ] || [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]; then
echo "No REGISTRY, USERNAME or PASSWORD provided." >&2
return 1
fi
local LABEL="gantry.auth.config"
CONFIG="C$(unique_id)"
docker service update --quiet --label-add "${LABEL}=${CONFIG}" "${SERVICE_NAME}"
local FILE_NOT_EXIST="/tmp/${CONFIG}"
reset_gantry_env "${SERVICE_NAME}"
Expand All @@ -254,7 +261,7 @@ Describe 'login'
BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}"
It 'run_test'
When run test_login_file_not_exist "${TEST_NAME}" "${SERVICE_NAME}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}"
When run test_login_file_not_exist "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}"
The status should be failure
The stdout should satisfy display_output
The stderr should satisfy display_output
Expand Down
6 changes: 3 additions & 3 deletions tests/gantry_manifest_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Describe 'manifest-command'
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}"
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_NO_NEW_IMAGES}"
The stderr should satisfy spec_expect_message "${NUM_SERVICES_UPDATING}"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--force"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--force.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_no_message "${UPDATED}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_message "${NO_UPDATES}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_no_message "${ROLLING_BACK}.*${SERVICE_NAME}"
Expand Down Expand Up @@ -130,7 +130,7 @@ Describe 'manifest-command'
The status should be success
The stdout should satisfy display_output
The stderr should satisfy display_output
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--insecure"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--insecure.*"
The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_message "${PERFORM_UPDATING}.*${SERVICE_NAME}.*${PERFORM_REASON_HAS_NEWER_IMAGE}"
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}"
Expand Down Expand Up @@ -173,7 +173,7 @@ Describe 'manifest-command'
The stdout should satisfy display_output
The stderr should satisfy display_output
# No options are added to the unknwon command.
The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--insecure"
The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--insecure.*"
The stderr should satisfy spec_expect_message "Unknown MANIFEST_CMD.*unsupported_cmd"
The stderr should satisfy spec_expect_message "${SKIP_UPDATING}.*${SERVICE_NAME}.*${SKIP_REASON_MANIFEST_FAILURE}"
The stderr should satisfy spec_expect_no_message "${PERFORM_UPDATING}.*${SERVICE_NAME}"
Expand Down
4 changes: 2 additions & 2 deletions tests/gantry_parallel_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Describe 'service-parallel'
The stderr should satisfy spec_expect_message "${NUM_SERVICES_NO_NEW_IMAGES}"
The stderr should satisfy spec_expect_message "${NUM_SERVICES_UPDATING}"
The stderr should satisfy spec_expect_no_message "${NO_SERVICES_UPDATED}"
The stderr should satisfy spec_expect_message "7 ${SERVICES_UPDATED}"
The stderr should satisfy spec_expect_message "$((MAX_SERVICES_NUM+1)) ${SERVICES_UPDATED}"
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_UPDATE_FAILED}"
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_ERRORS}"
The stderr should satisfy spec_expect_no_message "${NO_IMAGES_TO_REMOVE}"
Expand Down Expand Up @@ -130,7 +130,7 @@ Describe 'service-parallel'
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_NO_NEW_IMAGES}"
The stderr should satisfy spec_expect_message "${NUM_SERVICES_UPDATING}"
The stderr should satisfy spec_expect_no_message "${NO_SERVICES_UPDATED}"
The stderr should satisfy spec_expect_message "11 ${SERVICES_UPDATED}"
The stderr should satisfy spec_expect_message "$((MAX_SERVICES_NUM+1)) ${SERVICES_UPDATED}"
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_UPDATE_FAILED}"
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_ERRORS}"
The stderr should satisfy spec_expect_no_message "${NO_IMAGES_TO_REMOVE}"
Expand Down
2 changes: 1 addition & 1 deletion tests/gantry_rollback_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Describe 'rollback'
The stderr should satisfy spec_expect_message "${NUM_SERVICES_UPDATING}"
The stderr should satisfy spec_expect_no_message "${UPDATED}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--incorrect-option"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--incorrect-option.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_message "${ROLLING_BACK}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_message "${FAILED_TO_ROLLBACK}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_no_message "${ROLLED_BACK}.*${SERVICE_NAME}"
Expand Down
6 changes: 3 additions & 3 deletions tests/gantry_service_no_running_tasks_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ Describe "service-no-running-tasks"
# https://github.com/docker/cli/issues/627
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true.*${SERVICE_NAME}\."
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--replicas=0.*${SERVICE_NAME}\."
The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--detach=true.*${SERVICE_NAME_SUFFIX}\."
The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--replicas=0.*${SERVICE_NAME_SUFFIX}\."
The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--detach=true.*${SERVICE_NAME_SUFFIX}"
The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--replicas=0.*${SERVICE_NAME_SUFFIX}"
The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_message "${PERFORM_UPDATING}.*${SERVICE_NAME}.*${PERFORM_REASON_HAS_NEWER_IMAGE}"
The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME_SUFFIX}"
Expand Down Expand Up @@ -129,7 +129,7 @@ Describe "service-no-running-tasks"
The stderr should satisfy display_output
# Add "--detach=true" when there is no running tasks.
# https://github.com/docker/cli/issues/627
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true.*${SERVICE_NAME}"
# Cannot add "--replicas" to global mode
The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--replicas=0"
The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}"
Expand Down
6 changes: 3 additions & 3 deletions tests/gantry_update_options_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Describe 'update-options'
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}"
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_NO_NEW_IMAGES}"
The stderr should satisfy spec_expect_message "${NUM_SERVICES_UPDATING}"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_message "${UPDATED}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_no_message "${ROLLING_BACK}.*${SERVICE_NAME}"
Expand Down Expand Up @@ -148,7 +148,7 @@ Describe 'update-options'
The status should be success
The stdout should satisfy display_output
The stderr should satisfy display_output
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--detach=true.*${SERVICE_NAME}"
# Cannot add "--replicas" to replicated job
The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--replicas=0"
The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}"
Expand Down Expand Up @@ -214,7 +214,7 @@ Describe 'update-options'
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}"
The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_NO_NEW_IMAGES}"
The stderr should satisfy spec_expect_message "${NUM_SERVICES_UPDATING}"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--label-add=gantry.test=${SERVICE_NAME}"
The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--label-add=gantry.test=${SERVICE_NAME}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_message "${UPDATED}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}"
The stderr should satisfy spec_expect_no_message "${ROLLING_BACK}.*${SERVICE_NAME}"
Expand Down

0 comments on commit c1a21ba

Please sign in to comment.