Skip to content

Commit bcfd864

Browse files
Test bridge configuration against schema
1 parent 7f9313c commit bcfd864

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎tests/test_bridge_config.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
"""Validate the versioned bridge configuration."""
3+
from __future__ import annotations
4+
5+
import json
6+
from pathlib import Path
7+
8+
from jsonschema import Draft202012Validator
9+
10+
ROOT = Path(__file__).resolve().parents[1]
11+
CONFIG = ROOT / "bridge_config.json"
12+
SCHEMA = ROOT / "config" / "bridge_config.schema.json"
13+
14+
15+
def main() -> int:
16+
config = json.loads(CONFIG.read_text(encoding="utf-8"))
17+
schema = json.loads(SCHEMA.read_text(encoding="utf-8"))
18+
errors = sorted(
19+
Draft202012Validator(schema).iter_errors(config),
20+
key=lambda error: list(error.absolute_path),
21+
)
22+
if errors:
23+
detail = "\n".join(error.message for error in errors)
24+
raise AssertionError(f"bridge configuration is invalid:\n{detail}")
25+
print("bridge configuration schema test passed")
26+
return 0
27+
28+
29+
if __name__ == "__main__":
30+
raise SystemExit(main())

0 commit comments

Comments
 (0)