You've already forked docker-mailserver
mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-08-08 23:06:49 +02:00
tests: improve _send_email
(#3105)
This commit is contained in:
@ -7,25 +7,29 @@
|
||||
# ! ATTENTION: This file is loaded by `common.sh` - do not load it yourself!
|
||||
# ! ATTENTION: This file requires helper functions from `common.sh`!
|
||||
|
||||
# Sends a mail from localhost (127.0.0.1) via port 25 to the container. To send
|
||||
# a custom email, create a file at `test/test-files/email-templates/<TEST FILE>`,
|
||||
# Sends a mail from localhost (127.0.0.1) to a container. To send
|
||||
# a custom email, create a file at `test/test-files/<TEST FILE>`,
|
||||
# and provide `<TEST FILE>` as an argument to this function.
|
||||
#
|
||||
# @param ${1} = template file (path) name
|
||||
# @param ${2} = container name [OPTIONAL]
|
||||
# @param ${3} = port `nc` will use [OPTIONAL]
|
||||
# @param ${2} = parameters for `nc` [OPTIONAL] (default: `0.0.0.0 25`)
|
||||
#
|
||||
# ## Attention
|
||||
#
|
||||
# This function assumes `CONTAINER_NAME` to be properly set (to the container
|
||||
# name the command should be executed in)!
|
||||
#
|
||||
# This function will just send the email in an "asynchronous" fashion, i.e. it will
|
||||
# send the email but it will not make sure the mail queue is empty after the mail
|
||||
# has been sent.
|
||||
function _send_email() {
|
||||
local TEMPLATE_FILE=${1:?Must provide name of template file}
|
||||
local CONTAINER_NAME=$(__handle_container_name "${2:-}")
|
||||
local PORT=${3:-25}
|
||||
local NC_PARAMETERS=${2:-0.0.0.0 25}
|
||||
|
||||
_run_in_container_bash "nc 0.0.0.0 ${PORT} < /tmp/docker-mailserver-test/email-templates/${TEMPLATE_FILE}.txt"
|
||||
assert_not_equal "${NC_PARAMETERS}" ''
|
||||
assert_not_equal "${CONTAINER_NAME:-}" ''
|
||||
|
||||
_run_in_container_bash "nc ${NC_PARAMETERS} < /tmp/docker-mailserver-test/${TEMPLATE_FILE}.txt"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@ -39,7 +43,12 @@ function _send_email() {
|
||||
# test file and need to assert certain log entries for each mail individually.
|
||||
#
|
||||
# @param ${1} = template file (path) name
|
||||
# @param ${2} = container name [OPTIONAL]
|
||||
# @param ${2} = parameters for `nc` [OPTIONAL] (default: `0.0.0.0 25`)
|
||||
#
|
||||
# ## Attention
|
||||
#
|
||||
# This function assumes `CONTAINER_NAME` to be properly set (to the container
|
||||
# name the command should be executed in)!
|
||||
#
|
||||
# ## Safety
|
||||
#
|
||||
@ -47,11 +56,14 @@ function _send_email() {
|
||||
# If two clients send simultaneously, there is no guarantee the correct ID is
|
||||
# chosen. Sending more than one mail at any given point in time with this function
|
||||
# is UNDEFINED BEHAVIOR!
|
||||
function _send_mail_and_get_id() {
|
||||
function _send_email_and_get_id() {
|
||||
local TEMPLATE_FILE=${1:?Must provide name of template file}
|
||||
local CONTAINER_NAME=$(__handle_container_name "${2:-}")
|
||||
local NC_PARAMETERS=${2:-0.0.0.0 25}
|
||||
local MAIL_ID
|
||||
|
||||
assert_not_equal "${NC_PARAMETERS}" ''
|
||||
assert_not_equal "${CONTAINER_NAME:-}" ''
|
||||
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
_send_email "${TEMPLATE_FILE}"
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
@ -63,8 +75,6 @@ function _send_mail_and_get_id() {
|
||||
| grep -E -m 1 'postfix/smtpd.*: [A-Z0-9]+: client=localhost' \
|
||||
| grep -E -o '[A-Z0-9]{9,12}' || true)
|
||||
|
||||
run bash -c "-z ${MAIL_ID}"
|
||||
assert_success 'Could not obtain mail ID - aborting!'
|
||||
|
||||
assert_not_equal "${MAIL_ID}" ''
|
||||
echo "${MAIL_ID}"
|
||||
}
|
||||
|
Reference in New Issue
Block a user