Files
ops-hub/tests/test_interhub_gate_probe.py

42 lines
1.4 KiB
Python

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()