mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-21 16:23:34 +08:00
优化 Docker 启动完成日志 (#6112)
This commit is contained in:
@@ -78,6 +78,26 @@ def _run_permission_case(tmp_path: Path, body: str, env: dict[str, str] | None =
|
||||
return chown_log.read_text(encoding="utf-8") if chown_log.exists() else ""
|
||||
|
||||
|
||||
def _run_entrypoint_case(tmp_path: Path, body: str, env: dict[str, str] | None = None) -> str:
|
||||
functions = _write_entrypoint_functions(tmp_path)
|
||||
case_env = {
|
||||
**os.environ,
|
||||
"ENTRYPOINT_FUNCTIONS": str(functions),
|
||||
}
|
||||
if env:
|
||||
case_env.update(env)
|
||||
|
||||
script = textwrap.dedent(
|
||||
f"""\
|
||||
set -euo pipefail
|
||||
source "${{ENTRYPOINT_FUNCTIONS}}"
|
||||
{body}
|
||||
"""
|
||||
)
|
||||
result = subprocess.run(["bash", "-c", script], check=True, env=case_env, text=True, capture_output=True)
|
||||
return result.stdout
|
||||
|
||||
|
||||
def test_image_paths_are_not_chowned_by_default_regardless_of_owner(tmp_path: Path) -> None:
|
||||
log = _run_permission_case(
|
||||
tmp_path,
|
||||
@@ -170,3 +190,56 @@ def test_runtime_writable_paths_are_still_corrected(tmp_path: Path) -> None:
|
||||
assert not any(line.startswith("-R ") and ".cloakbrowser" in line for line in lines)
|
||||
assert not any(f"{tmp_path}/app " in line for line in lines)
|
||||
assert not any(f"{tmp_path}/public" in line for line in lines)
|
||||
|
||||
|
||||
def test_backend_ready_log_uses_configured_ports(tmp_path: Path) -> None:
|
||||
curl_log = tmp_path / "curl.log"
|
||||
output = _run_entrypoint_case(
|
||||
tmp_path,
|
||||
"""
|
||||
INFO() { printf '[INFO] %s\\n' "$1"; }
|
||||
curl() {
|
||||
printf '%s\\n' "$*" > "${CURL_LOG}"
|
||||
return 0
|
||||
}
|
||||
PORT=4321 NGINX_PORT=8765 wait_backend_ready 1 2 "$$"
|
||||
""",
|
||||
env={"CURL_LOG": str(curl_log)},
|
||||
)
|
||||
|
||||
assert curl_log.read_text(encoding="utf-8") == (
|
||||
"-fsS --max-time 2 http://127.0.0.1:4321/api/v1/system/global?token=moviepilot\n"
|
||||
)
|
||||
assert "MoviePilot Web 已可访问" in output
|
||||
assert "后端就绪耗时" in output
|
||||
assert "后端端口 4321" in output
|
||||
assert "前端端口 8765" in output
|
||||
|
||||
|
||||
def test_backend_ready_timeout_falls_back_to_default_for_invalid_value(tmp_path: Path) -> None:
|
||||
output = _run_entrypoint_case(
|
||||
tmp_path,
|
||||
"""
|
||||
WARN() { printf '[WARN] %s\\n' "$1"; }
|
||||
curl() { return 1; }
|
||||
MOVIEPILOT_BACKEND_READY_TIMEOUT=invalid wait_backend_ready 1 2 999999 || true
|
||||
""",
|
||||
)
|
||||
|
||||
assert "MOVIEPILOT_BACKEND_READY_TIMEOUT=invalid 无效,使用默认 300 秒" in output
|
||||
assert "后端服务启动完成探测已停止:后端进程已退出" in output
|
||||
|
||||
|
||||
def test_backend_ready_timeout_accepts_leading_zero_decimal(tmp_path: Path) -> None:
|
||||
output = _run_entrypoint_case(
|
||||
tmp_path,
|
||||
"""
|
||||
INFO() { printf '[INFO] %s\\n' "$1"; }
|
||||
WARN() { printf '[WARN] %s\\n' "$1"; }
|
||||
curl() { return 0; }
|
||||
MOVIEPILOT_BACKEND_READY_TIMEOUT=08 wait_backend_ready 1 2 "$$"
|
||||
""",
|
||||
)
|
||||
|
||||
assert "MOVIEPILOT_BACKEND_READY_TIMEOUT=08 无效" not in output
|
||||
assert "MoviePilot Web 已可访问" in output
|
||||
|
||||
Reference in New Issue
Block a user