MacOS linting & testing support + docs (#2001)

This commit is contained in:
Nathan Pierce 2021-06-07 08:58:34 -04:00 committed by GitHub
parent abdf681d02
commit 543bd8b16b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 109 additions and 153 deletions

View file

@ -6,7 +6,6 @@ on:
push: push:
branches: branches:
- master - master
jobs: jobs:
lint: lint:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
@ -17,25 +16,16 @@ jobs:
submodules: recursive submodules: recursive
- name: Hadolint - name: Hadolint
run: | run: |
sudo curl -S -L https://github.com/hadolint/hadolint/releases/download/v${HADOLINT_VERSION}/hadolint-$(uname -s)-$(uname -m) -o /usr/local/bin/hadolint
sudo chmod +rx /usr/local/bin/hadolint
make hadolint make hadolint
env: env:
HADOLINT_VERSION: 2.4.1 HADOLINT_VERSION: 2.4.1
- name: ShellCheck - name: ShellCheck
run: | run: |
sudo curl -S -L "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" | tar -xJ
sudo mv "shellcheck-v${SHELLCHECK_VERSION}/shellcheck" /usr/bin/
sudo rm -rf "shellcheck-v${SHELLCHECK_VERSION}"
make shellcheck make shellcheck
env: env:
SHELLCHECK_VERSION: 0.7.2 SHELLCHECK_VERSION: 0.7.2
- name: ECLint - name: ECLint
run: | run: |
sudo curl -S -L "https://github.com/editorconfig-checker/editorconfig-checker/releases/download/${ECLINT_VERSION}/ec-linux-amd64.tar.gz" | tar -xaz
sudo mv bin/ec-linux-amd64 /usr/bin/eclint
sudo rm -rf bin
sudo chmod +x /usr/bin/eclint
make eclint make eclint
env: env:
ECLINT_VERSION: 2.3.5 ECLINT_VERSION: 2.3.5

3
.gitignore vendored
View file

@ -43,6 +43,9 @@ test/config/without-virtual/
test/config/with-domain/ test/config/with-domain/
test/onedir test/onedir
test/duplicate_configs test/duplicate_configs
test/alias
test/quota
test/relay
config.bak config.bak
testconfig.bak testconfig.bak

View file

@ -4,10 +4,6 @@ NAME ?= mailserver-testing:ci
VCS_REF = $(shell git rev-parse --short HEAD) VCS_REF = $(shell git rev-parse --short HEAD)
VCS_VER = $(shell git describe --tags --contains --always) VCS_VER = $(shell git describe --tags --contains --always)
HADOLINT_VERSION = 2.4.1
SHELLCHECK_VERSION = 0.7.2
ECLINT_VERSION = 2.3.5
export CDIR = $(shell pwd) export CDIR = $(shell pwd)
# #
@ -29,7 +25,7 @@ clean:
# remove running and stopped test containers # remove running and stopped test containers
-@ [[ -d config.bak ]] && { rm -rf config ; mv config.bak config ; } || : -@ [[ -d config.bak ]] && { rm -rf config ; mv config.bak config ; } || :
-@ [[ -d testconfig.bak ]] && { sudo rm -rf test/config ; mv testconfig.bak test/config ; } || : -@ [[ -d testconfig.bak ]] && { sudo rm -rf test/config ; mv testconfig.bak test/config ; } || :
-@ docker ps -a | grep -E "mail|ldap_for_mail|mail_overri.*" | cut -f 1-1 -d ' ' | xargs --no-run-if-empty docker rm -f -@ for container in $$(docker ps -a | grep -E "mail|ldap_for_mail|mail_overri.*|hadolint|eclint|shellcheck" | cut -f 1-1 -d ' '); do docker rm -f $$container; done
-@ sudo rm -rf test/onedir test/alias test/quota test/relay test/config/dovecot-lmtp/userdb test/config/key* test/config/opendkim/keys/domain.tld/ test/config/opendkim/keys/example.com/ test/config/opendkim/keys/localdomain2.com/ test/config/postfix-aliases.cf test/config/postfix-receive-access.cf test/config/postfix-receive-access.cfe test/config/dovecot-quotas.cf test/config/postfix-send-access.cf test/config/postfix-send-access.cfe test/config/relay-hosts/chksum test/config/relay-hosts/postfix-aliases.cf test/config/dhparams.pem test/config/dovecot-lmtp/dh.pem test/config/relay-hosts/dovecot-quotas.cf test/config/user-patches.sh test/alias/config/postfix-virtual.cf test/quota/config/dovecot-quotas.cf test/quota/config/postfix-accounts.cf test/relay/config/postfix-relaymap.cf test/relay/config/postfix-sasl-password.cf test/duplicate_configs/ -@ sudo rm -rf test/onedir test/alias test/quota test/relay test/config/dovecot-lmtp/userdb test/config/key* test/config/opendkim/keys/domain.tld/ test/config/opendkim/keys/example.com/ test/config/opendkim/keys/localdomain2.com/ test/config/postfix-aliases.cf test/config/postfix-receive-access.cf test/config/postfix-receive-access.cfe test/config/dovecot-quotas.cf test/config/postfix-send-access.cf test/config/postfix-send-access.cfe test/config/relay-hosts/chksum test/config/relay-hosts/postfix-aliases.cf test/config/dhparams.pem test/config/dovecot-lmtp/dh.pem test/config/relay-hosts/dovecot-quotas.cf test/config/user-patches.sh test/alias/config/postfix-virtual.cf test/quota/config/dovecot-quotas.cf test/quota/config/postfix-accounts.cf test/relay/config/postfix-relaymap.cf test/relay/config/postfix-sasl-password.cf test/duplicate_configs/
# #
@ -60,13 +56,3 @@ shellcheck:
eclint: eclint:
@ ./test/linting/lint.sh eclint @ ./test/linting/lint.sh eclint
install_linters:
@ mkdir -p tools
@ curl -S -L \
"https://github.com/hadolint/hadolint/releases/download/v$(HADOLINT_VERSION)/hadolint-$(shell uname -s)-$(shell uname -m)" -o tools/hadolint
@ curl -S -L \
"https://github.com/koalaman/shellcheck/releases/download/v$(SHELLCHECK_VERSION)/shellcheck-v$(SHELLCHECK_VERSION).linux.x86_64.tar.xz" | tar -Jx shellcheck-v$(SHELLCHECK_VERSION)/shellcheck -O > tools/shellcheck
@ curl -S -L \
"https://github.com/editorconfig-checker/editorconfig-checker/releases/download/$(ECLINT_VERSION)/ec-linux-amd64.tar.gz" | tar -zx bin/ec-linux-amd64 -O > tools/eclint
@ chmod u+rx tools/*

View file

@ -35,10 +35,9 @@ The development workflow is the following:
2. Run `git submodule update --init --recursive` 2. Run `git submodule update --init --recursive`
2. Write the code that is needed :D 2. Write the code that is needed :D
3. Add integration tests if necessary 3. Add integration tests if necessary
4. Get the linters with `make install_linters` and install `jq` with the package manager of your OS 4. [Prepare your environment and run linting and tests][docs-tests]
5. Use `make clean all` to build image locally and run tests (note that tests work on Linux **only**) 5. Document your improvements if necessary (e.g. if you introduced new environment variables, describe those in the [ENV documentation][docs-environment])
6. Document your improvements if necessary (e.g. if you introduced new environment variables, describe those in the [ENV documentation][docs-environment]) 6. [Commit][commit] and [sign your commit][gpg], push and create a pull-request to merge into `master`. Please **use the pull-request template** to provide a minimum of contextual information and make sure to meet the requirements of the checklist.
7. [Commit][commit] and [sign your commit][gpg], push and create a pull-request to merge into `master`. Please **use the pull-request template** to provide a minimum of contextual information and make sure to meet the requirements of the checklist.
1. Pull requests are automatically tested against the CI and will be reviewed when tests pass 1. Pull requests are automatically tested against the CI and will be reviewed when tests pass
2. When your changes are validated, your branch is merged 2. When your changes are validated, your branch is merged
3. CI builds the new `:edge` image immediately and your changes will be includes in the next version release. 3. CI builds the new `:edge` image immediately and your changes will be includes in the next version release.
@ -46,5 +45,6 @@ The development workflow is the following:
[docs]: https://docker-mailserver.github.io/docker-mailserver/edge [docs]: https://docker-mailserver.github.io/docker-mailserver/edge
[github-file-readme]: https://github.com/docker-mailserver/docker-mailserver/blob/master/README.md [github-file-readme]: https://github.com/docker-mailserver/docker-mailserver/blob/master/README.md
[docs-environment]: ../config/environment.md [docs-environment]: ../config/environment.md
[docs-tests]: ./tests.md
[commit]: https://help.github.com/articles/closing-issues-via-commit-messages/ [commit]: https://help.github.com/articles/closing-issues-via-commit-messages/
[gpg]: https://docs.github.com/en/github/authenticating-to-github/generating-a-new-gpg-key [gpg]: https://docs.github.com/en/github/authenticating-to-github/generating-a-new-gpg-key

View file

@ -2,5 +2,16 @@
title: 'Contributing | Tests' title: 'Contributing | Tests'
--- ---
!!! todo 1. Install docker
This section should provide a detailed step by step guide on how to write tests 2. Execute `git submodule update --init --recursive`
3. Install jq
!!! info "MacOS Specific (needed for tests)"
```bash
brew install coreutils
# bash >= 4.0 for associative arrays
brew install bash
```
4. Execute `make clean all`

View file

@ -36,6 +36,12 @@ ly and use ./setup.sh help and read the VERSION section.\n" >&2
function _get_absolute_script_directory function _get_absolute_script_directory
{ {
if [[ "$(uname)" == "Darwin" ]]
then
readlink() {
greadlink "${@:+$@}" # Requires coreutils
}
fi
if dirname "$(readlink -f "${0}")" &>/dev/null if dirname "$(readlink -f "${0}")" &>/dev/null
then then
DIR="$(dirname "$(readlink -f "${0}")")" DIR="$(dirname "$(readlink -f "${0}")")"
@ -225,7 +231,7 @@ function _docker_image
if ${USE_CONTAINER} if ${USE_CONTAINER}
then then
# reuse existing container specified on command line # reuse existing container specified on command line
${CRI} exec "${USE_TTY}" "${CONTAINER_NAME}" "${@}" ${CRI} exec "${USE_TTY}" "${CONTAINER_NAME}" "${@:+$@}"
else else
# start temporary container with specified image # start temporary container with specified image
if ! _docker_image_exists "${IMAGE_NAME}" if ! _docker_image_exists "${IMAGE_NAME}"
@ -236,7 +242,7 @@ function _docker_image
${CRI} run --rm \ ${CRI} run --rm \
-v "${CONFIG_PATH}:/tmp/docker-mailserver${USE_SELINUX}" \ -v "${CONFIG_PATH}:/tmp/docker-mailserver${USE_SELINUX}" \
"${USE_TTY}" "${IMAGE_NAME}" "${@}" "${USE_TTY}" "${IMAGE_NAME}" "${@:+$@}"
fi fi
} }
@ -244,7 +250,7 @@ function _docker_container
{ {
if [[ -n ${CONTAINER_NAME} ]] if [[ -n ${CONTAINER_NAME} ]]
then then
${CRI} exec "${USE_TTY}" "${CONTAINER_NAME}" "${@}" ${CRI} exec "${USE_TTY}" "${CONTAINER_NAME}" "${@:+$@}"
else else
echo "The mailserver is not running!" echo "The mailserver is not running!"
exit 1 exit 1
@ -340,10 +346,10 @@ function _main
email ) email )
case ${2:-} in case ${2:-} in
add ) shift 2 ; _docker_image addmailuser "${@}" ;; add ) shift 2 ; _docker_image addmailuser "${@:+$@}" ;;
update ) shift 2 ; _docker_image updatemailuser "${@}" ;; update ) shift 2 ; _docker_image updatemailuser "${@:+$@}" ;;
del ) shift 2 ; _docker_container delmailuser "${@}" ;; del ) shift 2 ; _docker_container delmailuser "${@:+$@}" ;;
restrict ) shift 2 ; _docker_container restrict-access "${@}" ;; restrict ) shift 2 ; _docker_container restrict-access "${@:+$@}" ;;
list ) _docker_container listmailuser ;; list ) _docker_container listmailuser ;;
* ) _usage ;; * ) _usage ;;
esac esac
@ -360,24 +366,24 @@ function _main
quota ) quota )
case ${2:-} in case ${2:-} in
set ) shift 2 ; _docker_image setquota "${@}" ;; set ) shift 2 ; _docker_image setquota "${@:+$@}" ;;
del ) shift 2 ; _docker_image delquota "${@}" ;; del ) shift 2 ; _docker_image delquota "${@:+$@}" ;;
* ) _usage ;; * ) _usage ;;
esac esac
;; ;;
config ) config )
case ${2:-} in case ${2:-} in
dkim ) shift 2 ; _docker_image open-dkim "${@}" ;; dkim ) shift 2 ; _docker_image open-dkim "${@:+$@}" ;;
* ) _usage ;; * ) _usage ;;
esac esac
;; ;;
relay ) relay )
case ${2:-} in case ${2:-} in
add-domain ) shift 2 ; _docker_image addrelayhost "${@}" ;; add-domain ) shift 2 ; _docker_image addrelayhost "${@:+$@}" ;;
add-auth ) shift 2 ; _docker_image addsaslpassword "${@}" ;; add-auth ) shift 2 ; _docker_image addsaslpassword "${@:+$@}" ;;
exclude-domain ) shift 2 ; _docker_image excluderelaydomain "${@}" ;; exclude-domain ) shift 2 ; _docker_image excluderelaydomain "${@:+$@}" ;;
* ) _usage ;; * ) _usage ;;
esac esac
;; ;;
@ -385,7 +391,7 @@ function _main
debug ) debug )
case ${2:-} in case ${2:-} in
fetchmail ) _docker_image debug-fetchmail ;; fetchmail ) _docker_image debug-fetchmail ;;
fail2ban ) shift 2 ; _docker_container fail2ban "${@}" ;; fail2ban ) shift 2 ; _docker_container fail2ban "${@:+$@}" ;;
show-mail-logs ) _docker_container cat /var/log/mail/mail.log ;; show-mail-logs ) _docker_container cat /var/log/mail/mail.log ;;
inspect ) _inspect ;; inspect ) _inspect ;;
login ) login )
@ -394,7 +400,7 @@ function _main
then then
_docker_container /bin/bash _docker_container /bin/bash
else else
_docker_container /bin/bash -c "${@}" _docker_container /bin/bash -c "${@:+$@}"
fi fi
;; ;;
* ) _usage ; exit 1 ;; * ) _usage ; exit 1 ;;
@ -406,4 +412,4 @@ function _main
esac esac
} }
_main "${@}" _main "${@:+$@}"

View file

@ -163,6 +163,7 @@ function _populate_relayhost_map
if ! grep -q -e "^@${DOMAIN}\b" /etc/postfix/relayhost_map && ! grep -qs -e "^\s*@${DOMAIN}\s*$" /tmp/docker-mailserver/postfix-relaymap.cf if ! grep -q -e "^@${DOMAIN}\b" /etc/postfix/relayhost_map && ! grep -qs -e "^\s*@${DOMAIN}\s*$" /tmp/docker-mailserver/postfix-relaymap.cf
then then
_notify 'inf' "Adding relay mapping for ${DOMAIN}" _notify 'inf' "Adding relay mapping for ${DOMAIN}"
# shellcheck disable=SC2153
echo "@${DOMAIN} [${RELAY_HOST}]:${RELAY_PORT}" >> /etc/postfix/relayhost_map echo "@${DOMAIN} [${RELAY_HOST}]:${RELAY_PORT}" >> /etc/postfix/relayhost_map
fi fi
done done

View file

@ -1,11 +1,18 @@
{ {
"Version": "2.3.5",
"Verbose": false, "Verbose": false,
"Debug": false, "Debug": false,
"IgnoreDefaults": false, "IgnoreDefaults": false,
"SpacesAftertabs": true, "SpacesAftertabs": true,
"NoColor": false, "NoColor": false,
"Exclude": [], "Exclude": [
"^test/",
"\\.git.*",
"\\.bats$",
"\\.cf$",
"\\.conf$",
"\\.init$",
"\\.md$"
],
"AllowedContentTypes": [], "AllowedContentTypes": [],
"PassedFiles": [], "PassedFiles": [],
"Disable": { "Disable": {

View file

@ -2,6 +2,7 @@ ignored:
- DL3005 - DL3005
- DL3008 - DL3008
- DL3015 - DL3015
- DL3005
trustedRegistries: trustedRegistries:
- docker.io - docker.io

View file

@ -6,6 +6,13 @@
SCRIPT="lint.sh" SCRIPT="lint.sh"
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
REPO_ROOT="$(realpath "${SCRIPT_DIR}"/../../)"
HADOLINT_VERSION=2.4.1
ECLINT_VERSION=2.3.5
SHELLCHECK_VERSION=0.7.2
set -eEuo pipefail set -eEuo pipefail
trap '__log_err "${FUNCNAME[0]:-?}" "${BASH_COMMAND:-?}" ${LINENO:-?} ${?:-?}' ERR trap '__log_err "${FUNCNAME[0]:-?}" "${BASH_COMMAND:-?}" ${LINENO:-?} ${?:-?}' ERR
@ -51,26 +58,11 @@ function _eclint
{ {
local SCRIPT='EDITORCONFIG LINTER' local SCRIPT='EDITORCONFIG LINTER'
local IGNORE='.*\.git.*|.*\.md$|\.bats$|\.cf$|' if docker run --rm --tty \
IGNORE+='\.conf$|\.init$|.*test/.*|.*tools/.*' --volume "${REPO_ROOT}:/ci:ro" \
--workdir "/ci" \
local LINT=( --name eclint \
eclint "mstruebing/editorconfig-checker:${ECLINT_VERSION}" ec -config "/ci/test/linting/.ecrc.json"
-config
"${CDIR}/test/linting/.ecrc.json"
-exclude
"(${IGNORE})"
)
if ! __in_path "${LINT[0]}"
then
__log_failure 'linter not in PATH'
return 2
fi
__log_info "$(${LINT[0]} --version)"
if "${LINT[@]}"
then then
__log_success __log_success
else else
@ -82,17 +74,11 @@ function _eclint
function _hadolint function _hadolint
{ {
local SCRIPT='HADOLINT' local SCRIPT='HADOLINT'
local LINT=(hadolint -c "${CDIR}/test/linting/.hadolint.yaml")
if ! __in_path "${LINT[0]}" if docker run --rm --tty \
then --volume "${REPO_ROOT}:/ci:ro" \
__log_failure 'linter not in PATH' --workdir "/ci" \
return 2 "hadolint/hadolint:v${HADOLINT_VERSION}-alpine" hadolint --config "/ci/test/linting/.hadolint.yaml" Dockerfile
fi
__log_info "$(${LINT[0]} --version | grep -E -o "[0-9\.]*")"
if "${LINT[@]}" Dockerfile
then then
__log_success __log_success
else else
@ -104,73 +90,42 @@ function _hadolint
function _shellcheck function _shellcheck
{ {
local SCRIPT='SHELLCHECK' local SCRIPT='SHELLCHECK'
local ERR=0
local LINT=(shellcheck -x -S style -Cauto -o all -e SC2154 -W 50)
if ! __in_path "${LINT[0]}" # File paths for shellcheck:
then F_SH="$(find . -type f -iname '*.sh' \
__log_failure 'linter not in PATH' -not -path './test/bats/*' \
return 2 -not -path './test/test_helper/*' \
fi -not -path './target/docker-configomat/*'
)"
# macOS lacks parity for `-executable` but presently produces the same results: https://stackoverflow.com/a/4458361
[[ "$(uname)" == "Darwin" ]] && FIND_EXEC="-perm +111 -type l -or" || FIND_EXEC="-executable"
# shellcheck disable=SC2248
F_BIN="$(find 'target/bin' ${FIND_EXEC} -type f)"
F_BATS="$(find 'test' -maxdepth 1 -type f -iname '*.bats')"
__log_info "$(${LINT[0]} --version | grep -m 2 -o "[0-9.]*")" # This command is a bit easier to grok as multi-line. There is a `.shellcheckrc` file, but it's only supports half of the options below, thus kept as CLI:
CMD_SHELLCHECK=(shellcheck
# an overengineered solution to allow shellcheck -x to --external-sources
# properly follow `source=<SOURCE FILE>` when sourcing --check-sourced
# files with `. <FILE>` in shell scripts. --severity=style
while read -r FILE --color=auto
do --wiki-link-count=50
if ! ( --enable=all
cd "$(realpath "$(dirname "$(readlink -f "${FILE}")")")" --exclude=SC2154
if ! "${LINT[@]}" "$(basename -- "${FILE}")" --source-path=SCRIPTDIR
then "${F_SH} ${F_BIN} ${F_BATS}"
exit 1
fi
) )
then
ERR=1
fi
done < <(find . -type f -iname "*.sh" \
-not -path "./test/bats/*" \
-not -path "./test/test_helper/*" \
-not -path "./target/docker-configomat/*")
# the same for executables in target/bin/ # shellcheck disable=SC2068
while read -r FILE if docker run --rm --tty \
do --volume "${REPO_ROOT}:/ci:ro" \
if ! ( --workdir "/ci" \
cd "$(realpath "$(dirname "$(readlink -f "${FILE}")")")" "koalaman/shellcheck-alpine:v${SHELLCHECK_VERSION}" ${CMD_SHELLCHECK[@]}
if ! "${LINT[@]}" "$(basename -- "${FILE}")"
then then
exit 1
fi
)
then
ERR=1
fi
done < <(find target/bin -executable -type f)
# the same for all test files
while read -r FILE
do
if ! (
cd "$(realpath "$(dirname "$(readlink -f "${FILE}")")")"
if ! "${LINT[@]}" "$(basename -- "${FILE}")"
then
exit 1
fi
)
then
ERR=1
fi
done < <(find test/ -maxdepth 1 -type f -iname "*.bats")
if [[ ${ERR} -eq 1 ]]
then
__log_failure 'errors encountered'
return 1
else
__log_success __log_success
else
__log_failure
return 1
fi fi
} }
@ -187,8 +142,4 @@ function __main
esac esac
} }
# prefer linters installed in tools
PATH="${CDIR}/tools:${PATH}"
export PATH
__main "${@}" || exit ${?} __main "${@}" || exit ${?}

View file

@ -12,7 +12,7 @@ function setup_file() {
# We use a temporary config directory since we'll be dynamically editing # We use a temporary config directory since we'll be dynamically editing
# it with setup.sh. # it with setup.sh.
tmp_confdir=$(mktemp -d /tmp/docker-mailserver-config-relay-hosts-XXXXX) tmp_confdir=$(mktemp -d /tmp/docker-mailserver-config-relay-hosts-XXXXX)
cp -aT test/config/relay-hosts "${tmp_confdir}" cp -a test/config/relay-hosts/* "${tmp_confdir}/"
docker run -d --name mail_with_relays \ docker run -d --name mail_with_relays \
-v "${tmp_confdir}":/tmp/docker-mailserver \ -v "${tmp_confdir}":/tmp/docker-mailserver \
@ -39,12 +39,12 @@ function teardown_file() {
@test "checking relay hosts: default mapping is added from env vars" { @test "checking relay hosts: default mapping is added from env vars" {
run docker exec mail_with_relays grep -e domainone.tld /etc/postfix/relayhost_map run docker exec mail_with_relays grep -e domainone.tld /etc/postfix/relayhost_map
assert_output -e '^@domainone.tld\s+\[default.relay.com\]:2525$' assert_output -e '^@domainone.tld[[:space:]]+\[default.relay.com\]:2525$'
} }
@test "checking relay hosts: default mapping is added from env vars for virtual user entry" { @test "checking relay hosts: default mapping is added from env vars for virtual user entry" {
run docker exec mail_with_relays grep -e domain1.tld /etc/postfix/relayhost_map run docker exec mail_with_relays grep -e domain1.tld /etc/postfix/relayhost_map
assert_output -e '^@domain1.tld\s+\[default.relay.com\]:2525$' assert_output -e '^@domain1.tld[[:space:]]+\[default.relay.com\]:2525$'
} }
@test "checking relay hosts: default mapping is added from env vars for new user entry" { @test "checking relay hosts: default mapping is added from env vars for new user entry" {
@ -52,7 +52,7 @@ function teardown_file() {
assert_output '' assert_output ''
run ./setup.sh -c mail_with_relays email add user0@domainzero.tld password123 run ./setup.sh -c mail_with_relays email add user0@domainzero.tld password123
run_until_success_or_timeout 10 docker exec mail_with_relays grep -e domainzero.tld /etc/postfix/relayhost_map run_until_success_or_timeout 10 docker exec mail_with_relays grep -e domainzero.tld /etc/postfix/relayhost_map
assert_output -e '^@domainzero.tld\s+\[default.relay.com\]:2525$' assert_output -e '^@domainzero.tld[[:space:]]+\[default.relay.com\]:2525$'
} }
@test "checking relay hosts: default mapping is added from env vars for new virtual user entry" { @test "checking relay hosts: default mapping is added from env vars for new virtual user entry" {
@ -60,12 +60,12 @@ function teardown_file() {
assert_output '' assert_output ''
run ./setup.sh -c mail_with_relays alias add user2@domain2.tld user2@domaintwo.tld run ./setup.sh -c mail_with_relays alias add user2@domain2.tld user2@domaintwo.tld
run_until_success_or_timeout 10 docker exec mail_with_relays grep -e domain2.tld /etc/postfix/relayhost_map run_until_success_or_timeout 10 docker exec mail_with_relays grep -e domain2.tld /etc/postfix/relayhost_map
assert_output -e '^@domain2.tld\s+\[default.relay.com\]:2525$' assert_output -e '^@domain2.tld[[:space:]]+\[default.relay.com\]:2525$'
} }
@test "checking relay hosts: custom mapping is added from file" { @test "checking relay hosts: custom mapping is added from file" {
run docker exec mail_with_relays grep -e domaintwo.tld /etc/postfix/relayhost_map run docker exec mail_with_relays grep -e domaintwo.tld /etc/postfix/relayhost_map
assert_output -e '^@domaintwo.tld\s+\[other.relay.com\]:587$' assert_output -e '^@domaintwo.tld[[:space:]]+\[other.relay.com\]:587$'
} }
@test "checking relay hosts: ignored domain is not added" { @test "checking relay hosts: ignored domain is not added" {