diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 9d5e6c3..34d7321 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -38,7 +38,7 @@ jobs: run: | export DOCKERHUB_PASSWORD=${{ secrets.DOCKERHUB_PASSWORD }} export DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }} - bash shellspec --kcov --jobs 50 --tag "coverage:true" + bash shellspec --kcov --jobs 50 - name: Upload reports uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/on-push.yml b/.github/workflows/on-push.yml index 56152b6..91592ab 100644 --- a/.github/workflows/on-push.yml +++ b/.github/workflows/on-push.yml @@ -162,4 +162,4 @@ jobs: export DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }} export GANTRY_TEST_CONTAINER_REPO_TAG=$(cat tag.txt) echo "GANTRY_TEST_CONTAINER_REPO_TAG=${GANTRY_TEST_CONTAINER_REPO_TAG}" - bash shellspec --jobs 50 --tag "container_test:true" + bash shellspec --jobs 50 diff --git a/src/lib-common.sh b/src/lib-common.sh index c01ee1f..0673647 100755 --- a/src/lib-common.sh +++ b/src/lib-common.sh @@ -21,11 +21,12 @@ _random_string() { _pipe_name() { local BASE_NAME="${1:-pipe-base-name}" - local RANDOM_STR= - RANDOM_STR=$(_random_string) + local PID=$$ local TIMESTAMP= TIMESTAMP=$(date +%s) - local PIPE_NAME="/tmp/${BASE_NAME}-$$-${TIMESTAMP}-${RANDOM_STR}" + local RANDOM_STR= + RANDOM_STR=$(_random_string) + local PIPE_NAME="/tmp/${BASE_NAME}-${PID}-${TIMESTAMP}-${RANDOM_STR}" echo "${PIPE_NAME}" } @@ -79,6 +80,7 @@ extract_string() { # All lower or all upper. No mix. _log_level_to_upper() { local LEVEL="${1}"; + # tr is slow. case "${LEVEL}" in "debug") echo "DEBUG"; ;; "info") echo "INFO"; ;; @@ -114,20 +116,30 @@ _first_word_is_level() { esac } -_log_skip_level() { +_log_skip_level_echo_color() { local LEVEL="${1}"; + # Ideally, one function should do one thing. + # But by merging two functions "_log_skip" and "log_color" into one, we reduce the number of "case" to improve performance. + # local BLUE='\033[0;34m' + # local GREEN='\033[0;32m' + # local ORANGE='\033[0;33m' + # local RED='\033[0;31m' + # local NO_COLOR='\033[0m' + # SC2028 (info): echo may not expand escape sequences. Use printf. + # shellcheck disable=SC2028 case "${LEVEL}" in - "DEBUG") return "${2}"; ;; - "INFO"|"") return "${3}"; ;; - "WARN") return "${4}"; ;; - "ERROR") return "${5}"; ;; - "NONE"|*) return "${6}"; ;; + "DEBUG") echo "\033[0;34m"; return "${2}"; ;; + "INFO"|"") echo "\033[0;32m"; return "${3}"; ;; + "WARN") echo "\033[0;33m"; return "${4}"; ;; + "ERROR") echo "\033[0;31m"; return "${5}"; ;; + "NONE"|*) echo "\033[0m"; return "${6}"; ;; esac } +# Echo the color for the given LEVEL. # return 0 to skip logging. # return 1 otherwise. -_log_skip() { +_log_skip_echo_color() { local TARGET_LEVEL="${1}"; local LEVEL="${2}"; # This is 10% faster than the following command: @@ -143,67 +155,64 @@ _log_skip() { # } # test "$(_log_level "${LEVEL}")" -lt "$(_log_level "${TARGET_LEVEL}")"; return $? case "${TARGET_LEVEL}" in - "DEBUG") _log_skip_level "${LEVEL}" 1 1 1 1 1; ;; - "INFO"|"") _log_skip_level "${LEVEL}" 0 1 1 1 1; ;; - "WARN") _log_skip_level "${LEVEL}" 0 0 1 1 1; ;; - "ERROR") _log_skip_level "${LEVEL}" 0 0 0 1 1; ;; - "NONE"|*) _log_skip_level "${LEVEL}" 0 0 0 0 1; ;; - esac -} - -_level_color() { - local LEVEL="${1}" - local NO_COLOR='\033[0m' - local RED='\033[0;31m' - local ORANGE='\033[0;33m' - local GREEN='\033[0;32m' - local BLUE='\033[0;34m' - case "${LEVEL}" in - "DEBUG") echo "${BLUE}"; ;; - "INFO") echo "${GREEN}"; ;; - "WARN") echo "${ORANGE}"; ;; - "ERROR") echo "${RED}"; ;; - *) echo "${NO_COLOR}"; ;; + "DEBUG") _log_skip_level_echo_color "${LEVEL}" 1 1 1 1 1; ;; + "INFO"|"") _log_skip_level_echo_color "${LEVEL}" 0 1 1 1 1; ;; + "WARN") _log_skip_level_echo_color "${LEVEL}" 0 0 1 1 1; ;; + "ERROR") _log_skip_level_echo_color "${LEVEL}" 0 0 0 1 1; ;; + "NONE"|*) _log_skip_level_echo_color "${LEVEL}" 0 0 0 0 1; ;; esac - return 0; -} - -_color_iso_time() { - local EPOCH="${1}" - # Highlight time within the day in ISO-8601 (2024-11-23T21:50:13-08:00) - # local NO_COLOR='\033[0m' - # local DGRAY="\033[1;30m" - # local LGRAY="\033[0;37m" - local TIME_STR= - TIME_STR=$(busybox date -d "@${EPOCH}" +"\033[1;30m%Y-%m-%dT\033[0;37m%H:%M:%S\033[1;30m%z") - # +0000 -> +00:00 - echo "${TIME_STR:0:-2}:${TIME_STR:0-2}\033[0m" } _log_formatter() { local TARGET_LEVEL="${LOG_LEVEL:-}"; local LEVEL="${1}"; - local EPOCH="${2}"; + local TIME_WITH_COLOR="${2}"; local LOCATION="${3}"; local SCOPE="${4}"; TARGET_LEVEL=$(_log_level_to_upper "${TARGET_LEVEL}") LEVEL=$(_log_level_to_upper "${LEVEL}") - _log_skip "${TARGET_LEVEL}" "${LEVEL}" && return 0; + local LEVEL_COLOR= + LEVEL_COLOR=$(_log_skip_echo_color "${TARGET_LEVEL}" "${LEVEL}") && return 0; shift 4; - local NO_COLOR='\033[0m' - local DGRAY='\033[1;30m' - local TIME_STR LOC_STR LEVEL_STR SCOPE_STR - TIME_STR="${DGRAY}[$(_color_iso_time "${EPOCH}")${DGRAY}]${NO_COLOR}" + # Faster for not using local variables. (tested in a micro benchmark) + # local DGRAY='\033[1;30m' + # local NO_COLOR='\033[0m' + # Formatting time logically should be done inside this function. + # But we let caller do it to reduce the number of calls of "date" to increase performance. + local TIME_STR="\033[1;30m[${TIME_WITH_COLOR}\033[1;30m]\033[0m" + local LEVEL_STR="${LEVEL_COLOR}[${LEVEL}]\033[0m " + local LOC_STR SCOPE_STR if [ -n "${LOCATION}" ]; then - LOC_STR="${DGRAY}[${LOCATION}]${NO_COLOR}" + LOC_STR="\033[1;30m[${LOCATION}]\033[0m" fi - LEVEL_STR="$(_level_color "${LEVEL}")[${LEVEL}]${NO_COLOR} " if [ -n "${SCOPE}" ]; then - SCOPE_STR="${DGRAY}${SCOPE}:${NO_COLOR} " + SCOPE_STR="\033[1;30m${SCOPE}:\033[0m " fi - local MSG_STR= - MSG_STR=$(echo "${*}" | tr '\n' ' ') - echo -e "${TIME_STR}${LOC_STR}${LEVEL_STR}${SCOPE_STR}${MSG_STR}" >&2 + # sed to remove \n + # :a - Creates a label a for looping. + # N - Appends the next line to the pattern space. + # $!ba - Loops back to the label a if not the last line ($! means "not last line"). + # s/\n/ /g - Substitutes all newline characters with a space. + echo -e "${TIME_STR}${LOC_STR}${LEVEL_STR}${SCOPE_STR}${*}" | sed ':a;N;$!ba;s/\n/ /g' >&2 + # Here are a few alternatives to "sed" + # "echo without quotes" remove carriage returns, tabs and multiple spaces. + # "echo" is faster than "tr", but it does not preserve the leading space. + # That is why we don't use "echo" here. + # "tr '\n' ' '" is slow and adds a space to the end of the string. +} + +_time_format() { + # To mimik format from "date -Isecond". + # Highlight time within the day in ISO-8601 (2024-11-23T21:50:13-08:00) + # local DGRAY="\033[1;30m" + # local LGRAY="\033[0;37m" + # local NO_COLOR='\033[0m' + # echo "${DGRAY}%Y-%m-%dT${LGRAY}%H:%M:%S${DGRAY}%z${NO_COLOR}" + # The following is faster than the above for not using local variables. (tested in a micro benchmark) + # Busybox date does not support %:z, only %z. So the time zone will be -0800. + # SC2028 (info): echo may not expand escape sequences. Use printf. + # shellcheck disable=SC2028 + echo "\033[1;30m%Y-%m-%dT\033[0;37m%H:%M:%S\033[1;30m%z\033[0m" } # We want to print an empty line for log without an argument. Thus we do not run the following check. @@ -216,38 +225,51 @@ log() { LEVEL="${1}"; shift; fi - local EPOCH= - EPOCH="$(date +%s)" - _log_formatter "${LEVEL}" "${EPOCH}" "${LOCAL_NODE}" "${LOCAL_SCOPE}" "${@}"; + local TIME_WITH_COLOR= + TIME_WITH_COLOR="$(date +"$(_time_format)")" + _log_formatter "${LEVEL}" "${TIME_WITH_COLOR}" "${LOCAL_NODE}" "${LOCAL_SCOPE}" "${@}"; } -_log_docker_time_epoch() { - # Convert timestamps from `docker service logs` to EPOCH. +_log_docker_time() { + # Convert timestamps from `docker service logs`. # The timestamps is in UTC. # docker service logs --timestamps --no-task-ids # 2023-06-22T01:20:54.535860111Z @ | local TIME_INPUT="${1}" - if ! busybox date -d "${TIME_INPUT}" -D "%Y-%m-%dT%H:%M:%S" -u +%s 2>/dev/null; then - date +%s - return 1 + # We are expecting most inputs are correct. + # coreutils date can do the conversion in one command, thus faster. + # date -d "${TIME_INPUT}" +"$(_time_format)" 2>/dev/null && return 0 + local EPOCH= + if EPOCH=$(busybox date -d "${TIME_INPUT}" -D "%Y-%m-%dT%H:%M:%S" -u +%s 2>/dev/null); then + date -d "@${EPOCH}" +"$(_time_format)" 2>&1 + return 0 + fi + if [ -n "${TIME_INPUT}" ]; then + echo "${TIME_INPUT}" + else + date +"$(_time_format)" fi + return 1 } # Convert logs from `docker service logs` to `log` format. # docker service logs --timestamps --no-task-ids # 2023-06-22T01:20:54.535860111Z @ | _log_docker_line() { - local LOCAL_NODE="${NODE_NAME:-}" - local LOCAL_SCOPE="${LOG_SCOPE:-}" + local NODE="${NODE_NAME:-}" + local SCOPE="${LOG_SCOPE:-}" local LEVEL="INFO"; - local EPOCH NODE SCOPE MESSAGE # Using the same regexp for all 4 parts: - local TIME_DOCKER TASK_DOCKER NODE_DOCKER - read -r TIME_DOCKER TASK_DOCKER NODE_DOCKER MESSAGE < <(echo "${*}" | sed -n -E "s/^(\S+) +(\S+)@(\S+) +\| ?/\1 \2 \3 /p"); - EPOCH=$(_log_docker_time_epoch "${TIME_DOCKER}"); + local TIME_DOCKER TASK_DOCKER NODE_DOCKER MESSAGE + # Add a "+" before the last part to ensure we preserve the leading spaces in the message. + read -r TIME_DOCKER TASK_DOCKER NODE_DOCKER MESSAGE < <(echo "${*}" | sed -n -E "s/^(\S+) +(\S+)@(\S+) +\| ?/\1 \2 \3 +/p"); + local TIME_WITH_COLOR= + TIME_WITH_COLOR=$(_log_docker_time "${TIME_DOCKER}"); if [ -n "${TASK_DOCKER}" ] || [ -n "${NODE_DOCKER}" ] || [ -n "${MESSAGE}" ]; then NODE="${NODE_DOCKER}" SCOPE="${TASK_DOCKER}" + # Remove the extra "+" we added above for preserving the leading spaces. + MESSAGE="${MESSAGE:1}" if _first_word_is_level "${MESSAGE}"; then LEVEL=$(_get_first_word "${MESSAGE}"); MESSAGE=$(extract_string "${MESSAGE}" ' ' 2-); @@ -256,11 +278,9 @@ _log_docker_line() { # All three are empty, sed failure indicates errors. # format error, imply that we receive an error message from the "docker service logs" command. LEVEL="ERROR" - NODE="${LOCAL_NODE}" - SCOPE="${LOCAL_SCOPE}" MESSAGE="${*}" fi - _log_formatter "${LEVEL}" "${EPOCH}" "${NODE}" "${SCOPE}" "${MESSAGE}"; + _log_formatter "${LEVEL}" "${TIME_WITH_COLOR}" "${NODE}" "${SCOPE}" "${MESSAGE}"; } _log_docker_multiple_lines() { @@ -441,15 +461,10 @@ _get_docker_command_name_arg() { } _get_docker_command_detach() { - if echo "${@}" | grep_q "--detach=false"; then - echo "false" - elif echo "${@}" | grep_q "--detach"; then - # assume we find --detach or --detach=true. - echo "true" - else - echo "false" - fi - return 0 + echo "${@}" | grep_q "--detach=false" && return 1; + # assume we find --detach or --detach=true. + echo "${@}" | grep_q "--detach" && return 0; + return 1; } docker_service_logs() { @@ -557,25 +572,35 @@ _all_tasks_reach_state() { return 0 } -# Usage: wait_service_state -# Wait for the service, usually a global job or a replicated job, -# to reach either running or complete state. +# Usage: wait_service_state [WANT_STATE] [timeout in seconds] +# Wait for the service, usually a global job or a replicated job, to reach either running or complete state. # Valid WANT_STATE includes "Running" and "Complete" -# When the WANT_STATE is complete, the function returns immediately -# when any of the tasks of the service fails. -# In case of task failing, the function returns a non-zero value. +# When the WANT_STATE is complete, the function returns immediately when any of the tasks of the service fails. +# In case of task failing, the function returns the first failing task's return value. +# When the WANT_STATE is empty, this function reports the status of all tasks and then returns. wait_service_state() { local SERVICE_NAME="${1}"; local WANT_STATE="${2}"; + local TIMEOUT_SECONDS="${3}"; local CHECK_FAILURES=false [ "${WANT_STATE}" = "Complete" ] && CHECK_FAILURES=true local SLEEP_SECONDS=1 - local DOCKER_CMD_ERROR=1 + local START_TIME= + START_TIME=$(date +%s) local RETURN_VALUE=0 + local DOCKER_CMD_ERROR=1 local STATES= while STATES=$(_docker_service_task_states "${SERVICE_NAME}" 2>&1); do DOCKER_CMD_ERROR=0 RETURN_VALUE=$(_all_tasks_reach_state "${WANT_STATE}" "${CHECK_FAILURES}" "${STATES}") && break + local SECONDS_ELAPSED= + if is_number "${TIMEOUT_SECONDS}" \ + && SECONDS_ELAPSED=$(first_minus_second "$(date +%s)" "${START_TIME}") \ + && [ "${SECONDS_ELAPSED}" -ge "${TIMEOUT_SECONDS}" ]; then + log ERROR "wait_service_state ${SERVICE_NAME} ${WANT_STATE} timeout after ${SECONDS_ELAPSED}s." + RETURN_VALUE=2 + break + fi sleep "${SLEEP_SECONDS}" DOCKER_CMD_ERROR=1 done @@ -636,9 +661,7 @@ docker_global_job() { # A job could fail when using docker_replicated_job. docker_replicated_job() { local SERVICE_NAME= - local IS_DETACH= SERVICE_NAME=$(_get_docker_command_name_arg "${@}") - IS_DETACH=$(_get_docker_command_detach "${@}") # Add "--detach" to work around https://github.com/docker/cli/issues/2979 # The Docker CLI does not exit on failures. log INFO "Starting replicated-job ${SERVICE_NAME}." @@ -648,7 +671,7 @@ docker_replicated_job() { return 1 fi # If the command line does not contain '--detach', the function returns til the replicated job is complete. - if ! "${IS_DETACH}"; then + if ! _get_docker_command_detach "${@}"; then wait_service_state "${SERVICE_NAME}" "Complete" || return $? fi return 0 diff --git a/src/lib-gantry.sh b/src/lib-gantry.sh index 18766a6..fdc58e2 100755 --- a/src/lib-gantry.sh +++ b/src/lib-gantry.sh @@ -1013,14 +1013,18 @@ _update_single_service() { local UPDATE_COMMAND="${TIMEOUT_COMMAND} docker ${AUTH_CONFIG} service update" local UPDATE_RETURN_VALUE=0 local UPDATE_MSG= + # Add "2>/dev/null" outside the $(cmd) to suppress the "Terminated" message from "busybox timeout". # Add "-quiet" to suppress progress output. # SC2086: Double quote to prevent globbing and word splitting. # shellcheck disable=SC2086 - UPDATE_MSG=$(${UPDATE_COMMAND} --quiet ${AUTOMATIC_OPTIONS} ${UPDATE_OPTIONS} --image="${IMAGE}" "${SERVICE_NAME}" 2>&1); + UPDATE_MSG=$(${UPDATE_COMMAND} --quiet ${AUTOMATIC_OPTIONS} ${UPDATE_OPTIONS} --image="${IMAGE}" "${SERVICE_NAME}" 2>&1) 2>/dev/null; UPDATE_RETURN_VALUE=$? if [ "${UPDATE_RETURN_VALUE}" != 0 ]; then - # https://git.savannah.gnu.org/cgit/coreutils.git/tree/src/timeout.c + # When there is a timeout: + # * coreutils timeout returns 124: https://git.savannah.gnu.org/cgit/coreutils.git/tree/src/timeout.c + # * busybox timeout returns 143 local TIMEOUT_RETURN_CODE=124 + timeout --help 2>&1 | grep_q_i "BusyBox" && TIMEOUT_RETURN_CODE=143 local TIMEOUT_MSG="" if [ -n "${TIMEOUT_COMMAND}" ] && [ "${UPDATE_RETURN_VALUE}" = "${TIMEOUT_RETURN_CODE}" ]; then TIMEOUT_MSG="The return value ${UPDATE_RETURN_VALUE} indicates the job timed out." diff --git a/tests/README.md b/tests/README.md index b334374..bc72c2b 100644 --- a/tests/README.md +++ b/tests/README.md @@ -29,14 +29,11 @@ bash shellspec --jobs 50 To generate coverage (require [kcov](https://github.com/SimonKagstrom/kcov) installed): ``` -bash shellspec --kcov --tag coverage:true +bash shellspec --kcov ``` If you want to test a container image of *Gantry*, you need to specify the image of *Gantry* via the environment variable `GANTRY_TEST_CONTAINER_REPO_TAG`. ``` export GANTRY_TEST_CONTAINER_REPO_TAG=: -bash shellspec --tag "container_test:true" "coverage:true" +bash shellspec --jobs 50 ``` - -> NOTE: Negative tests will hang when testing a *Gantry* container, which may be due to a bug in shellspec. So when testing *Gantry* images, we should run only tests with tag `container_test:true`. - diff --git a/tests/gantry_cleanup_images_spec.sh b/tests/gantry_cleanup_images_spec.sh index 3189ed0..000aa2b 100644 --- a/tests/gantry_cleanup_images_spec.sh +++ b/tests/gantry_cleanup_images_spec.sh @@ -20,7 +20,7 @@ Describe 'cleanup-images' SUITE_NAME="cleanup-images" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_CLEANUP_IMAGES_false" "container_test:true" "coverage:true" + Describe "test_CLEANUP_IMAGES_false" TEST_NAME="test_CLEANUP_IMAGES_false" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -63,7 +63,7 @@ Describe 'cleanup-images' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_CLEANUP_IMAGES_OPTIONS_bad" "container_test:true" "coverage:true" + Describe "test_CLEANUP_IMAGES_OPTIONS_bad" TEST_NAME="test_CLEANUP_IMAGES_OPTIONS_bad" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -110,7 +110,7 @@ Describe 'cleanup-images' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_CLEANUP_IMAGES_OPTIONS_good" "container_test:true" "coverage:true" + Describe "test_CLEANUP_IMAGES_OPTIONS_good" TEST_NAME="test_CLEANUP_IMAGES_OPTIONS_good" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -156,7 +156,7 @@ Describe 'cleanup-images' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_IMAGES_TO_REMOVE_none_empty" "container_test:true" "coverage:true" + Describe "test_IMAGES_TO_REMOVE_none_empty" # Test the remove image entrypoint. To improve coverage. TEST_NAME="test_IMAGES_TO_REMOVE_none_empty" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") diff --git a/tests/gantry_common_options_spec.sh b/tests/gantry_common_options_spec.sh index f659d7d..0e8c70c 100644 --- a/tests/gantry_common_options_spec.sh +++ b/tests/gantry_common_options_spec.sh @@ -19,7 +19,7 @@ Describe 'common-options' SUITE_NAME="common-options" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_common_DOCKER_HOST_not_swarm_manager" "container_test:false" "coverage:true" + Describe "test_common_DOCKER_HOST_not_swarm_manager" TEST_NAME="test_common_DOCKER_HOST_not_swarm_manager" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -27,12 +27,8 @@ Describe 'common-options' local TEST_NAME="${1}" local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" - export DOCKER_HOST="8.8.8.8:53" - local RETURN_VALUE=0 + export GANTRY_TEST_DOCKER_HOST="8.8.8.8:53" run_gantry "${TEST_NAME}" - RETURN_VALUE="${?}" - export DOCKER_HOST= - return "${RETURN_VALUE}" } BeforeEach "common_setup_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" @@ -69,7 +65,7 @@ Describe 'common-options' The stderr should satisfy spec_expect_no_message "${SLEEP_SECONDS_BEFORE_NEXT_UPDATE}" End End - Describe "test_common_LOG_LEVEL_none" "container_test:true" "coverage:true" + Describe "test_common_LOG_LEVEL_none" TEST_NAME="test_common_LOG_LEVEL_none" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -93,10 +89,12 @@ Describe 'common-options' End End # Do not run test_common_no_new_env with the kcov, which alters the environment variables. - Describe "test_common_no_new_env" "container_test:false" "coverage:false" + Describe "test_common_no_new_env" # Check there is no new variable set, # to avoid errors like https://github.com/shizunge/gantry/issues/64#issuecomment-2475499085 - # We don't need to run this test using containers because we check env on the host, while the container test set env inside the container. + # + # It makes no sense to run run this test using containers because we check env on the host, while the container test set env inside the container. + # But it should not failed with a container. We are just testing GANTRY_LOG_LEVEL=WARN. TEST_NAME="test_common_no_new_env" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -111,16 +109,16 @@ Describe 'common-options' reset_gantry_env "${SERVICE_NAME}" # There should be no warnings or errors. So it should work the same as LOG_LEVLE=NONE. export GANTRY_LOG_LEVEL=WARN - - # Allow the following 3 mismatches used in log() function. - unset LOG_LEVEL NODE_NAME LOG_SCOPE - # _ contains the last command. declare is a bash builtin. - unset _; declare -p > "${ENV_BEFORE_RUN}" + declare -p > "${ENV_BEFORE_RUN}" run_gantry "${TEST_NAME}" - # Allow the following 3 mismatches used in log() function. - unset LOG_LEVEL NODE_NAME LOG_SCOPE - unset _; declare -p > "${ENV_AFTER_RUN}" - diff "${ENV_BEFORE_RUN}" "${ENV_AFTER_RUN}" + declare -p > "${ENV_AFTER_RUN}" + # Allow the 3 mismatches LOG_LEVEL NODE_NAME LOG_SCOPE used in log() function. + # Allow the 2 mismatches LINENO _ for kcov coverage. + for ALLOWED in LOG_LEVEL NODE_NAME LOG_SCOPE LINENO _; do + sed -i "s/^declare .* ${ALLOWED}=.*//" "${ENV_BEFORE_RUN}" + sed -i "s/^declare .* ${ALLOWED}=.*//" "${ENV_AFTER_RUN}" + done + diff --ignore-blank-lines "${ENV_BEFORE_RUN}" "${ENV_AFTER_RUN}" rm "${ENV_BEFORE_RUN}" rm "${ENV_AFTER_RUN}" } @@ -135,7 +133,7 @@ Describe 'common-options' The stderr should satisfy spec_expect_no_message ".+" End End - Describe "test_common_PRE_POST_RUN_CMD" "container_test:true" "coverage:true" + Describe "test_common_PRE_POST_RUN_CMD" TEST_NAME="test_common_PRE_POST_RUN_CMD" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -148,7 +146,7 @@ Describe 'common-options' # Test that pre-run command can change the global configurations. export GANTRY_PRE_RUN_CMD="echo \"Pre update\"; GANTRY_UPDATE_OPTIONS=--detach=true; GANTRY_CLEANUP_IMAGES=false;" # This command outputs multiple lines. - local POST_CMD="for I in \$(seq 3 5); do echo \"OUTPUT_LINE=\$I\"; done" + local POST_CMD="for I in \$(seq 3 5); do echo \"TEST_OUTPUT_MULTIPLE_LINES=\$I\"; done" # Test that the command returns a non-zero value. export GANTRY_POST_RUN_CMD="echo \"Post update\"; ${POST_CMD}; false;" run_gantry "${TEST_NAME}" @@ -162,8 +160,8 @@ Describe 'common-options' The stdout should satisfy spec_expect_no_message ".+" The stderr should satisfy display_output The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" - The stderr should satisfy spec_expect_message "Pre update" - The stderr should satisfy spec_expect_message "Finish pre-run command." + The stderr should satisfy spec_expect_message "Pre update$" + The stderr should satisfy spec_expect_message "Finish pre-run command.$" 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}" @@ -186,19 +184,16 @@ Describe 'common-options' The stderr should satisfy spec_expect_no_message "${REMOVED_IMAGE}.*" The stderr should satisfy spec_expect_no_message "${FAILED_TO_REMOVE_IMAGE}.*" The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" - The stderr should satisfy spec_expect_message "Post update" - The stderr should satisfy spec_expect_message "OUTPUT_LINE=3" - The stderr should satisfy spec_expect_message "OUTPUT_LINE=4" - The stderr should satisfy spec_expect_message "OUTPUT_LINE=5" - The stderr should satisfy spec_expect_message "Finish post-run command with a non-zero return value 1." + The stderr should satisfy spec_expect_message "Post update$" + The stderr should satisfy spec_expect_message "TEST_OUTPUT_MULTIPLE_LINES=3$" + The stderr should satisfy spec_expect_message "TEST_OUTPUT_MULTIPLE_LINES=4$" + The stderr should satisfy spec_expect_message "TEST_OUTPUT_MULTIPLE_LINES=5$" + The stderr should satisfy spec_expect_message "Finish post-run command with a non-zero return value 1.$" The stderr should satisfy spec_expect_no_message "${SCHEDULE_NEXT_UPDATE_AT}" The stderr should satisfy spec_expect_no_message "${SLEEP_SECONDS_BEFORE_NEXT_UPDATE}" End End - # run_gantry prints logs after gantry exists, while testing a container. - # In thes test, gantry never exit, but will be killed, thus there is no log. - # Therefore we disable the container test for this test. - Describe "test_common_SLEEP_SECONDS" "container_test:false" "coverage:true" + Describe "test_common_SLEEP_SECONDS" TEST_NAME="test_common_SLEEP_SECONDS" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -207,9 +202,11 @@ Describe 'common-options' local SERVICE_NAME="${2}" reset_gantry_env "${SERVICE_NAME}" export GANTRY_SLEEP_SECONDS="7" + # Run run_gantry in background. run_gantry "${TEST_NAME}" & local PID="${!}" sleep $((GANTRY_SLEEP_SECONDS*3+1)) + stop_gantry_container "${TEST_NAME}" kill "${PID}" } BeforeEach "common_setup_no_new_image ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" @@ -249,7 +246,7 @@ Describe 'common-options' The stderr should satisfy spec_expect_message "${SLEEP_SECONDS_BEFORE_NEXT_UPDATE}" End End - Describe "test_common_SLEEP_SECONDS_not_a_number" "container_test:false" "coverage:true" + Describe "test_common_SLEEP_SECONDS_not_a_number" TEST_NAME="test_common_SLEEP_SECONDS_not_a_number" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/gantry_filters_spec.sh b/tests/gantry_filters_spec.sh index d14ebcb..0715d20 100644 --- a/tests/gantry_filters_spec.sh +++ b/tests/gantry_filters_spec.sh @@ -19,7 +19,7 @@ Describe 'filters' SUITE_NAME="filters" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_SERVICES_FILTERS_bad" "container_test:false" "coverage:true" + Describe "test_SERVICES_FILTERS_bad" TEST_NAME="test_SERVICES_FILTERS_bad" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -64,7 +64,7 @@ Describe 'filters' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_SERVICES_EXCLUDED_multiple_services" "container_test:true" "coverage:true" + Describe "test_SERVICES_EXCLUDED_multiple_services" TEST_NAME="test_SERVICES_EXCLUDED_multiple_services" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -122,7 +122,7 @@ Describe 'filters' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_SERVICES_EXCLUDED_FILTERS_default" "container_test:true" "coverage:true" + Describe "test_SERVICES_EXCLUDED_FILTERS_default" TEST_NAME="test_SERVICES_EXCLUDED_FILTERS_default" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -173,7 +173,7 @@ Describe 'filters' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_SERVICES_EXCLUDED_FILTERS_bad" "container_test:false" "coverage:true" + Describe "test_SERVICES_EXCLUDED_FILTERS_bad" TEST_NAME="test_SERVICES_EXCLUDED_FILTERS_bad" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/gantry_jobs_spec.sh b/tests/gantry_jobs_spec.sh index 0bd26ae..0e447da 100644 --- a/tests/gantry_jobs_spec.sh +++ b/tests/gantry_jobs_spec.sh @@ -15,11 +15,11 @@ # along with this program. If not, see . # -Describe 'update-jobs' - SUITE_NAME="update-jobs" +Describe 'jobs' + SUITE_NAME="jobs" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_jobs_skipping" "container_test:true" "coverage:true" + Describe "test_jobs_skipping" # For `docker service ls --filter`, the name filter matches on all or the prefix of a service's name # See https://docs.docker.com/engine/reference/commandline/service_ls/#name # It does not do the exact match of the name. See https://github.com/moby/moby/issues/32985 @@ -64,11 +64,11 @@ Describe 'update-jobs' The stderr should satisfy spec_expect_no_message "${PERFORM_UPDATING}.*${SERVICE_NAME_SUFFIX}" The stderr should satisfy spec_expect_message "${SKIP_UPDATING}.*${SERVICE_NAME}.*${SKIP_REASON_CURRENT_IS_LATEST}" The stderr should satisfy spec_expect_no_message "${PERFORM_UPDATING}.*${SERVICE_NAME}" - The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" The stderr should satisfy spec_expect_message "${NUM_SERVICES_SKIP_JOBS}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}" The stderr should satisfy spec_expect_message "${NUM_SERVICES_NO_NEW_IMAGES}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_UPDATING}" + The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" 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_no_message "${ROLLING_BACK}.*${SERVICE_NAME}" @@ -86,7 +86,7 @@ Describe 'update-jobs' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_jobs_UPDATE_JOBS_true" "container_test:true" "coverage:true" + Describe "test_jobs_UPDATE_JOBS_true" TEST_NAME="test_jobs_UPDATE_JOBS_true" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -113,12 +113,12 @@ Describe 'update-jobs' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" 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 "${SET_TIMEOUT_TO}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" 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.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" 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}" @@ -137,7 +137,7 @@ Describe 'update-jobs' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_jobs_label_UPDATE_JOBS_true" "container_test:true" "coverage:true" + Describe "test_jobs_label_UPDATE_JOBS_true" TEST_NAME="test_jobs_label_UPDATE_JOBS_true" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -170,12 +170,12 @@ Describe 'update-jobs' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" 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 "${SET_TIMEOUT_TO}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" 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.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" 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}" @@ -194,7 +194,7 @@ Describe 'update-jobs' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_jobs_no_running_tasks" "container_test:true" "coverage:true" + Describe "test_jobs_no_running_tasks" TEST_NAME="test_jobs_no_running_tasks" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -231,11 +231,11 @@ Describe 'update-jobs' The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--replicas=0" 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 "${SET_TIMEOUT_TO}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" 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_no_message "${SET_TIMEOUT_TO}" 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}" @@ -253,4 +253,4 @@ Describe 'update-jobs' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End -End # Describe 'update-jobs' +End # Describe 'jobs' diff --git a/tests/gantry_login_docker_config_spec.sh b/tests/gantry_login_docker_config_spec.sh index d8a14db..09e9754 100644 --- a/tests/gantry_login_docker_config_spec.sh +++ b/tests/gantry_login_docker_config_spec.sh @@ -31,15 +31,18 @@ # D=1 C=1 L=0 test_login_docker_config_no_label # D=1 C=1 L=1 test_login_docker_config_label_override SERVICE_NAME1 -Describe 'login_docker_config' - SUITE_NAME="login_docker_config" +Describe 'login-docker-config' + SUITE_NAME="login-docker-config" BeforeAll "initialize_all_tests ${SUITE_NAME} ENFORCE_LOGIN" AfterAll "finish_all_tests ${SUITE_NAME} ENFORCE_LOGIN" - Describe "test_login_docker_config_no_label" "container_test:true" "coverage:true" + Describe "test_login_docker_config_no_label" TEST_NAME="test_login_docker_config_no_label" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_docker_config_no_label() { local TEST_NAME="${1}" @@ -52,7 +55,7 @@ Describe 'login_docker_config' local USER_FILE=; USER_FILE=$(mktemp); echo "${USERNAME}" > "${USER_FILE}"; local PASS_FILE=; PASS_FILE=$(mktemp); echo "${PASSWORD}" > "${PASS_FILE}"; reset_gantry_env "${SERVICE_NAME}" - export DOCKER_CONFIG="${CONFIG}" + export GANTRY_TEST_DOCKER_CONFIG="${CONFIG}" export GANTRY_REGISTRY_CONFIG="${CONFIG}" export GANTRY_REGISTRY_HOST="${REGISTRY}" export GANTRY_REGISTRY_PASSWORD_FILE="${PASS_FILE}" @@ -68,14 +71,14 @@ Describe 'login_docker_config' 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_docker_config_no_label "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_docker_config_no_label "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" The stderr should satisfy display_output The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" The stderr should satisfy spec_expect_no_message "${LOGGED_INTO_REGISTRY}.*${DEFAULT_CONFIGURATION}" - The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" The stderr should satisfy spec_expect_no_message "${CONFIG_IS_NOT_A_DIRECTORY}" The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" @@ -106,11 +109,14 @@ Describe 'login_docker_config' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_docker_config_default_config" "container_test:true" "coverage:true" + Describe "test_login_docker_config_default_config" TEST_NAME="test_login_docker_config_default_config" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_docker_config_default_config() { local TEST_NAME="${1}" @@ -124,7 +130,7 @@ Describe 'login_docker_config' local PASS_FILE=; PASS_FILE=$(mktemp); echo "${PASSWORD}" > "${PASS_FILE}"; # Do not set GANTRY_AUTH_CONFIG_LABEL on the service. reset_gantry_env "${SERVICE_NAME}" - export DOCKER_CONFIG="${CONFIG}" + export GANTRY_TEST_DOCKER_CONFIG="${CONFIG}" # Do not set GANTRY_REGISTRY_CONFIG to login to the default configuration. export GANTRY_REGISTRY_HOST="${REGISTRY}" export GANTRY_REGISTRY_PASSWORD_FILE="${PASS_FILE}" @@ -141,7 +147,7 @@ Describe 'login_docker_config' 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_docker_config_default_config "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_docker_config_default_config "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" @@ -177,14 +183,17 @@ Describe 'login_docker_config' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_docker_config_label_override" "container_test:false" "coverage:true" + Describe "test_login_docker_config_label_override" TEST_NAME="test_login_docker_config_label_override" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") SERVICE_NAME0="${SERVICE_NAME}-0" SERVICE_NAME1="${SERVICE_NAME}-1" SERVICE_NAME2="${SERVICE_NAME}-2" - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_start() { local TEST_NAME="${1}" @@ -218,7 +227,7 @@ Describe 'login_docker_config' docker_service_update --label-add "${GANTRY_AUTH_CONFIG_LABEL}=${CONFIG}" "${SERVICE_NAME1}" reset_gantry_env "${SERVICE_NAME}" # Inspection and updating should use DOCKER_CONFIG or the label. - export DOCKER_CONFIG="${CONFIG}" + export GANTRY_TEST_DOCKER_CONFIG="${CONFIG}" export GANTRY_REGISTRY_CONFIGS_FILE="${CONFIGS_FILE}" # Set GANTRY_CLEANUP_IMAGES="false" to speedup the test. We are not testing removing image here. export GANTRY_CLEANUP_IMAGES="false" @@ -241,21 +250,21 @@ Describe 'login_docker_config' BeforeEach "test_start ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "test_end ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_login_docker_config_label_override "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_docker_config_label_override "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" The stderr should satisfy display_output The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" - The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" - The stderr should satisfy spec_expect_message "incorrect-${CONFIG}.*${CONFIG_IS_NOT_A_DIRECTORY}" + The stderr should satisfy spec_expect_message "incorrect-${AUTH_CONFIG}.*${CONFIG_IS_NOT_A_DIRECTORY}" # Check warnings The stderr should satisfy spec_expect_message "${THERE_ARE_NUM_CONFIGURATIONS}.*" The stderr should satisfy spec_expect_message "${USER_LOGGED_INTO_DEFAULT}.*" - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config incorrect-${CONFIG}.*${SERVICE_NAME0}" - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*${SERVICE_NAME1}" - The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*${SERVICE_NAME2}" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config incorrect-${AUTH_CONFIG}.*${SERVICE_NAME0}" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*${SERVICE_NAME1}" + The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*${SERVICE_NAME2}" The stderr should satisfy spec_expect_no_message "${PERFORM_UPDATING}.*${SERVICE_NAME0}.*" The stderr should satisfy spec_expect_message "${SKIP_UPDATING}.*${SERVICE_NAME0}.*${SKIP_REASON_MANIFEST_FAILURE}" The stderr should satisfy spec_expect_message "${PERFORM_UPDATING}.*${SERVICE_NAME1}.*${PERFORM_REASON_HAS_NEWER_IMAGE}" @@ -296,4 +305,4 @@ Describe 'login_docker_config' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End -End # Describe 'login_docker_config' +End # Describe 'login-docker-config' diff --git a/tests/gantry_login_negative_spec.sh b/tests/gantry_login_negative_spec.sh index 6db85d2..da6b932 100644 --- a/tests/gantry_login_negative_spec.sh +++ b/tests/gantry_login_negative_spec.sh @@ -15,15 +15,18 @@ # along with this program. If not, see . # -Describe 'login_negative' - SUITE_NAME="login_negative" +Describe 'login-negative' + SUITE_NAME="login-negative" BeforeAll "initialize_all_tests ${SUITE_NAME} ENFORCE_LOGIN" AfterAll "finish_all_tests ${SUITE_NAME} ENFORCE_LOGIN" - Describe "test_login_no_login" "container_test:false" "coverage:true" + Describe "test_login_no_login" TEST_NAME="test_login_no_login" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_no_login() { local TEST_NAME="${1}" @@ -34,7 +37,7 @@ Describe 'login_negative' 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_no_login "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_no_login "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" @@ -70,11 +73,14 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_incorrect_password" "container_test:false" "coverage:true" + Describe "test_login_incorrect_password" TEST_NAME="test_login_incorrect_password" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_incorrect_password() { local TEST_NAME="${1}" @@ -104,14 +110,14 @@ Describe 'login_negative' 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_incorrect_password "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_incorrect_password "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" The stderr should satisfy display_output The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" The stderr should satisfy spec_expect_no_message "${LOGGED_INTO_REGISTRY}" - The stderr should satisfy spec_expect_message "${FAILED_TO_LOGIN_TO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${FAILED_TO_LOGIN_TO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${CONFIG_IS_NOT_A_DIRECTORY}" The stderr should satisfy spec_expect_message "${SKIP_UPDATING_ALL}.*${SKIP_REASON_PREVIOUS_ERRORS}" The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" @@ -139,11 +145,11 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_read_only_file" "container_test:false" "coverage:true" + Describe "test_login_read_only_file" TEST_NAME="test_login_read_only_file" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + AUTH_CONFIG=$(mktemp -d) TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_read_only_file() { local TEST_NAME="${1}" @@ -153,13 +159,16 @@ Describe 'login_negative' local USERNAME="${5}" local PASSWORD="${6}" check_login_input "${REGISTRY}" "${USERNAME}" "${PASSWORD}" || return 1; - # Set the config folder to read only. (It won't work for container_test) + # When running with an image, we are not changing the folder inside the contianer. + # So do not run the test with a container/image. mkdir -p "${CONFIG}" chmod 444 "${CONFIG}" local USER_FILE=; USER_FILE=$(mktemp); echo "${USERNAME}" > "${USER_FILE}"; local PASS_FILE=; PASS_FILE=$(mktemp); echo "${PASSWORD}" > "${PASS_FILE}"; docker_service_update --label-add "${GANTRY_AUTH_CONFIG_LABEL}=${CONFIG}" "${SERVICE_NAME}" reset_gantry_env "${SERVICE_NAME}" + # Use GANTRY_TEST_HOST_TO_CONTAINER to mount the file from host to the container. + export GANTRY_TEST_HOST_TO_CONTAINER="${CONFIG}" export GANTRY_REGISTRY_CONFIG="${CONFIG}" export GANTRY_REGISTRY_HOST="${REGISTRY}" export GANTRY_REGISTRY_PASSWORD_FILE="${PASS_FILE}" @@ -169,20 +178,20 @@ Describe 'login_negative' RETURN_VALUE="${?}" rm "${USER_FILE}" rm "${PASS_FILE}" - [ -d "${CONFIG}" ] && chmod 777 "${CONFIG}" && rm -r "${CONFIG}" + # [ -d "${CONFIG}" ] && chmod 777 "${CONFIG}" && rm -r "${CONFIG}" return "${RETURN_VALUE}" } 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_read_only_file "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_read_only_file "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" The stderr should satisfy display_output The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" The stderr should satisfy spec_expect_no_message "${LOGGED_INTO_REGISTRY}" - The stderr should satisfy spec_expect_message "${FAILED_TO_LOGIN_TO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${FAILED_TO_LOGIN_TO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${CONFIG_IS_NOT_A_DIRECTORY}" The stderr should satisfy spec_expect_message "${SKIP_UPDATING_ALL}.*${SKIP_REASON_PREVIOUS_ERRORS}" The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" @@ -210,11 +219,14 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_config_mismatch_default" "container_test:false" "coverage:true" + Describe "test_login_config_mismatch_default" TEST_NAME="test_login_config_mismatch_default" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_config_mismatch_default() { local TEST_NAME="${1}" @@ -254,21 +266,21 @@ Describe 'login_negative' 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_mismatch_default "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_config_mismatch_default "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" The stderr should satisfy display_output The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${DEFAULT_CONFIGURATION}" - The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" - The stderr should satisfy spec_expect_message "incorrect-${CONFIG}.*${CONFIG_IS_NOT_A_DIRECTORY}" + The stderr should satisfy spec_expect_message "incorrect-${AUTH_CONFIG}.*${CONFIG_IS_NOT_A_DIRECTORY}" # Check warnings The stderr should satisfy spec_expect_message "${THERE_ARE_NUM_CONFIGURATIONS}.*" The stderr should satisfy spec_expect_message "${USER_LOGGED_INTO_DEFAULT}.*" - The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*" - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config incorrect-${CONFIG}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config incorrect-${AUTH_CONFIG}.*${SERVICE_NAME}" 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}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" @@ -295,11 +307,14 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_config_mismatch_no_default" "container_test:false" "coverage:true" + Describe "test_login_config_mismatch_no_default" TEST_NAME="test_login_config_mismatch_no_default" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_config_mismatch_no_default() { local TEST_NAME="${1}" @@ -332,22 +347,22 @@ Describe 'login_negative' 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_mismatch_no_default "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_config_mismatch_no_default "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" The stderr should satisfy display_output The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" The stderr should satisfy spec_expect_no_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${DEFAULT_CONFIGURATION}" - The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" - The stderr should satisfy spec_expect_message "incorrect-${CONFIG}.*${CONFIG_IS_NOT_A_DIRECTORY}" + The stderr should satisfy spec_expect_message "incorrect-${AUTH_CONFIG}.*${CONFIG_IS_NOT_A_DIRECTORY}" # Check warnings The stderr should satisfy spec_expect_message "${THERE_ARE_NUM_CONFIGURATIONS}.*" # This message does not present, because we don't login with the default configuration. The stderr should satisfy spec_expect_no_message "${USER_LOGGED_INTO_DEFAULT}.*" - The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*" - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config incorrect-${CONFIG}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config incorrect-${AUTH_CONFIG}.*${SERVICE_NAME}" 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}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" @@ -374,7 +389,7 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_multi_services_no_label" "container_test:false" "coverage:true" + Describe "test_login_multi_services_no_label" # To test https://github.com/shizunge/gantry/issues/64#issuecomment-2475499085 TEST_NAME="test_login_multi_services_no_label" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") @@ -383,7 +398,10 @@ Describe 'login_negative' IMAGE_WITH_TAG1="${IMAGE_WITH_TAG}-1" SERVICE_NAME0="${SERVICE_NAME}-0" SERVICE_NAME1="${SERVICE_NAME}-1" - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_start() { local TEST_NAME="${1}" @@ -446,16 +464,16 @@ Describe 'login_negative' BeforeEach "test_start ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" AfterEach "test_end ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' - When run test_login_multi_services_no_label "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_multi_services_no_label "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" The stderr should satisfy display_output The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" - The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" - The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*${SERVICE_NAME0}" - The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${CONFIG}.*${SERVICE_NAME1}" + The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*${SERVICE_NAME0}" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*${SERVICE_NAME1}" The stderr should satisfy spec_expect_no_message "${PERFORM_UPDATING}.*${SERVICE_NAME0}.*" The stderr should satisfy spec_expect_message "${SKIP_UPDATING}.*${SERVICE_NAME0}.*${SKIP_REASON_MANIFEST_FAILURE}" The stderr should satisfy spec_expect_message "${PERFORM_UPDATING}.*${SERVICE_NAME1}.*${PERFORM_REASON_HAS_NEWER_IMAGE}" @@ -489,11 +507,14 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_REGISTRY_CONFIGS_FILE_bad_format" "container_test:false" "coverage:true" + Describe "test_login_REGISTRY_CONFIGS_FILE_bad_format" TEST_NAME="test_login_REGISTRY_CONFIGS_FILE_bad_format" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_REGISTRY_CONFIGS_FILE_bad_format() { local TEST_NAME="${1}" @@ -522,7 +543,7 @@ Describe 'login_negative' 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}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_REGISTRY_CONFIGS_FILE_bad_format "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" @@ -530,7 +551,7 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" The stderr should satisfy spec_expect_message "format error.*Found extra item\(s\)" The stderr should satisfy spec_expect_message "format error.*Missing item\(s\)" - The stderr should satisfy spec_expect_no_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_no_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" The stderr should satisfy spec_expect_no_message "${CONFIG_IS_NOT_A_DIRECTORY}" The stderr should satisfy spec_expect_message "${SKIP_UPDATING_ALL}.*${SKIP_REASON_PREVIOUS_ERRORS}" @@ -559,11 +580,14 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_file_not_exist" "container_test:false" "coverage:true" + Describe "test_login_file_not_exist" TEST_NAME="test_login_file_not_exist" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_file_not_exist() { local TEST_NAME="${1}" @@ -590,13 +614,13 @@ Describe 'login_negative' 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}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_file_not_exist "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" The stderr should satisfy display_output The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" - The stderr should satisfy spec_expect_no_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_no_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" The stderr should satisfy spec_expect_no_message "${CONFIG_IS_NOT_A_DIRECTORY}" The stderr should satisfy spec_expect_message "${SKIP_UPDATING_ALL}.*${SKIP_REASON_PREVIOUS_ERRORS}" @@ -625,4 +649,4 @@ Describe 'login_negative' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End -End # Describe 'login_negative' +End # Describe 'login-negative' diff --git a/tests/gantry_login_spec.sh b/tests/gantry_login_spec.sh index 4c26906..c6d02ed 100644 --- a/tests/gantry_login_spec.sh +++ b/tests/gantry_login_spec.sh @@ -22,11 +22,14 @@ Describe 'login' SUITE_NAME="login" BeforeAll "initialize_all_tests ${SUITE_NAME} ENFORCE_LOGIN" AfterAll "finish_all_tests ${SUITE_NAME} ENFORCE_LOGIN" - Describe "test_login_config" "container_test:true" "coverage:true" + Describe "test_login_config" TEST_NAME="test_login_config" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_config() { local TEST_NAME="${1}" @@ -58,14 +61,14 @@ 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}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_config "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" The stderr should satisfy display_output The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" The stderr should satisfy spec_expect_no_message "${LOGGED_INTO_REGISTRY}.*${DEFAULT_CONFIGURATION}" - The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" The stderr should satisfy spec_expect_no_message "${CONFIG_IS_NOT_A_DIRECTORY}" The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" @@ -74,7 +77,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}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*${SERVICE_NAME}" # 2 "--with-registry-auth" for SERVICE_NAME. One is automatically added. The other is from user. The stderr should satisfy spec_expect_message "${ADDING_OPTIONS_WITH_REGISTRY_AUTH}.*automatically.*${SERVICE_NAME}" The stderr should satisfy spec_expect_message "${ADDING_OPTIONS_WITH_REGISTRY_AUTH}.*specified by user.*${SERVICE_NAME}" @@ -96,11 +99,11 @@ Describe 'login' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_default_config" "container_test:true" "coverage:true" + Describe "test_login_default_config" TEST_NAME="test_login_default_config" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="NotUsed" + AUTH_CONFIG="NotUsed" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_default_config() { local TEST_NAME="${1}" @@ -130,7 +133,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_default_config "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_default_config "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" @@ -166,11 +169,14 @@ Describe 'login' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_REGISTRY_CONFIGS_FILE" "container_test:true" "coverage:true" + Describe "test_login_REGISTRY_CONFIGS_FILE" TEST_NAME="test_login_REGISTRY_CONFIGS_FILE" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="C$(unique_id)" + # When running with an Gantry image, docker buildx writes files to this folder which are owned by root. + # Using a relative path, this the container will not write to the folder on the host. + # So do not use an absolute path, otherwise we cannot remove this folder on the host. + AUTH_CONFIG="C$(unique_id)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_REGISTRY_CONFIGS_FILE() { local TEST_NAME="${1}" @@ -204,14 +210,14 @@ 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}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_REGISTRY_CONFIGS_FILE "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" The stderr should satisfy display_output The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" The stderr should satisfy spec_expect_no_message "${LOGGED_INTO_REGISTRY}.*${DEFAULT_CONFIGURATION}" - The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${CONFIG}" + The stderr should satisfy spec_expect_message "${LOGGED_INTO_REGISTRY}.*${TEST_REGISTRY}.*${AUTH_CONFIG}" The stderr should satisfy spec_expect_no_message "${FAILED_TO_LOGIN_TO_REGISTRY}" The stderr should satisfy spec_expect_no_message "${CONFIG_IS_NOT_A_DIRECTORY}" The stderr should satisfy spec_expect_no_message "${SKIP_UPDATING}.*${SERVICE_NAME}" @@ -220,7 +226,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}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_message "${ADDING_OPTIONS}.*--config ${AUTH_CONFIG}.*${SERVICE_NAME}" # Gantry adds --with-registry-auth for finding GANTRY_AUTH_CONFIG_LABEL on the service. The stderr should satisfy spec_expect_message "${ADDING_OPTIONS_WITH_REGISTRY_AUTH}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${THERE_ARE_ADDITIONAL_MESSAGES}.*${SERVICE_NAME}.*" @@ -241,11 +247,11 @@ Describe 'login' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_login_external_config" "container_test:true" "coverage:true" + Describe "test_login_external_config" TEST_NAME="test_login_external_config" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") - CONFIG="$(mktemp -d)" + AUTH_CONFIG="$(mktemp -d)" TEST_REGISTRY=$(load_test_registry "${SUITE_NAME}") || return 1 test_login_external_config() { local TEST_NAME="${1}" @@ -260,7 +266,7 @@ Describe 'login' chmod 555 "${CONFIG}" # Do not set GANTRY_AUTH_CONFIG_LABEL on service. reset_gantry_env "${SERVICE_NAME}" - export DOCKER_CONFIG="${CONFIG}" + export GANTRY_TEST_DOCKER_CONFIG="${CONFIG}" # Use manifest to avoid write to DOCKER_CONFIG. # When running container test, Gantry runs as root. # We cannot remove DOCKER_CONFIG when it containes data from root. @@ -276,7 +282,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_external_config "${TEST_NAME}" "${SERVICE_NAME}" "${CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" + When run test_login_external_config "${TEST_NAME}" "${SERVICE_NAME}" "${AUTH_CONFIG}" "${TEST_REGISTRY}" "${TEST_USERNAME}" "${TEST_PASSWORD}" The status should be success The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" diff --git a/tests/gantry_manifest_spec.sh b/tests/gantry_manifest_spec.sh index d79ca32..e7152ba 100644 --- a/tests/gantry_manifest_spec.sh +++ b/tests/gantry_manifest_spec.sh @@ -19,7 +19,7 @@ Describe 'manifest-command' SUITE_NAME="manifest-command" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_MANIFEST_CMD_none" "container_test:true" "coverage:true" + Describe "test_MANIFEST_CMD_none" TEST_NAME="test_MANIFEST_CMD_none" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -70,7 +70,7 @@ Describe 'manifest-command' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_MANIFEST_CMD_none_SERVICES_SELF" "container_test:true" "coverage:true" + Describe "test_MANIFEST_CMD_none_SERVICES_SELF" TEST_NAME="test_MANIFEST_CMD_none_SERVICES_SELF" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -118,7 +118,7 @@ Describe 'manifest-command' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_MANIFEST_CMD_manifest" "container_test:true" "coverage:true" + Describe "test_MANIFEST_CMD_manifest" TEST_NAME="test_MANIFEST_CMD_manifest" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -163,7 +163,7 @@ Describe 'manifest-command' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_MANIFEST_CMD_label" "container_test:true" "coverage:true" + Describe "test_MANIFEST_CMD_label" TEST_NAME="test_MANIFEST_CMD_label" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -213,7 +213,7 @@ Describe 'manifest-command' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_MANIFEST_CMD_unsupported_cmd" "container_test:false" "coverage:true" + Describe "test_MANIFEST_CMD_unsupported_cmd" TEST_NAME="test_MANIFEST_CMD_unsupported_cmd" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -260,7 +260,7 @@ Describe 'manifest-command' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_MANIFEST_CMD_failure" "container_test:false" "coverage:true" + Describe "test_MANIFEST_CMD_failure" TEST_NAME="test_MANIFEST_CMD_failure" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/gantry_notify_spec.sh b/tests/gantry_notify_spec.sh index 02dacdd..a3556f9 100644 --- a/tests/gantry_notify_spec.sh +++ b/tests/gantry_notify_spec.sh @@ -69,7 +69,7 @@ Describe 'notify' SUITE_NAME="notify" BeforeAll "_notify_before_all ${SUITE_NAME}" AfterAll "_notify_after_all ${SUITE_NAME}" - Describe "test_notify_apprise" "container_test:true" "coverage:true" + Describe "test_notify_apprise" TEST_NAME="test_notify_apprise" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -120,7 +120,7 @@ Describe 'notify' The stderr should satisfy spec_expect_message "${SEND_NOTIFY_APPRISE}" End End - Describe "test_notify_apprise_no_new_image" "container_test:true" "coverage:true" + Describe "test_notify_apprise_no_new_image" TEST_NAME="test_notify_apprise_no_new_image" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -172,7 +172,7 @@ Describe 'notify' The stderr should satisfy spec_expect_message "${SEND_NOTIFY_APPRISE}" End End - Describe "test_notify_apprise_bad_url" "container_test:true" "coverage:true" + Describe "test_notify_apprise_bad_url" TEST_NAME="test_notify_apprise_bad_url" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -217,7 +217,7 @@ Describe 'notify' The stderr should satisfy spec_expect_message "Failed to send notification via Apprise" End End - Describe "test_notify_on_change_new_image" "container_test:true" "coverage:true" + Describe "test_notify_on_change_new_image" TEST_NAME="test_notify_on_change_new_image" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -269,7 +269,7 @@ Describe 'notify' The stderr should satisfy spec_expect_message "${SEND_NOTIFY_APPRISE}" End End - Describe "test_notify_on_change_no_updates" "container_test:true" "coverage:true" + Describe "test_notify_on_change_no_updates" TEST_NAME="test_notify_on_change_no_updates" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -320,7 +320,7 @@ Describe 'notify' The stderr should satisfy spec_expect_message "${SKIP_SENDING_NOTIFICATION}" End End - Describe "test_notify_on_change_errors" "container_test:false" "coverage:true" + Describe "test_notify_on_change_errors" TEST_NAME="test_notify_on_change_errors" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/gantry_parallel_spec.sh b/tests/gantry_parallel_spec.sh index b1f77ab..7e8dd4b 100644 --- a/tests/gantry_parallel_spec.sh +++ b/tests/gantry_parallel_spec.sh @@ -19,7 +19,7 @@ Describe 'service-parallel' SUITE_NAME="service-parallel" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_parallel_less_workers" "container_test:true" "coverage:true" + Describe "test_parallel_less_workers" TEST_NAME="test_parallel_less_workers" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -85,7 +85,7 @@ Describe 'service-parallel' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_parallel_more_workers" "container_test:true" "coverage:true" + Describe "test_parallel_more_workers" TEST_NAME="test_parallel_more_workers" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -132,7 +132,7 @@ Describe 'service-parallel' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_parallel_GANTRY_MANIFEST_NUM_WORKERS_not_a_number" "container_test:false" "coverage:true" + Describe "test_parallel_GANTRY_MANIFEST_NUM_WORKERS_not_a_number" TEST_NAME="test_parallel_GANTRY_MANIFEST_NUM_WORKERS_not_a_number" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -176,7 +176,7 @@ Describe 'service-parallel' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_parallel_GANTRY_UPDATE_NUM_WORKERS_not_a_number" "container_test:false" "coverage:true" + Describe "test_parallel_GANTRY_UPDATE_NUM_WORKERS_not_a_number" TEST_NAME="test_parallel_GANTRY_UPDATE_NUM_WORKERS_not_a_number" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/gantry_rollback_spec.sh b/tests/gantry_rollback_spec.sh index 0e561bf..81288c3 100644 --- a/tests/gantry_rollback_spec.sh +++ b/tests/gantry_rollback_spec.sh @@ -19,7 +19,7 @@ Describe 'rollback' SUITE_NAME="rollback" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_rollback_due_to_timeout" "container_test:false" "coverage:true" + Describe "test_rollback_due_to_timeout" TEST_NAME="test_rollback_due_to_timeout" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -44,12 +44,12 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" 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_message "${SET_TIMEOUT_TO} ${TIMEOUT}.*${SERVICE_NAME}" - The stderr should satisfy spec_expect_message "${RETURN_VALUE_INDICATES_TIMEOUT}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" 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 "${SET_TIMEOUT_TO} ${TIMEOUT}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_message "${RETURN_VALUE_INDICATES_TIMEOUT}" 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_no_message "${ADDING_OPTIONS}" @@ -68,7 +68,7 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_rollback_failed" "container_test:false" "coverage:true" + Describe "test_rollback_failed" TEST_NAME="test_rollback_failed" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -96,12 +96,12 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" 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_message "${SET_TIMEOUT_TO} ${TIMEOUT}.*${SERVICE_NAME}" - The stderr should satisfy spec_expect_message "${RETURN_VALUE_INDICATES_TIMEOUT}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" 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 "${SET_TIMEOUT_TO} ${TIMEOUT}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_message "${RETURN_VALUE_INDICATES_TIMEOUT}" 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}.*--with-registry-auth.*${SERVICE_NAME}" @@ -120,7 +120,7 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_rollback_ROLLBACK_ON_FAILURE_false" "container_test:false" "coverage:true" + Describe "test_rollback_ROLLBACK_ON_FAILURE_false" TEST_NAME="test_rollback_ROLLBACK_ON_FAILURE_false" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -146,12 +146,12 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" 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_message "${SET_TIMEOUT_TO} ${TIMEOUT}.*${SERVICE_NAME}" - The stderr should satisfy spec_expect_message "${RETURN_VALUE_INDICATES_TIMEOUT}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" 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 "${SET_TIMEOUT_TO} ${TIMEOUT}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_message "${RETURN_VALUE_INDICATES_TIMEOUT}" 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_no_message "${ADDING_OPTIONS}" @@ -170,7 +170,7 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_rollback_label_failed" "container_test:false" "coverage:true" + Describe "test_rollback_label_failed" TEST_NAME="test_rollback_label_failed" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -201,12 +201,12 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" 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_message "${SET_TIMEOUT_TO} ${TIMEOUT}.*${SERVICE_NAME}" - The stderr should satisfy spec_expect_message "${RETURN_VALUE_INDICATES_TIMEOUT}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" 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 "${SET_TIMEOUT_TO} ${TIMEOUT}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_message "${RETURN_VALUE_INDICATES_TIMEOUT}" 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}.*--with-registry-auth.*${SERVICE_NAME}" @@ -225,7 +225,7 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_rollback_label_ROLLBACK_ON_FAILURE_false" "container_test:false" "coverage:true" + Describe "test_rollback_label_ROLLBACK_ON_FAILURE_false" TEST_NAME="test_rollback_label_ROLLBACK_ON_FAILURE_false" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -253,12 +253,12 @@ Describe 'rollback' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" 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_message "${SET_TIMEOUT_TO} ${TIMEOUT}.*${SERVICE_NAME}" - The stderr should satisfy spec_expect_message "${RETURN_VALUE_INDICATES_TIMEOUT}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" 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 "${SET_TIMEOUT_TO} ${TIMEOUT}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_message "${RETURN_VALUE_INDICATES_TIMEOUT}" 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_no_message "${ADDING_OPTIONS}" diff --git a/tests/gantry_service_multiple_spec.sh b/tests/gantry_service_multiple_spec.sh index 1da1dfa..80ea6c3 100644 --- a/tests/gantry_service_multiple_spec.sh +++ b/tests/gantry_service_multiple_spec.sh @@ -19,7 +19,7 @@ Describe 'service-multiple-services' SUITE_NAME="service-multiple-services" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_multiple_services_excluded_filters" "container_test:true" "coverage:true" + Describe "test_multiple_services_excluded_filters" TEST_NAME="test_multiple_services_excluded_filters" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/gantry_service_no_running_tasks_spec.sh b/tests/gantry_service_no_running_tasks_spec.sh index f39be20..0ddd2ae 100644 --- a/tests/gantry_service_no_running_tasks_spec.sh +++ b/tests/gantry_service_no_running_tasks_spec.sh @@ -19,7 +19,7 @@ Describe "service-no-running-tasks" SUITE_NAME="service-no-running-tasks" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_no_running_tasks_replicated" "container_test:true" "coverage:true" + Describe "test_no_running_tasks_replicated" # For `docker service ls --filter`, the name filter matches on all or the prefix of a service's name # See https://docs.docker.com/engine/reference/commandline/service_ls/#name # It does not do the exact match of the name. See https://github.com/moby/moby/issues/32985 @@ -99,7 +99,7 @@ Describe "service-no-running-tasks" The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_no_running_tasks_global" "container_test:true" "coverage:true" + Describe "test_no_running_tasks_global" TEST_NAME="test_no_running_tasks_global" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") diff --git a/tests/gantry_service_single_spec.sh b/tests/gantry_service_single_spec.sh index 9daeb2b..492ec7a 100644 --- a/tests/gantry_service_single_spec.sh +++ b/tests/gantry_service_single_spec.sh @@ -19,7 +19,7 @@ Describe 'service-single-service' SUITE_NAME="service-single-service" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_new_image_no" "container_test:true" "coverage:true" + Describe "test_new_image_no" TEST_NAME="test_new_image_no" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -40,12 +40,13 @@ Describe 'service-single-service' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" The stderr should satisfy spec_expect_message "${SKIP_UPDATING}.*${SERVICE_NAME}.*${SKIP_REASON_CURRENT_IS_LATEST}" The stderr should satisfy spec_expect_no_message "${PERFORM_UPDATING}.*${SERVICE_NAME}" - The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_INSPECT_FAILURE}" The stderr should satisfy spec_expect_message "${NUM_SERVICES_NO_NEW_IMAGES}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_UPDATING}" The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}" + The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" + The stderr should satisfy spec_expect_no_message "${RETURN_VALUE_INDICATES_TIMEOUT}" The stderr should satisfy spec_expect_no_message "${THERE_ARE_ADDITIONAL_MESSAGES}.*${SERVICE_NAME}.*" The stderr should satisfy spec_expect_no_message "${UPDATED}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}" @@ -65,7 +66,7 @@ Describe 'service-single-service' The stderr should satisfy spec_expect_no_message "${SCHEDULE_NEXT_UPDATE_AT}" End End - Describe "test_new_image_yes" "container_test:true" "coverage:true" + Describe "test_new_image_yes" TEST_NAME="test_new_image_yes" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -86,12 +87,13 @@ Describe 'service-single-service' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" 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 "${SET_TIMEOUT_TO}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" 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_no_message "${ADDING_OPTIONS}" + The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" + The stderr should satisfy spec_expect_no_message "${RETURN_VALUE_INDICATES_TIMEOUT}" The stderr should satisfy spec_expect_no_message "${THERE_ARE_ADDITIONAL_MESSAGES}.*${SERVICE_NAME}.*" The stderr should satisfy spec_expect_message "${UPDATED}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}" @@ -111,7 +113,7 @@ Describe 'service-single-service' The stderr should satisfy spec_expect_no_message "${SCHEDULE_NEXT_UPDATE_AT}" End End - Describe "test_new_image_no_digest" "container_test:true" "coverage:true" + Describe "test_new_image_no_digest" TEST_NAME="test_new_image_no_digest" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -142,12 +144,13 @@ Describe 'service-single-service' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" 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_DIGEST_IS_EMPTY}" - The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" 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_no_message "${ADDING_OPTIONS}" + The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" + The stderr should satisfy spec_expect_no_message "${RETURN_VALUE_INDICATES_TIMEOUT}" The stderr should satisfy spec_expect_no_message "${THERE_ARE_ADDITIONAL_MESSAGES}.*${SERVICE_NAME}.*" The stderr should satisfy spec_expect_message "${UPDATED}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}" @@ -168,7 +171,7 @@ Describe 'service-single-service' The stderr should satisfy spec_expect_no_message "${SCHEDULE_NEXT_UPDATE_AT}" End End - Describe "test_new_image_SERVICES_SELF" "container_test:true" "coverage:true" + Describe "test_new_image_SERVICES_SELF" TEST_NAME="test_new_image_SERVICES_SELF" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -191,7 +194,6 @@ Describe 'service-single-service' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" 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 "${SET_TIMEOUT_TO}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" 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}" @@ -199,6 +201,8 @@ Describe 'service-single-service' # We won't see the NUM_SERVICES_UPDATING message because GANTRY_SERVICES_SELF is not added to the list. The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_UPDATING}" The stderr should satisfy spec_expect_no_message "${ADDING_OPTIONS}" + The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" + The stderr should satisfy spec_expect_no_message "${RETURN_VALUE_INDICATES_TIMEOUT}" The stderr should satisfy spec_expect_no_message "${THERE_ARE_ADDITIONAL_MESSAGES}.*${SERVICE_NAME}.*" The stderr should satisfy spec_expect_message "${UPDATED}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${NO_UPDATES}.*${SERVICE_NAME}" diff --git a/tests/gantry_update_options_spec.sh b/tests/gantry_update_options_spec.sh index 8d97030..ea47e37 100644 --- a/tests/gantry_update_options_spec.sh +++ b/tests/gantry_update_options_spec.sh @@ -25,7 +25,7 @@ Describe 'update-options' SUITE_NAME="update-options" BeforeAll "initialize_all_tests ${SUITE_NAME}" AfterAll "finish_all_tests ${SUITE_NAME}" - Describe "test_update_UPDATE_OPTIONS" "container_test:true" "coverage:true" + Describe "test_update_UPDATE_OPTIONS" TEST_NAME="test_update_UPDATE_OPTIONS" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -58,12 +58,12 @@ Describe 'update-options' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" 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 "${SET_TIMEOUT_TO}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" 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}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" 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}" @@ -81,7 +81,7 @@ Describe 'update-options' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_update_label_UPDATE_OPTIONS" "container_test:true" "coverage:true" + Describe "test_update_label_UPDATE_OPTIONS" TEST_NAME="test_update_label_UPDATE_OPTIONS" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -117,12 +117,12 @@ Describe 'update-options' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" 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 "${SET_TIMEOUT_TO}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" 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}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_no_message "${SET_TIMEOUT_TO}" 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}" @@ -140,7 +140,7 @@ Describe 'update-options' The stderr should satisfy spec_expect_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_update_UPDATE_TIMEOUT_SECONDS_not_a_number" "container_test:false" "coverage:true" + Describe "test_update_UPDATE_TIMEOUT_SECONDS_not_a_number" TEST_NAME="test_update_UPDATE_TIMEOUT_SECONDS_not_a_number" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -163,11 +163,11 @@ Describe 'update-options' The stderr should satisfy spec_expect_message "UPDATE_TIMEOUT_SECONDS ${MUST_BE_A_NUMBER}.*" 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 "${SET_TIMEOUT_TO}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" 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_no_message "${SET_TIMEOUT_TO}" 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_no_message "${ROLLING_BACK}.*${SERVICE_NAME}" @@ -185,7 +185,7 @@ Describe 'update-options' The stderr should satisfy spec_expect_no_message "${DONE_REMOVING_IMAGES}" End End - Describe "test_update_lable_UPDATE_TIMEOUT_SECONDS" "container_test:true" "coverage:true" + Describe "test_update_lable_UPDATE_TIMEOUT_SECONDS" TEST_NAME="test_update_lable_UPDATE_TIMEOUT_SECONDS" IMAGE_WITH_TAG=$(get_image_with_tag "${SUITE_NAME}") SERVICE_NAME=$(get_test_service_name "${TEST_NAME}") @@ -225,12 +225,12 @@ Describe 'update-options' The stderr should satisfy spec_expect_no_message "${START_WITHOUT_A_SQUARE_BRACKET}" 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_message "${SET_TIMEOUT_TO} ${TIMEOUT}.*${SERVICE_NAME}" The stderr should satisfy spec_expect_no_message "${NUM_SERVICES_SKIP_JOBS}" 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}.*${SERVICE_NAME}" + The stderr should satisfy spec_expect_message "${SET_TIMEOUT_TO} ${TIMEOUT}.*${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}" diff --git a/tests/spec_gantry_test_helper.sh b/tests/spec_gantry_test_helper.sh index 0d4be29..21a1dd1 100644 --- a/tests/spec_gantry_test_helper.sh +++ b/tests/spec_gantry_test_helper.sh @@ -15,8 +15,6 @@ # along with this program. If not, see . # -set -a - # Constant strings for checks. # START_WITHOUT_A_SQUARE_BRACKET ignores color codes. Use test_log not to trigger this check. export START_WITHOUT_A_SQUARE_BRACKET="^(?!(?:\x1b\[[0-9;]*[mG])?\[)" @@ -46,7 +44,7 @@ export USER_LOGGED_INTO_DEFAULT="User logged in using the default Docker configu export ADDING_OPTIONS="Adding options" export ADDING_OPTIONS_WITH_REGISTRY_AUTH="Adding options.*--with-registry-auth" export SET_TIMEOUT_TO="Set timeout to" -export RETURN_VALUE_INDICATES_TIMEOUT="The return value 124 indicates the job timed out." +export RETURN_VALUE_INDICATES_TIMEOUT="The return value [0-9]+ indicates the job timed out." export THERE_ARE_ADDITIONAL_MESSAGES="There are additional messages from updating" export NUM_SERVICES_SKIP_JOBS="Skip updating [0-9]+ service\(s\) due to they are job\(s\)" export NUM_SERVICES_INSPECT_FAILURE="Failed to inspect [0-9]+ service\(s\)" @@ -76,6 +74,8 @@ export TEST_SERVICE_IMAGE="alpine:latest" test_log() { echo "${GANTRY_LOG_LEVEL}" | grep -q -i "^NONE$" && return 0; + echo "${GANTRY_LOG_LEVEL}" | grep -q -i "^ERROR$" && return 0; + echo "${GANTRY_LOG_LEVEL}" | grep -q -i "^WARN$" && return 0; [ -n "${GANTRY_IMAGES_TO_REMOVE}" ] && echo "${*}" >&2 && return 0; echo "[$(date -Iseconds)] Test: ${*}" >&2 } @@ -144,14 +144,14 @@ common_setup_timeout() { local IMAGE_WITH_TAG="${2}" local SERVICE_NAME="${3}" local TIMEOUT="${4}" - local TIMEOUT_PLUS_ONE=$((TIMEOUT+1)) - local TIMEOUT_PLUS_TWO=$((TIMEOUT+2)) + local TIMEOUT_PLUS=$((TIMEOUT+1)) + local TIMEOUT_MORE=$((TIMEOUT+2)) initialize_test "${TEST_NAME}" # -1 thus the task runs forever. # exit will take longer than the timeout. - build_and_push_test_image "${IMAGE_WITH_TAG}" "-1" "${TIMEOUT_PLUS_TWO}" + build_and_push_test_image "${IMAGE_WITH_TAG}" "-1" "${TIMEOUT_MORE}" # Timeout set by "service create" should be smaller than the exit time above. - start_replicated_service "${SERVICE_NAME}" "${IMAGE_WITH_TAG}" "${TIMEOUT_PLUS_ONE}" + start_replicated_service "${SERVICE_NAME}" "${IMAGE_WITH_TAG}" "${TIMEOUT_PLUS}" build_and_push_test_image "${IMAGE_WITH_TAG}" } @@ -420,8 +420,9 @@ initialize_test() { reset_gantry_env() { local SERVICE_NAME="${1}" - export DOCKER_CONFIG= - export DOCKER_HOST= + export GANTRY_TEST_HOST_TO_CONTAINER= + export GANTRY_TEST_DOCKER_CONFIG= + export GANTRY_TEST_DOCKER_HOST= export GANTRY_LOG_LEVEL="DEBUG" export GANTRY_NODE_NAME= export GANTRY_POST_RUN_CMD= @@ -622,7 +623,7 @@ wait_zero_running_tasks() { # See https://docs.docker.com/engine/reference/commandline/service_ls/#name # It does not do the exact match of the name. See https://github.com/moby/moby/issues/32985 # We do an extra step to to perform the exact match. - REPLICAS=$(echo "${REPLICAS}" | sed -n "s/\(.*\) ${SERVICE_NAME}$/\1/p") + REPLICAS=$(echo "${REPLICAS}" | sed -n -E "s/(.*) ${SERVICE_NAME}$/\1/p") if [ "${TRIES}" -ge "${MAX_RETRIES}" ]; then echo "wait_zero_running_tasks Reach MAX_RETRIES ${MAX_RETRIES}" >&2 return 1 @@ -665,7 +666,7 @@ pull_image_if_not_exist() { _enforce_login_enabled() { local ENFORCE_LOGIN="${1}" - test "${ENFORCE_LOGIN}" == "ENFORCE_LOGIN" + test "${ENFORCE_LOGIN}" = "ENFORCE_LOGIN" } _add_htpasswd() { @@ -688,21 +689,13 @@ _add_htpasswd() { } _wait_service_state() { - local SERVICE_NAME="${1}" - local STATE="${2}" - local TRIES=0 - local MAX_RETRIES=120 - while ! docker service ps --format "{{.CurrentState}}" "${SERVICE_NAME}" | grep -q "${STATE}"; do - if [ "${TRIES}" -ge "${MAX_RETRIES}" ]; then - echo "_wait_service_state Reach MAX_RETRIES ${MAX_RETRIES}" >&2 - return 1 - fi - TRIES=$((TRIES+1)) - sleep 1 - done + local SERVICE_NAME="${1}"; + local WANT_STATE="${2}"; + local TIMEOUT_SECONDS="${3}"; + wait_service_state "${SERVICE_NAME}" "${WANT_STATE}" "${TIMEOUT_SECONDS}" 1>/dev/null 2>&1 } -_correct_test_service_name() { +_sanitize_test_service_name() { local SERVICE_NAME="${1}" [ "${#SERVICE_NAME}" -gt 63 ] && SERVICE_NAME=${SERVICE_NAME:0:63} echo "${SERVICE_NAME}" @@ -724,7 +717,7 @@ start_replicated_service() { local SERVICE_NAME="${1}" local IMAGE_WITH_TAG="${2}" local TIMEOUT_SECONDS="${3:-1}" - SERVICE_NAME=$(_correct_test_service_name "${SERVICE_NAME}") + SERVICE_NAME=$(_sanitize_test_service_name "${SERVICE_NAME}") echo "Creating service ${SERVICE_NAME} in replicated mode " # During creation: # * Add --detach to reduce the test runtime. @@ -746,8 +739,8 @@ start_replicated_service() { $(_location_constraints) \ --mode=replicated \ --detach=true \ - "${IMAGE_WITH_TAG}" - _wait_service_state "${SERVICE_NAME}" "Running" + "${IMAGE_WITH_TAG}"; + _wait_service_state "${SERVICE_NAME}" "Running" 120 } start_multiple_replicated_services() { @@ -771,7 +764,7 @@ start_global_service() { local SERVICE_NAME="${1}" local IMAGE_WITH_TAG="${2}" local TIMEOUT_SECONDS="${3:-1}" - SERVICE_NAME=$(_correct_test_service_name "${SERVICE_NAME}") + SERVICE_NAME=$(_sanitize_test_service_name "${SERVICE_NAME}") echo "Creating service ${SERVICE_NAME} in global mode " # Do not add --detach, because we want to wait for the job finishes. # SC2046 (warning): Quote this to prevent word splitting. @@ -794,7 +787,7 @@ _start_replicated_job() { local IMAGE_WITH_TAG="${2}" local TASK_SECONDS="${3:-1}" local EXIT_SECONDS="${4:-1}" - SERVICE_NAME=$(_correct_test_service_name "${SERVICE_NAME}") + SERVICE_NAME=$(_sanitize_test_service_name "${SERVICE_NAME}") echo "Creating service ${SERVICE_NAME} in replicated job mode " # Always add --detach=true, do not wait for the job finishes. # SC2046 (warning): Quote this to prevent word splitting. @@ -808,9 +801,9 @@ _start_replicated_job() { $(_location_constraints) \ --mode=replicated-job \ --detach=true \ - "${IMAGE_WITH_TAG}" + "${IMAGE_WITH_TAG}"; # wait until the job is running - _wait_service_state "${SERVICE_NAME}" "Running" + _wait_service_state "${SERVICE_NAME}" "Running" 120 } stop_service() { @@ -867,6 +860,15 @@ _get_entrypoint() { echo "source ${STATIC_VAR_ENTRYPOINT}" } +_get_file_readonly() { + local NAME="${1}" + if [ -w "${NAME}" ]; then + echo "false" + else + echo "true" + fi +} + _add_file_to_mount_options() { local MOUNT_OPTIONS="${1}" local HOST_PATH="${2}" @@ -874,40 +876,63 @@ _add_file_to_mount_options() { # Use the absolute path inside the container. local TARGET= TARGET=$(readlink -f "${HOST_PATH}") - MOUNT_OPTIONS="${MOUNT_OPTIONS} --mount type=bind,source=${HOST_PATH},target=${TARGET}" + local READONLY= + READONLY=$(_get_file_readonly "${HOST_PATH}") + MOUNT_OPTIONS="${MOUNT_OPTIONS} --mount type=bind,source=${HOST_PATH},target=${TARGET},readonly=${READONLY}" fi echo "${MOUNT_OPTIONS}" } -_run_gantry_container() { +stop_gantry_container() { local STACK="${1}" local SUT_REPO_TAG= SUT_REPO_TAG="$(_get_sut_image)" if [ -z "${SUT_REPO_TAG}" ]; then - return 1 + return 0; fi + local RETURN_VALUE=0 local SERVICE_NAME= - SERVICE_NAME="gantry-test-SUT-$(unique_id)" + SERVICE_NAME="gantry-test-SUT-${STACK}" + SERVICE_NAME=$(_sanitize_test_service_name "${SERVICE_NAME}") + local CMD_OUTPUT= + docker service logs --raw "${SERVICE_NAME}" + if ! CMD_OUTPUT=$(docker service rm "${SERVICE_NAME}" 2>&1); then + echo "Failed to remove service ${SERVICE_NAME}: ${CMD_OUTPUT}" >&2 + RETURN_VALUE=1 + fi + return "${RETURN_VALUE}" +} + +_run_gantry_container() { + local STACK="${1}" + local SUT_REPO_TAG="${2}" + pull_image_if_not_exist "${SUT_REPO_TAG}" + local SERVICE_NAME= + SERVICE_NAME="gantry-test-SUT-${STACK}" + SERVICE_NAME=$(_sanitize_test_service_name "${SERVICE_NAME}") docker service rm "${SERVICE_NAME}" >/dev/null 2>&1; local MOUNT_OPTIONS= - MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${DOCKER_CONFIG}") + MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${GANTRY_TEST_HOST_TO_CONTAINER}") + MOUNT_OPTIONS=$(_add_file_to_mount_options "${MOUNT_OPTIONS}" "${GANTRY_TEST_DOCKER_CONFIG}") 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}") test_log "Starting SUT service ${SERVICE_NAME} with image ${SUT_REPO_TAG}." + test_log "MOUNT_OPTIONS=${MOUNT_OPTIONS}" local RETURN_VALUE=0 local CMD_OUTPUT= # SC2086 (info): Double quote to prevent globbing and word splitting. # shellcheck disable=SC2086 if ! CMD_OUTPUT=$(docker service create --name "${SERVICE_NAME}" \ + --detach=true \ --mode replicated-job --restart-condition=none --network host \ --constraint "node.role==manager" \ --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \ ${MOUNT_OPTIONS} \ - --env "DOCKER_CONFIG=${DOCKER_CONFIG}" \ - --env "DOCKER_HOST=${DOCKER_HOST}" \ + --env "DOCKER_CONFIG=${GANTRY_TEST_DOCKER_CONFIG}" \ + --env "DOCKER_HOST=${GANTRY_TEST_DOCKER_HOST}" \ --env "GANTRY_LOG_LEVEL=${GANTRY_LOG_LEVEL}" \ --env "GANTRY_NODE_NAME=${GANTRY_NODE_NAME}" \ --env "GANTRY_POST_RUN_CMD=${GANTRY_POST_RUN_CMD}" \ @@ -948,22 +973,53 @@ _run_gantry_container() { echo "Failed to create service ${SERVICE_NAME}: ${CMD_OUTPUT}" >&2 RETURN_VALUE=1 fi - docker service logs --raw "${SERVICE_NAME}" - if ! CMD_OUTPUT=$(docker service rm "${SERVICE_NAME}" 2>&1); then - echo "Failed to remove service ${SERVICE_NAME}: ${CMD_OUTPUT}" >&2 - RETURN_VALUE=1 - fi + _wait_service_state "${SERVICE_NAME}" "Complete" 120 + RETURN_VALUE=$? + stop_gantry_container "${STACK}" || return 1 return "${RETURN_VALUE}" } +_restore_env() { + local ENV_NAME="${1}" + local ENV_SET="${2}" + local ENV_VALUE="${3}" + if [ "${ENV_SET}" = "1" ]; then + eval "export ${ENV_NAME}=\"${ENV_VALUE}\"" + else + unset "${ENV_NAME}" + fi +} + run_gantry() { local STACK="${1}" - if _run_gantry_container "${STACK}"; then - return 0 + local DOCKER_CONFIG_SET=0 + local OLD_DOCKER_CONFIG= + local DOCKER_HOST_SET=0 + local OLD_DOCKER_HOST= + if env | grep_q "^DOCKER_CONFIG="; then + DOCKER_CONFIG_SET=1 + OLD_DOCKER_CONFIG="${DOCKER_CONFIG}" + fi + if env | grep_q "^DOCKER_HOST="; then + DOCKER_HOST_SET=1 + OLD_DOCKER_HOST="${DOCKER_HOST}" fi - local ENTRYPOINT= - ENTRYPOINT=$(_get_entrypoint) || return 1 - ${ENTRYPOINT} "${STACK}" + local RETURN_VALUE=1 + local SUT_REPO_TAG= + SUT_REPO_TAG="$(_get_sut_image)" + if [ -n "${SUT_REPO_TAG}" ]; then + _run_gantry_container "${STACK}" "${SUT_REPO_TAG}" + RETURN_VALUE=$? + else + [ -n "${GANTRY_TEST_DOCKER_CONFIG}" ] && export DOCKER_CONFIG="${GANTRY_TEST_DOCKER_CONFIG}" + [ -n "${GANTRY_TEST_DOCKER_HOST}" ] && export DOCKER_HOST="${GANTRY_TEST_DOCKER_HOST}" + local ENTRYPOINT= + if ENTRYPOINT=$(_get_entrypoint); then + ${ENTRYPOINT} "${STACK}" + RETURN_VALUE=$? + fi + fi + _restore_env "DOCKER_CONFIG" "${DOCKER_CONFIG_SET}" "${OLD_DOCKER_CONFIG}" + _restore_env "DOCKER_HOST" "${DOCKER_HOST_SET}" "${OLD_DOCKER_HOST}" + return "${RETURN_VALUE}" } - -set +a