M6.5: enroll n8n (recipe #6, workflow automation) — tests authored (single-service, .n8n volume)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
7
tests/n8n/recipe_meta.py
Normal file
7
tests/n8n/recipe_meta.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# Per-recipe harness config for n8n (recipe #6 — workflow automation; single-service, stateful via
|
||||||
|
# the /home/node/.n8n volume, sqlite by default). Normal terminate-at-Traefik (no passthrough).
|
||||||
|
# n8n exposes /healthz (200 {"status":"ok"}) once up.
|
||||||
|
HEALTH_PATH = "/healthz"
|
||||||
|
HEALTH_OK = (200,)
|
||||||
|
DEPLOY_TIMEOUT = 600
|
||||||
|
HTTP_TIMEOUT = 300
|
||||||
29
tests/n8n/test_backup.py
Normal file
29
tests/n8n/test_backup.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
"""n8n — backup/restore stage (D2): write a marker into the backed-up /home/node/.n8n path, backup,
|
||||||
|
mutate, restore, assert the restored state matches the pre-mutation state.
|
||||||
|
|
||||||
|
The n8n `app` service is labelled `backupbot.backup=true` with `backupbot.backup.path=/home/node/.n8n`,
|
||||||
|
so a marker file there is backed up; checked via `exec_in_app`."""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "runner"))
|
||||||
|
from harness import lifecycle # noqa: E402
|
||||||
|
|
||||||
|
MARKER = "/home/node/.n8n/ci-marker.txt"
|
||||||
|
|
||||||
|
|
||||||
|
def test_backup_mutate_restore(deployed, meta):
|
||||||
|
domain = deployed
|
||||||
|
|
||||||
|
lifecycle.exec_in_app(domain, ["sh", "-c", f"echo original > {MARKER}"])
|
||||||
|
assert lifecycle.exec_in_app(domain, ["cat", MARKER]).strip() == "original"
|
||||||
|
lifecycle.backup_app(domain)
|
||||||
|
|
||||||
|
lifecycle.exec_in_app(domain, ["sh", "-c", f"echo mutated > {MARKER}"])
|
||||||
|
assert lifecycle.exec_in_app(domain, ["cat", MARKER]).strip() == "mutated"
|
||||||
|
|
||||||
|
lifecycle.restore_app(domain)
|
||||||
|
lifecycle.wait_healthy(domain, ok_codes=tuple(meta["HEALTH_OK"]), path=meta["HEALTH_PATH"],
|
||||||
|
deploy_timeout=meta["DEPLOY_TIMEOUT"], http_timeout=meta["HTTP_TIMEOUT"])
|
||||||
|
assert lifecycle.exec_in_app(domain, ["cat", MARKER]).strip() == "original", \
|
||||||
|
"restore did not return the pre-mutation state"
|
||||||
29
tests/n8n/test_install.py
Normal file
29
tests/n8n/test_install.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
"""n8n — install stage (recipe #6, workflow automation). D2 install + D3 Playwright."""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "runner"))
|
||||||
|
from harness import lifecycle # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
|
def test_healthz(deployed_app):
|
||||||
|
status = lifecycle.http_get(deployed_app, "/healthz")
|
||||||
|
assert status == 200, f"expected 200 from {deployed_app}/healthz, got {status}"
|
||||||
|
|
||||||
|
|
||||||
|
def test_playwright_loads_editor(deployed_app):
|
||||||
|
"""A real browser loads the live n8n editor SPA over HTTPS."""
|
||||||
|
from playwright.sync_api import sync_playwright
|
||||||
|
|
||||||
|
url = f"https://{deployed_app}/"
|
||||||
|
with sync_playwright() as p:
|
||||||
|
browser = p.chromium.launch(args=["--no-sandbox"])
|
||||||
|
try:
|
||||||
|
ctx = browser.new_context(ignore_https_errors=True)
|
||||||
|
page = ctx.new_page()
|
||||||
|
resp = page.goto(url, wait_until="domcontentloaded", timeout=60000)
|
||||||
|
assert resp is not None and resp.status in (200, 304), f"page status {resp and resp.status}"
|
||||||
|
body = page.content().lower()
|
||||||
|
assert "n8n" in body or "<html" in body, "no n8n content served"
|
||||||
|
finally:
|
||||||
|
browser.close()
|
||||||
41
tests/n8n/test_upgrade.py
Normal file
41
tests/n8n/test_upgrade.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
"""n8n — upgrade stage (D2): deploy the previous published version, write a data marker into the
|
||||||
|
persistent /home/node/.n8n volume, upgrade to current/$REF, assert health + data survival.
|
||||||
|
|
||||||
|
n8n state lives in the .n8n volume (sqlite + config); the marker is a file there, read back via
|
||||||
|
`exec_in_app` (not HTTP-served)."""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "runner"))
|
||||||
|
from harness import lifecycle # noqa: E402
|
||||||
|
|
||||||
|
MARKER = "/home/node/.n8n/ci-marker.txt"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def old_app(recipe, app_domain, meta, request):
|
||||||
|
prev = lifecycle.previous_version(recipe)
|
||||||
|
if not prev:
|
||||||
|
pytest.skip(f"{recipe}: no previous published version to upgrade from")
|
||||||
|
lifecycle.janitor()
|
||||||
|
request.addfinalizer(lambda: lifecycle.teardown_app(app_domain))
|
||||||
|
lifecycle.deploy_app(recipe, app_domain, version=prev)
|
||||||
|
lifecycle.wait_healthy(app_domain, ok_codes=tuple(meta["HEALTH_OK"]), path=meta["HEALTH_PATH"],
|
||||||
|
deploy_timeout=meta["DEPLOY_TIMEOUT"], http_timeout=meta["HTTP_TIMEOUT"])
|
||||||
|
return app_domain, prev
|
||||||
|
|
||||||
|
|
||||||
|
def test_upgrade_preserves_data(old_app, meta):
|
||||||
|
domain, prev = old_app
|
||||||
|
lifecycle.exec_in_app(domain, ["sh", "-c", f"echo upgrade-survives > {MARKER}"])
|
||||||
|
assert lifecycle.exec_in_app(domain, ["cat", MARKER]).strip() == "upgrade-survives"
|
||||||
|
|
||||||
|
lifecycle.upgrade_app(domain, version=os.environ.get("VERSION") or None)
|
||||||
|
lifecycle.wait_healthy(domain, ok_codes=tuple(meta["HEALTH_OK"]), path=meta["HEALTH_PATH"],
|
||||||
|
deploy_timeout=meta["DEPLOY_TIMEOUT"], http_timeout=meta["HTTP_TIMEOUT"])
|
||||||
|
|
||||||
|
assert lifecycle.http_get(domain, meta["HEALTH_PATH"]) == 200
|
||||||
|
assert lifecycle.exec_in_app(domain, ["cat", MARKER]).strip() == "upgrade-survives", \
|
||||||
|
"data did not survive the upgrade"
|
||||||
Reference in New Issue
Block a user