change if style (#3361)

This commit is contained in:
Casper 2023-05-24 09:06:59 +02:00 committed by GitHub
parent 0e592aa911
commit cf74127f78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
58 changed files with 297 additions and 594 deletions

View file

@ -52,12 +52,10 @@ __load_bats_helper
#
# This function is internal and should not be used in tests.
function __handle_container_name() {
if [[ -n ${1:-} ]] && [[ ${1:-} =~ ^dms-test_ ]]
then
if [[ -n ${1:-} ]] && [[ ${1:-} =~ ^dms-test_ ]]; then
printf '%s' "${1}"
return 0
elif [[ -n ${CONTAINER_NAME+set} ]]
then
elif [[ -n ${CONTAINER_NAME+set} ]]; then
printf '%s' "${CONTAINER_NAME}"
return 0
else
@ -169,8 +167,7 @@ function _repeat_in_container_until_success_or_timeout() {
function _repeat_until_success_or_timeout() {
local FATAL_FAILURE_TEST_COMMAND
if [[ "${1:-}" == "--fatal-test" ]]
then
if [[ "${1:-}" == "--fatal-test" ]]; then
FATAL_FAILURE_TEST_COMMAND="${2:?Provided --fatal-test but no command}"
shift 2
fi
@ -178,8 +175,7 @@ function _repeat_until_success_or_timeout() {
local TIMEOUT=${1:?Timeout duration must be provided}
shift 1
if ! [[ "${TIMEOUT}" =~ ^[0-9]+$ ]]
then
if ! [[ "${TIMEOUT}" =~ ^[0-9]+$ ]]; then
echo "First parameter for timeout must be an integer, received \"${TIMEOUT}\""
return 1
fi
@ -188,16 +184,14 @@ function _repeat_until_success_or_timeout() {
until "${@}"
do
if [[ -n ${FATAL_FAILURE_TEST_COMMAND} ]] && ! eval "${FATAL_FAILURE_TEST_COMMAND}"
then
if [[ -n ${FATAL_FAILURE_TEST_COMMAND} ]] && ! eval "${FATAL_FAILURE_TEST_COMMAND}"; then
echo "\`${FATAL_FAILURE_TEST_COMMAND}\` failed, early aborting repeat_until_success of \`${*}\`" >&2
return 1
fi
sleep 1
if [[ $(( SECONDS - STARTTIME )) -gt ${TIMEOUT} ]]
then
if [[ $(( SECONDS - STARTTIME )) -gt ${TIMEOUT} ]]; then
echo "Timed out on command: ${*}" >&2
return 1
fi
@ -213,8 +207,7 @@ function _run_until_success_or_timeout() {
local TIMEOUT=${1:?Timeout duration must be provided}
shift 1
if [[ ! ${TIMEOUT} =~ ^[0-9]+$ ]]
then
if [[ ! ${TIMEOUT} =~ ^[0-9]+$ ]]; then
echo "First parameter for timeout must be an integer, received \"${TIMEOUT}\""
return 1
fi
@ -226,8 +219,7 @@ function _run_until_success_or_timeout() {
do
sleep 1
if (( SECONDS - STARTTIME > TIMEOUT ))
then
if (( SECONDS - STARTTIME > TIMEOUT )); then
echo "Timed out on command: ${*}" >&2
return 1
fi
@ -270,8 +262,7 @@ function _wait_for_smtp_port_in_container_to_respond() {
local COUNT=0
until [[ $(_exec_in_container timeout 10 /bin/bash -c 'echo QUIT | nc localhost 25') == *'221 2.0.0 Bye'* ]]
do
if [[ ${COUNT} -eq 20 ]]
then
if [[ ${COUNT} -eq 20 ]]; then
echo "Unable to receive a valid response from 'nc localhost 25' within 20 seconds"
return 1
fi

View file

@ -17,8 +17,7 @@
# This function is internal and should not be used in tests.
function __initialize_variables() {
function __check_if_set() {
if [[ ${!1+set} != 'set' ]]
then
if [[ ${!1+set} != 'set' ]]; then
echo "ERROR: (helper/setup.sh) '${1:?No variable name given to __check_if_set}' is not set" >&2
exit 1
fi
@ -64,8 +63,7 @@ function _duplicate_config_for_container() {
local OUTPUT_FOLDER
OUTPUT_FOLDER=$(_print_private_config_path "${2}")
if [[ -z ${OUTPUT_FOLDER} ]]
then
if [[ -z ${OUTPUT_FOLDER} ]]; then
echo "'OUTPUT_FOLDER' in '_duplicate_config_for_container' is empty" >&2
return 1
fi

View file

@ -71,14 +71,11 @@ function _generate_openssl_cmd() {
local CMD_OPENSSL="timeout 1 openssl s_client -connect ${HOST}:${PORT}"
# STARTTLS ports need to add a hint:
if [[ ${PORT} =~ ^(25|587)$ ]]
then
if [[ ${PORT} =~ ^(25|587)$ ]]; then
CMD_OPENSSL="${CMD_OPENSSL} -starttls smtp"
elif [[ ${PORT} == 143 ]]
then
elif [[ ${PORT} == 143 ]]; then
CMD_OPENSSL="${CMD_OPENSSL} -starttls imap"
elif [[ ${PORT} == 110 ]]
then
elif [[ ${PORT} == 110 ]]; then
CMD_OPENSSL="${CMD_OPENSSL} -starttls pop3"
fi

View file

@ -111,8 +111,7 @@ function _shellcheck
"koalaman/shellcheck-alpine:v${SHELLCHECK_VERSION}" "${CMD_SHELLCHECK[@]}" \
"${BATS_EXTRA_ARGS[@]}" "${F_BATS[@]}" || ERROR=1
if [[ ${ERROR} -eq 0 ]]
then
if [[ ${ERROR} -eq 0 ]]; then
_log 'info' 'ShellCheck succeeded'
else
_log 'error' 'ShellCheck failed'

View file

@ -107,8 +107,7 @@ function wait_for_smtp_port_in_container() {
function wait_for_smtp_port_in_container_to_respond() {
local COUNT=0
until [[ $(docker exec "${1}" timeout 10 /bin/sh -c "echo QUIT | nc localhost 25") == *"221 2.0.0 Bye"* ]]; do
if [[ $COUNT -eq 20 ]]
then
if [[ $COUNT -eq 20 ]]; then
echo "Unable to receive a valid response from 'nc localhost 25' within 20 seconds"
return 1
fi

View file

@ -240,8 +240,7 @@ function _copy_to_letsencrypt_storage() {
FQDN_DIR=$(echo "${DEST}" | cut -d '/' -f1)
mkdir -p "${TEST_TMP_CONFIG}/letsencrypt/${FQDN_DIR}"
if ! cp "${PWD}/test/test-files/ssl/${SRC}" "${TEST_TMP_CONFIG}/letsencrypt/${DEST}"
then
if ! cp "${PWD}/test/test-files/ssl/${SRC}" "${TEST_TMP_CONFIG}/letsencrypt/${DEST}"; then
echo "Could not copy cert file '${SRC}'' to '${DEST}'" >&2
exit 1
fi

View file

@ -76,8 +76,7 @@ function _configure_and_run_dms_container() {
local ALT_KEY_TYPE=$3 # Optional parameter
export TEST_VARIANT="${TLS_LEVEL}-${KEY_TYPE}"
if [[ -n ${ALT_KEY_TYPE} ]]
then
if [[ -n ${ALT_KEY_TYPE} ]]; then
TEST_VARIANT+="-${ALT_KEY_TYPE}"
fi
@ -98,8 +97,7 @@ function _configure_and_run_dms_container() {
--env SSL_KEY_PATH="/config/ssl/with_ca/ecdsa/key.${KEY_TYPE}.pem"
)
if [[ -n ${ALT_KEY_TYPE} ]]
then
if [[ -n ${ALT_KEY_TYPE} ]]; then
CUSTOM_SETUP_ARGUMENTS+=(
--env SSL_ALT_CERT_PATH="/config/ssl/with_ca/ecdsa/cert.${ALT_KEY_TYPE}.pem"
--env SSL_ALT_KEY_PATH="/config/ssl/with_ca/ecdsa/key.${ALT_KEY_TYPE}.pem"
@ -199,8 +197,7 @@ function compare_cipherlist() {
function get_cipherlist() {
local TLS_VERSION=$1
if [[ ${TLS_VERSION} == "TLSv1_3" ]]
then
if [[ ${TLS_VERSION} == "TLSv1_3" ]]; then
# TLS v1.3 cipher suites are not user defineable and not unique to the available certificate(s).
# They do not support server enforced order either.
echo '"TLS_AES_256_GCM_SHA384 TLS_CHACHA20_POLY1305_SHA256 TLS_AES_128_GCM_SHA256"'

View file

@ -184,8 +184,7 @@ function _check_if_process_is_running() {
local IS_RUNNING=$(docker exec "${CONTAINER_NAME}" pgrep --list-full "${MIN_SECS_RUNNING[@]}" "${PROCESS}")
# When no matches are found, nothing is returned. Provide something we can assert on (helpful for debugging):
if [[ ! ${IS_RUNNING} =~ ${PROCESS} ]]
then
if [[ ! ${IS_RUNNING} =~ ${PROCESS} ]]; then
echo "'${PROCESS}' is not running"
return 1
fi