reef-railiance/tests/test_binding_projection.py
2026-08-21 02:01:49 +02:00

65 lines
2 KiB
Python

import importlib.util
from pathlib import Path
import yaml
MODULE = Path(__file__).parents[1] / "tools/check_binding_projection.py"
SPEC = importlib.util.spec_from_file_location("binding_projection", MODULE)
binding_projection = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(binding_projection)
def write_yaml(path: Path, value: dict) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(yaml.safe_dump(value, sort_keys=False), encoding="utf-8")
def test_matching_projection_passes(tmp_path):
repo = tmp_path / "reef-example"
write_yaml(
repo / "declarations/reef.yaml",
{"reef_id": "reef-example", "hosted_rails": ["rail-kubernetes"]},
)
write_yaml(
repo / "bindings/rails.yaml",
{"hosted_rails": [{"rail_id": "rail-kubernetes"}]},
)
write_yaml(
repo / "bindings/rapps.yaml",
{"bound_rapps": [{"rapp_id": "rapp-example"}]},
)
write_yaml(
tmp_path / "rail-kubernetes/declarations/rail.yaml",
{"rail_id": "rail-kubernetes"},
)
write_yaml(
tmp_path / "rapp-example/declarations/rapp.yaml",
{"rapp_id": "rapp-example", "bound_reefs": ["reef-example"]},
)
assert binding_projection.assess(repo, tmp_path) == []
def test_stale_rapp_projection_fails(tmp_path):
repo = tmp_path / "reef-example"
write_yaml(
repo / "declarations/reef.yaml",
{"reef_id": "reef-example", "hosted_rails": ["rail-kubernetes"]},
)
write_yaml(
repo / "bindings/rails.yaml",
{"hosted_rails": [{"rail_id": "rail-kubernetes"}]},
)
write_yaml(repo / "bindings/rapps.yaml", {"bound_rapps": []})
write_yaml(
tmp_path / "rail-kubernetes/declarations/rail.yaml",
{"rail_id": "rail-kubernetes"},
)
write_yaml(
tmp_path / "rapp-example/declarations/rapp.yaml",
{"rapp_id": "rapp-example", "bound_reefs": ["reef-example"]},
)
failures = binding_projection.assess(repo, tmp_path)
assert failures and "rapp projection differs" in failures[0]