This commit is contained in:
1 parent
6520152282
commit
646ba3be81
3 files changed
+27
-15
No files matched your search
+13
-1
@@ -14,6 +14,12 @@ import unittest
|
||||
@unittest.skipUnless(shutil.which("rsync") and shutil.which("flock"), "deployment tools are not installed")
|
||||
class DeploymentTests(unittest.TestCase):
|
||||
def test_deploy_preserves_runtime_and_archive_and_restarts_service(self):
|
||||
self._run_deployment(archive_exists=True)
|
||||
|
||||
def test_deploy_creates_archive_before_restarting_service(self):
|
||||
self._run_deployment(archive_exists=False)
|
||||
|
||||
def _run_deployment(self, *, archive_exists):
|
||||
workflow = (Path(__file__).resolve().parents[1] / ".gitea/workflows/deploy.yml").read_text()
|
||||
deploy_step = workflow.split("- name: Deploy and restart\n", 1)[1]
|
||||
script = textwrap.dedent(deploy_step.split("run: |\n", 1)[1])
|
||||
@@ -34,6 +40,8 @@ class DeploymentTests(unittest.TestCase):
|
||||
".venv/keep.txt": "runtime venv",
|
||||
".git/keep.txt": "existing checkout metadata",
|
||||
}
|
||||
if not archive_exists:
|
||||
del protected["data/archive/date=2026-11-01/samples.parquet"]
|
||||
for relative, content in protected.items():
|
||||
target = deployment / relative
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
@@ -47,7 +55,7 @@ class DeploymentTests(unittest.TestCase):
|
||||
runtime.chmod(0o755)
|
||||
mocks = {
|
||||
"sudo": '#!/bin/sh\n[ "$1" = "-n" ] || exit 99\nshift\nexec "$@"\n',
|
||||
"systemctl": '#!/bin/sh\nprintf "%s\\n" "$*" >> "$SOLAR_DEPLOY_TEST_LOG"\nif [ "$1" = show ]; then printf "0\\n"; fi\n',
|
||||
"systemctl": '#!/bin/sh\nif [ "$1" = restart ] && [ ! -d "$DEPLOY_PATH/data/archive" ]; then echo "Archive directory is missing before service restart" >&2; exit 1; fi\nprintf "%s\\n" "$*" >> "$SOLAR_DEPLOY_TEST_LOG"\nif [ "$1" = show ]; then printf "0\\n"; fi\n',
|
||||
"sleep": "#!/bin/sh\nexit 0\n",
|
||||
"curl": '#!/bin/sh\nprintf "curl %s\\n" "$*" >> "$SOLAR_DEPLOY_TEST_LOG"\n',
|
||||
}
|
||||
@@ -61,6 +69,10 @@ class DeploymentTests(unittest.TestCase):
|
||||
"HEALTH_URL": "https://rpioffice.nest.lutran.ch/solar-relay/healthz"}
|
||||
result = subprocess.run(["bash", "-c", script], cwd=checkout, env=env, capture_output=True, text=True, timeout=15)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertTrue((deployment / "data/archive").is_dir())
|
||||
if not archive_exists:
|
||||
for relative in ("data", "data/archive"):
|
||||
self.assertEqual((deployment / relative).stat().st_mode & 0o777, 0o700)
|
||||
self.assertTrue((deployment / "solar_relay/new.py").exists())
|
||||
self.assertFalse((deployment / "obsolete.py").exists())
|
||||
for relative, content in protected.items():
|
||||
|
||||
Reference in new issue
Block a user