42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
import importlib.util
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
_SCRIPT = Path(__file__).parents[1] / "scripts" / "preflight-deployment.py"
|
|
_SPEC = importlib.util.spec_from_file_location("deployment_preflight", _SCRIPT)
|
|
assert _SPEC is not None and _SPEC.loader is not None
|
|
preflight = importlib.util.module_from_spec(_SPEC)
|
|
sys.modules[_SPEC.name] = preflight
|
|
_SPEC.loader.exec_module(preflight)
|
|
|
|
|
|
class DeploymentPreflightTests(unittest.TestCase):
|
|
def test_maps_nested_container_path_to_host_source(self):
|
|
container = {
|
|
"Mounts": [
|
|
{"Type": "bind", "Source": "/srv/data", "Destination": "/data"},
|
|
{"Type": "bind", "Source": "/srv/sync", "Destination": "/data/Sync"},
|
|
]
|
|
}
|
|
mapping = preflight.map_path(container, "/data/Sync/routes/route-1")
|
|
self.assertEqual(mapping.source, Path("/srv/sync/routes/route-1"))
|
|
self.assertEqual(str(mapping.destination), "/data/Sync")
|
|
|
|
def test_rejects_api_and_client_roots_from_different_host_paths(self):
|
|
with self.assertRaisesRegex(preflight.CheckFailure, "host paths differ"):
|
|
preflight.require_same_path(
|
|
"Syncthing api_root/local_root",
|
|
preflight.Mapping(Path("/srv/syncthing-config/routes"), Path("/var/syncthing")),
|
|
preflight.Mapping(Path("/srv/sync/routes"), Path("/data/storage")),
|
|
)
|
|
|
|
def test_rejects_unmounted_container_path(self):
|
|
with self.assertRaisesRegex(preflight.CheckFailure, "not backed"):
|
|
preflight.map_path({"Mounts": []}, "/missing")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|