Skip to content

Commit ca65ddd

Browse files
Add unit tests for rc routes
1 parent 9e6088a commit ca65ddd

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tests/unit_test.py

+48
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from codeflare_sdk.cluster.cluster import (
3333
Cluster,
3434
ClusterConfiguration,
35+
_map_to_ray_cluster,
3536
list_all_clusters,
3637
list_all_queued,
3738
_copy_to_ray,
@@ -1901,6 +1902,53 @@ def route_retrieval(group, version, namespace, plural, name):
19011902
}
19021903

19031904

1905+
def test_map_to_ray_cluster(mocker):
1906+
mocker.patch("kubernetes.config.load_kube_config")
1907+
1908+
mocker.patch(
1909+
"codeflare_sdk.cluster.cluster.is_openshift_cluster", return_value=True
1910+
)
1911+
1912+
mock_api_client = mocker.MagicMock(spec=client.ApiClient)
1913+
mocker.patch(
1914+
"codeflare_sdk.cluster.auth.api_config_handler", return_value=mock_api_client
1915+
)
1916+
1917+
mock_routes = {
1918+
"items": [
1919+
{
1920+
"apiVersion": "route.openshift.io/v1",
1921+
"kind": "Route",
1922+
"metadata": {
1923+
"name": "ray-dashboard-quicktest",
1924+
"namespace": "ns",
1925+
},
1926+
"spec": {"host": "ray-dashboard-quicktest"},
1927+
},
1928+
]
1929+
}
1930+
1931+
def custom_side_effect(group, version, namespace, plural, **kwargs):
1932+
if plural == "routes":
1933+
return mock_routes
1934+
elif plural == "rayclusters":
1935+
return get_ray_obj("ray.io", "v1", "ns", "rayclusters")
1936+
1937+
mocker.patch(
1938+
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
1939+
side_effect=custom_side_effect,
1940+
)
1941+
1942+
rc = get_ray_obj("ray.io", "v1", "ns", "rayclusters")["items"][0]
1943+
rc_name = rc["metadata"]["name"]
1944+
rc_dashboard = f"http://ray-dashboard-{rc_name}"
1945+
1946+
result = _map_to_ray_cluster(rc)
1947+
1948+
assert result is not None
1949+
assert result.dashboard == rc_dashboard
1950+
1951+
19041952
def test_list_clusters(mocker, capsys):
19051953
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
19061954
mocker.patch("kubernetes.client.ApisApi.get_api_versions")

0 commit comments

Comments
 (0)