78 lines
2.8 KiB
Python
78 lines
2.8 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
BUILDER_ROOT = Path(__file__).resolve().parents[1]
|
|
TOOLS_ROOT = BUILDER_ROOT / "tools"
|
|
sys.path.insert(0, str(TOOLS_ROOT))
|
|
|
|
from _common import ( # noqa: E402
|
|
CORE_DYLIB,
|
|
GROUP_DYLIBS,
|
|
ORIGINAL_DEPLOYMENT_SEED,
|
|
ORIGINAL_REPORTING_SEED,
|
|
)
|
|
from _path_patch import OLD_DAILY_PATH, PATH_TEMPLATE, patch_initial_daily_path # noqa: E402
|
|
|
|
|
|
TEST_CHANNEL = "0123456789abcdef0123456789abcdef"
|
|
|
|
|
|
class InitialDailyPathPatchTests(unittest.TestCase):
|
|
def test_path_template_matches_online_sync(self) -> None:
|
|
self.assertEqual(PATH_TEMPLATE, "/sync/daily.html")
|
|
self.assertEqual(PATH_TEMPLATE.encode("ascii"), OLD_DAILY_PATH)
|
|
|
|
def test_group_dylibs_noop_when_path_unchanged(self) -> None:
|
|
for group, path in GROUP_DYLIBS.items():
|
|
with self.subTest(group=group):
|
|
source = path.read_bytes()
|
|
patched, metadata = patch_initial_daily_path(
|
|
source, TEST_CHANNEL, label=path.name
|
|
)
|
|
self.assertEqual(patched, source)
|
|
self.assertEqual(metadata["strategy"], "noop_online_path")
|
|
self.assertEqual(metadata["path"], "/sync/daily.html")
|
|
|
|
def test_fat_core_noop_when_path_unchanged(self) -> None:
|
|
source = CORE_DYLIB.read_bytes()
|
|
self.assertEqual(source[:4], bytes.fromhex("cafebabe"))
|
|
patched, metadata = patch_initial_daily_path(
|
|
source, TEST_CHANNEL, label=CORE_DYLIB.name
|
|
)
|
|
self.assertEqual(patched, source)
|
|
self.assertEqual(metadata["strategy"], "noop_online_path")
|
|
self.assertEqual(metadata["path"], "/sync/daily.html")
|
|
|
|
def test_secondary_pack_manifest_records_online_path(self) -> None:
|
|
with tempfile.TemporaryDirectory() as temp:
|
|
command = [
|
|
sys.executable,
|
|
str(TOOLS_ROOT / "patch_secondary_packs.py"),
|
|
"--deployment-seed",
|
|
ORIGINAL_DEPLOYMENT_SEED,
|
|
"--reporting-seed",
|
|
ORIGINAL_REPORTING_SEED,
|
|
"--channel-id",
|
|
TEST_CHANNEL,
|
|
"--out",
|
|
temp,
|
|
]
|
|
subprocess.run(command, check=True, capture_output=True, text=True, cwd=str(BUILDER_ROOT))
|
|
manifest = json.loads((Path(temp) / "MANIFEST.json").read_text())
|
|
path_patch = manifest["initial_daily_path_patch"]
|
|
self.assertEqual(path_patch["path"], "/sync/daily.html")
|
|
self.assertEqual(
|
|
{group: item["strategy"] for group, item in path_patch["groups"].items()},
|
|
{"A": "noop_online_path", "B": "noop_online_path"},
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|