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_).
This commit is contained in:
polarathene 2023-09-04 18:23:24 +12:00
parent d6ae1a8d4d
commit 4b02933dd2
2 changed files with 7 additions and 12 deletions

View File

@ -59,6 +59,6 @@ function _create_config_postfix() {
if ! grep --silent '^query_filter =' "${LDAP_CONFIG_FILE}"; then if ! grep --silent '^query_filter =' "${LDAP_CONFIG_FILE}"; then
_log 'warn' "'${LDAP_CONFIG_FILE}' is missing the 'query_filter' setting - disabling" _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 fi
} }

View File

@ -429,17 +429,12 @@ function _should_successfully_deliver_mail_to() {
function _should_have_matching_setting() { function _should_have_matching_setting() {
local KEY_VALUE=${1} local KEY_VALUE=${1}
local CONFIG_FILE=${2} local CONFIG_FILE=${2}
local KV_DELIMITER=${3:-'='}
function __trim_whitespace() { local KEY
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<< "${1}" 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} /'"
local KEY VALUE assert_output "${LDAP_SETTING}"
# 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}$"
assert_success assert_success
} }