Add explanatory comments to all test scripts

This commit is contained in:
2026-06-02 23:36:18 +01:00
parent fe8744e20e
commit 34b2515fca
5 changed files with 61 additions and 13 deletions
+36 -6
View File
@@ -5,8 +5,10 @@ ROOT="$(dirname "$(realpath "$0")")/.."
pass=0
fail=0
# Allow overriding gomplate binary path via env var
gomplate="${GOMPLATE_BIN:-gomplate}"
# Ensure gomplate is installed before running template tests
require_gomplate() {
if ! command -v "$gomplate" &>/dev/null; then
echo "gomplate not found. Install it from https://github.com/hairyhenderson/gomplate"
@@ -24,14 +26,19 @@ render() {
-f "$tmpl" 2>/dev/null
}
# Render by exporting env vars directly (avoids gomplate datasource quirks)
# Render a template by exporting env vars directly
# This avoids gomplate datasource quirks with .env files
render_via_env() {
local tmpl=$1 envfile=$2
# shellcheck disable=2046
env $(xargs < "$envfile") "$gomplate" -f "$tmpl" 2>/dev/null
}
# --- entrypoint.sh.tmpl tests ---
# ---------------------------------------------------------------------------
# entrypoint.sh.tmpl tests
# ---------------------------------------------------------------------------
# Default entrypoint: no multisite, uploads guard, chown with --from, wp-cli
test_entrypoint_default() {
local envfile=$1
local output
@@ -60,6 +67,7 @@ test_entrypoint_default() {
echo " PASS entrypoint default"
}
# Multisite enable: should set WP_ALLOW_MULTISITE
test_entrypoint_multisite_enable() {
local envfile=$1
local output
@@ -72,6 +80,7 @@ test_entrypoint_multisite_enable() {
echo " PASS entrypoint multisite enable"
}
# Multisite subdomain: should set MULTISITE, SUBDOMAIN_INSTALL, DOMAIN_CURRENT_SITE
test_entrypoint_multisite_subdomain() {
local envfile=$1
local output
@@ -92,6 +101,7 @@ test_entrypoint_multisite_subdomain() {
echo " PASS entrypoint multisite subdomain"
}
# Multisite subfolder: should set MULTISITE but not SUBDOMAIN_INSTALL
test_entrypoint_multisite_subfolder() {
local envfile=$1
local output
@@ -108,6 +118,7 @@ test_entrypoint_multisite_subfolder() {
echo " PASS entrypoint multisite subfolder"
}
# CORS: should enable Apache headers module and set Access-Control-Allow-Origin
test_entrypoint_cors() {
local envfile=$1
local output
@@ -124,6 +135,7 @@ test_entrypoint_cors() {
echo " PASS entrypoint CORS"
}
# PHP extensions: should install additional PHP extensions like calendar
test_entrypoint_php_extensions() {
local envfile=$1
local output
@@ -136,6 +148,7 @@ test_entrypoint_php_extensions() {
echo " PASS entrypoint PHP extensions"
}
# Composer: should download Composer via getcomposer.org
test_entrypoint_composer() {
local envfile=$1
local output
@@ -148,7 +161,11 @@ test_entrypoint_composer() {
echo " PASS entrypoint composer"
}
# --- htaccess.tmpl tests ---
# ---------------------------------------------------------------------------
# htaccess.tmpl tests
# ---------------------------------------------------------------------------
# Default htaccess: standard WordPress rewrite rule, no multisite section
test_htaccess_default() {
local envfile=$1
local output
@@ -165,6 +182,7 @@ test_htaccess_default() {
echo " PASS htaccess default"
}
# Multisite htaccess: multisite section present, no standard rewrite rule
test_htaccess_multisite() {
local envfile=$1 mode=$2
local output
@@ -181,7 +199,11 @@ test_htaccess_multisite() {
echo " PASS htaccess multisite $mode"
}
# --- uploads.ini.tmpl tests ---
# ---------------------------------------------------------------------------
# uploads.ini.tmpl tests
# ---------------------------------------------------------------------------
# Default uploads config: 256M upload limit, 30s execution time
test_uploads_default() {
local output
output=$(render_via_env "uploads.ini.tmpl" "tests/fixtures/default.env")
@@ -197,6 +219,7 @@ test_uploads_default() {
echo " PASS uploads default"
}
# Custom uploads config: 512M upload limit, 60s execution time
test_uploads_custom() {
local envfile=$1
local output
@@ -213,7 +236,11 @@ test_uploads_custom() {
echo " PASS uploads custom"
}
# --- msmtp.conf.tmpl tests ---
# ---------------------------------------------------------------------------
# msmtp.conf.tmpl tests
# ---------------------------------------------------------------------------
# Full SMTP config: host, from, auth, passwordeval, TLS, set_from_header
test_msmtp_default() {
local output
output=$(render_via_env "msmtp.conf.tmpl" "tests/fixtures/smtp-full.env")
@@ -245,7 +272,9 @@ test_msmtp_default() {
echo " PASS msmtp full config"
}
# --- Run all template tests ---
# ---------------------------------------------------------------------------
# Run all template tests
# ---------------------------------------------------------------------------
echo "=== Template Rendering Tests ==="
cd "$ROOT"
@@ -275,4 +304,5 @@ test_msmtp_default && pass=$((pass+1)) || fail=$((fail+1))
echo "---"
echo "Passed: $pass Failed: $fail"
# Exit with failure if any template test failed
[ "$fail" -eq 0 ]