39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
import importlib.util
|
|
from pathlib import Path
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
spec = importlib.util.spec_from_file_location("gateway_lab", ROOT / "scripts/gateway-lab.py")
|
|
lab = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(lab)
|
|
|
|
|
|
class GatewayLabTest(unittest.TestCase):
|
|
def test_empty_cluster_needs_all_standard_crds(self):
|
|
self.assertEqual(lab.crd_actions({}), lab.CRDS)
|
|
|
|
def test_resume_lab_owned_install(self):
|
|
name = next(iter(lab.CRDS))
|
|
self.assertNotIn(name, lab.crd_actions({name: {"metadata": {"labels": {lab.OWNER: lab.VERSION}}}}))
|
|
|
|
def test_unknown_existing_crd_is_not_replaced(self):
|
|
name = next(iter(lab.CRDS))
|
|
with self.assertRaisesRegex(RuntimeError, "unknown"):
|
|
lab.crd_actions({name: {"metadata": {}}})
|
|
|
|
def test_official_matching_crd_is_reused(self):
|
|
name = next(iter(lab.CRDS))
|
|
obj = {"metadata": {"annotations": {"gateway.networking.k8s.io/bundle-version": lab.VERSION}}}
|
|
self.assertNotIn(name, lab.crd_actions({name: obj}))
|
|
|
|
def test_missing_telemetry_stops_before_changes(self):
|
|
with mock.patch.object(lab, "get", return_value=None), mock.patch.object(lab, "kubectl") as command:
|
|
with self.assertRaisesRegex(RuntimeError, "OpenTelemetry"):
|
|
lab.install()
|
|
command.assert_not_called()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|