Something went wrong. Try again.
deployment templates for lichen
Something went wrong. Try again.
2.9 kB · 52 lines
Python
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253"""Exercise the container entrypoint without touching a container or deployment."""
import jsonimport osfrom pathlib import Pathimport subprocessimport tempfileimport unittest
class EntrypointTests(unittest.TestCase): """Both admin operations and hosted startup must use the selected executable."""
def test_image_and_override_with_new_and_existing_admin(self): """The override must work even when the image has no usable bundled executable.""" source = (Path(__file__).resolve().parents[1] / "docker-compose/entrypoint.sh").read_text() for override in [False, True]: for existing in [False, True]: with self.subTest(override=override, existing=existing), tempfile.TemporaryDirectory() as tmp: root = Path(tmp) data = root / "data" data.mkdir() (data / "lichen.toml").touch() (data / "users").mkdir() if existing: (data / "users/admin.toml").touch() tools = root / "tools" tools.mkdir() log = root / "calls" mock = '#!/usr/bin/env python3\nimport json,os,sys\nwith open(os.environ["ENTRYPOINT_TEST_LOG"],"a") as f: f.write(json.dumps(sys.argv)+"\\n")\n' for name in ["rm", "apk", "git", "lichen"]: path = tools / name path.write_text(mock) path.chmod(0o755) custom = root / "override" custom.mkdir() if override: path = custom / "lichen" path.write_text(mock) path.chmod(0o755) (tools / "lichen").unlink() script = root / "entrypoint.sh" script.write_text(source.replace("/opt/lichen-bin", str(custom)).replace("/data", str(data))) env = dict(os.environ, PATH=str(tools) + os.pathsep + os.environ["PATH"], ENTRYPOINT_TEST_LOG=str(log), ADMIN_PASSWORD="fixture-password", ADMIN_USER="admin") subprocess.run(["sh", str(script)], env=env, check=True, capture_output=True) calls = [json.loads(line) for line in log.read_text().splitlines()] calls = [argv for argv in calls if Path(argv[0]).name == "lichen"] self.assertEqual(len(calls), 2) selected = custom / "lichen" if override else tools / "lichen" self.assertTrue(all(argv[0] == str(selected) for argv in calls)) self.assertEqual(calls[0][1:5], ["server", "--multi", "users", "set-password" if existing else "add"]) self.assertEqual(calls[1][1:], ["server", "--multi", "--root-dir", str(data), "run"])