feat: add interhub bootstrap helper

This commit is contained in:
2026-06-17 00:17:59 +02:00
parent 9fce939d29
commit 6aff34cc5b
11 changed files with 1197 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
from __future__ import annotations
import unittest
from ops_hub.interhub_gate_probe import (
REQUIRED_OPENAPI_PATHS,
api_url,
evaluate_openapi_paths,
normalize_base_url,
)
class InterHubGateProbeTests(unittest.TestCase):
def test_normalize_base_url(self) -> None:
self.assertEqual(normalize_base_url("https://hub.example"), "https://hub.example/")
self.assertEqual(normalize_base_url("https://hub.example/"), "https://hub.example/")
def test_api_url_joins_versioned_paths(self) -> None:
self.assertEqual(
api_url("https://hub.example", "/api/v2/hubs"),
"https://hub.example/api/v2/hubs",
)
def test_evaluate_openapi_paths_detects_all_required_paths(self) -> None:
openapi = {"paths": {path: {} for path in REQUIRED_OPENAPI_PATHS}}
present, missing = evaluate_openapi_paths(openapi)
self.assertEqual(present, list(REQUIRED_OPENAPI_PATHS))
self.assertEqual(missing, [])
def test_evaluate_openapi_paths_reports_missing_paths(self) -> None:
openapi = {"paths": {"/hubs": {}}}
present, missing = evaluate_openapi_paths(openapi)
self.assertEqual(present, ["/hubs"])
self.assertEqual(
missing,
["/hub-capability-manifests", "/api-consumers", "/policy-scopes"],
)
if __name__ == "__main__":
unittest.main()