|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import json |
| 4 | +from pathlib import Path |
| 5 | + |
| 6 | +from sourceos_syncd.reports import validate_repair_plan, validate_report |
| 7 | + |
| 8 | +SERVICE_EXAMPLES = Path("examples/service") |
| 9 | + |
| 10 | + |
| 11 | +def load_json(name: str) -> dict: |
| 12 | + return json.loads((SERVICE_EXAMPLES / name).read_text(encoding="utf-8")) |
| 13 | + |
| 14 | + |
| 15 | +def test_service_state_example_validates_as_state_integrity_report() -> None: |
| 16 | + report = load_json("statez.minimal.json") |
| 17 | + |
| 18 | + assert validate_report(report) == [] |
| 19 | + |
| 20 | + |
| 21 | +def test_service_repair_preview_example_validates_as_repair_plan() -> None: |
| 22 | + plan = load_json("repairz.preview.json") |
| 23 | + |
| 24 | + assert validate_repair_plan(plan) == [] |
| 25 | + assert plan["status"] == "preview" |
| 26 | + assert plan["service"]["preview_only"] is True |
| 27 | + assert plan["policy"]["destructive_actions_present"] is False |
| 28 | + |
| 29 | + |
| 30 | +def test_service_json_examples_have_expected_shapes() -> None: |
| 31 | + assert load_json("healthz.json")["live"] is True |
| 32 | + assert load_json("readyz.healthy.json")["ready"] is True |
| 33 | + assert load_json("readyz.uninitialized.json")["ready"] is False |
| 34 | + assert load_json("events.json")["events"][0]["event_id"] == "evt-00000001" |
| 35 | + assert load_json("event.evt-00000001.json")["event_id"] == "evt-00000001" |
| 36 | + assert load_json("event-explain.evt-00000001.json")["event_id"] == "evt-00000001" |
| 37 | + |
| 38 | + |
| 39 | +def test_service_metrics_example_names_core_series() -> None: |
| 40 | + metrics = (SERVICE_EXAMPLES / "metrics.txt").read_text(encoding="utf-8") |
| 41 | + |
| 42 | + assert "sourceos_syncd_ready" in metrics |
| 43 | + assert "sourceos_syncd_initialized" in metrics |
| 44 | + assert "sourceos_syncd_replay_lag_events" in metrics |
| 45 | + assert "sourceos_syncd_corrupted_objects" in metrics |
| 46 | + assert "sourceos_syncd_ready_http_code" in metrics |
0 commit comments