From 140b29ef5abd9f40fc47fc9cf8606b4add05f059 Mon Sep 17 00:00:00 2001 From: Tobias Kaupat Date: Sun, 18 Oct 2026 10:40:42 +0200 Subject: [PATCH] test: check the msmtp config copy at real container startup Co-Authored-By: Claude Sonnet 5.5 --- test/features.sh | 8 ++++---- test/lib.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/test/features.sh b/test/features.sh index 0446251..c3f77e4 100644 --- a/test/features.sh +++ b/test/features.sh @@ -133,13 +133,13 @@ if require_feature msmtp "PR #84"; then assert_contains "$sendmail_target" "msmtp" \ "sendmail is provided by msmtp" - start_container msmtp-config - if wait_for_start; then - write_file /config/msmtprc 'defaults + # The config has to be in place when the container starts, entry.sh copies + # it. Re-running entry.sh in a live container would start a second crond. + start_container_with_file msmtp-config /config/msmtprc 'defaults account default host localhost ' - in_container /entry.sh true >/dev/null 2>&1 + if wait_for_start; then if in_container test -f /etc/msmtprc; then pass "msmtp config from /config is copied to /etc/msmtprc" mode="$(in_container stat -c '%a' /etc/msmtprc 2>&1 | tr -d '\r')" diff --git a/test/lib.sh b/test/lib.sh index d8d036b..1dc496f 100644 --- a/test/lib.sh +++ b/test/lib.sh @@ -128,6 +128,34 @@ start_container() { "$IMAGE" >/dev/null } +# start_container_with_file [extra docker run args...] +# Like start_container, but the file exists before entry.sh runs, so tests can +# cover what the entrypoint does with it at real container startup. The file is +# placed with `docker create` + `docker cp`, no bind mount. +start_container_with_file() { + local suffix="$1" path="$2" content="$3" + shift 3 + local seed seed_src + seed="$(mktemp -d)" + printf '%s' "$content" > "${seed}/$(basename "$path")" + CONTAINER="rbd-test-${suffix}-$$" + docker rm -f "$CONTAINER" >/dev/null 2>&1 || true + docker create --name "$CONTAINER" \ + -e RESTIC_PASSWORD=testpassword \ + -e RESTIC_TAG=testtag \ + -e "BACKUP_CRON=0 0 31 2 *" \ + "$@" \ + "$IMAGE" >/dev/null + if command -v cygpath >/dev/null 2>&1; then + seed_src="$(cygpath -w "$seed")" + else + seed_src="$seed" + fi + docker cp "${seed_src}/." "${CONTAINER}:$(dirname "$path")" + rm -rf "$seed" + docker start "$CONTAINER" >/dev/null +} + stop_container() { [ -n "$CONTAINER" ] || return 0 docker rm -f "$CONTAINER" >/dev/null 2>&1 || true