From 4b02933dd25ed029dc27ea8edfe73f75c75e436d Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Mon, 4 Sep 2023 18:23:24 +1200 Subject: [PATCH] tests: Adjust KV match logic Inverse the assert to process the config file entry lookup to reduce the white-space between key and value to a consistent ` = ` which can then be compared directly to the `KEY_VALUE` input (_instead of the KV isolation dance used previously_). --- target/scripts/startup/setup.d/ldap.sh | 2 +- test/tests/serial/mail_with_ldap.bats | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/target/scripts/startup/setup.d/ldap.sh b/target/scripts/startup/setup.d/ldap.sh index f4ffb36e..eb2fdf3b 100644 --- a/target/scripts/startup/setup.d/ldap.sh +++ b/target/scripts/startup/setup.d/ldap.sh @@ -59,6 +59,6 @@ function _create_config_postfix() { if ! grep --silent '^query_filter =' "${LDAP_CONFIG_FILE}"; then _log 'warn' "'${LDAP_CONFIG_FILE}' is missing the 'query_filter' setting - disabling" - sed -i "s/$(_escape_for_sed <<< ${LDAP_CONFIG_FILE})//" /etc/postfix/main.cf + sed -i "s/$(_escape_for_sed <<< "${LDAP_CONFIG_FILE}")//" /etc/postfix/main.cf fi } diff --git a/test/tests/serial/mail_with_ldap.bats b/test/tests/serial/mail_with_ldap.bats index 771a18ae..32cbc9ec 100644 --- a/test/tests/serial/mail_with_ldap.bats +++ b/test/tests/serial/mail_with_ldap.bats @@ -429,17 +429,12 @@ function _should_successfully_deliver_mail_to() { function _should_have_matching_setting() { local KEY_VALUE=${1} local CONFIG_FILE=${2} + local KV_DELIMITER=${3:-'='} - function __trim_whitespace() { - sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<< "${1}" - } - - local KEY VALUE - # Split string into key/value vars and trim white-space: - KEY=$(__trim_whitespace "${KEY_VALUE%=*}") - VALUE=$(__trim_whitespace "${KEY_VALUE#*=}") - - _run_in_container grep "${KEY}" "${CONFIG_FILE}" - assert_output --regexp "^${KEY}\s*=\s*${VALUE}$" + local KEY + KEY="${KEY_VALUE%%"${KV_DELIMITER}"*}" + # Look up the KEY portion from the target config file and use sed to reduce white-space between key and value: + _run_in_container_bash "grep '^${KEY}' '${CONFIG_FILE}' | sed 's/\s*${KV_DELIMITER}\s*/ ${KV_DELIMITER} /'" + assert_output "${LDAP_SETTING}" assert_success }