62 lines
2.6 KiB
Python
62 lines
2.6 KiB
Python
|
|
"""Tests for bin/deploy-box-web.sh."""
|
||
|
|
import os
|
||
|
|
import subprocess
|
||
|
|
import tarfile
|
||
|
|
import unittest
|
||
|
|
|
||
|
|
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||
|
|
SCRIPT_PATH = os.path.join(REPO_ROOT, "bin", "deploy-box-web.sh")
|
||
|
|
|
||
|
|
class TestDeployBoxWeb(unittest.TestCase):
|
||
|
|
def test_script_exists_and_executable(self):
|
||
|
|
self.assertTrue(os.path.exists(SCRIPT_PATH), f"Missing script: {SCRIPT_PATH}")
|
||
|
|
self.assertTrue(os.access(SCRIPT_PATH, os.X_OK), "Script not executable")
|
||
|
|
|
||
|
|
def test_bash_syntax(self):
|
||
|
|
proc = subprocess.run(["bash", "-n", SCRIPT_PATH], capture_output=True, text=True)
|
||
|
|
self.assertEqual(proc.returncode, 0, f"Syntax error in script: {proc.stderr}")
|
||
|
|
|
||
|
|
def test_dry_run_output(self):
|
||
|
|
proc = subprocess.run([SCRIPT_PATH, "--dry-run"], capture_output=True, text=True)
|
||
|
|
self.assertEqual(proc.returncode, 0, f"Dry-run failed: {proc.stderr}")
|
||
|
|
self.assertIn("Box Web Console Deployment Plan", proc.stdout)
|
||
|
|
self.assertIn("34.139.37.135", proc.stdout)
|
||
|
|
self.assertIn("/srv/box/www", proc.stdout)
|
||
|
|
self.assertIn("index.html", proc.stdout)
|
||
|
|
self.assertIn("box.js", proc.stdout)
|
||
|
|
self.assertIn("box.css", proc.stdout)
|
||
|
|
self.assertIn("DRY-RUN (no changes)", proc.stdout)
|
||
|
|
self.assertIn("sha256:", proc.stdout)
|
||
|
|
|
||
|
|
def test_custom_parameters(self):
|
||
|
|
cmd = [
|
||
|
|
SCRIPT_PATH,
|
||
|
|
"--host", "custom.domain.net",
|
||
|
|
"--user", "deployer",
|
||
|
|
"--dest", "/opt/box/web",
|
||
|
|
"--dry-run"
|
||
|
|
]
|
||
|
|
proc = subprocess.run(cmd, capture_output=True, text=True)
|
||
|
|
self.assertEqual(proc.returncode, 0)
|
||
|
|
self.assertIn("deployer@custom.domain.net:/opt/box/web", proc.stdout)
|
||
|
|
|
||
|
|
def test_bundle_only(self):
|
||
|
|
proc = subprocess.run([SCRIPT_PATH, "--bundle-only"], capture_output=True, text=True)
|
||
|
|
self.assertEqual(proc.returncode, 0, f"Bundle creation failed: {proc.stderr}")
|
||
|
|
self.assertIn("Archive created", proc.stdout)
|
||
|
|
# Extract bundle path from output
|
||
|
|
for line in proc.stdout.splitlines():
|
||
|
|
if "Bundle generated at" in line:
|
||
|
|
bundle_path = line.split("Bundle generated at")[1].strip().split()[0].rstrip(".")
|
||
|
|
self.assertTrue(os.path.exists(bundle_path))
|
||
|
|
with tarfile.open(bundle_path, "r:gz") as tar:
|
||
|
|
names = tar.getnames()
|
||
|
|
self.assertIn("index.html", names)
|
||
|
|
self.assertIn("box.js", names)
|
||
|
|
self.assertIn("box.css", names)
|
||
|
|
os.remove(bundle_path)
|
||
|
|
break
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
unittest.main()
|