Skip to content

Commit 171392e

Browse files
committed
test: add unit tests for status, details, and list CLI commands
1 parent d5fb325 commit 171392e

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

tests/unit_test.py

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,135 @@ def test_list_clusters_all_namespaces(mocker, capsys):
236236
)
237237

238238

239+
def test_raycluster_details_cli(mocker):
240+
runner = CliRunner()
241+
mocker.patch(
242+
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
243+
side_effect=get_ray_obj,
244+
)
245+
mocker.patch(
246+
"codeflare_sdk.cluster.cluster.get_current_namespace",
247+
return_value="ns",
248+
)
249+
mocker.patch(
250+
"codeflare_sdk.cluster.cluster.Cluster.status",
251+
return_value=(False, CodeFlareClusterStatus.UNKNOWN),
252+
)
253+
mocker.patch(
254+
"codeflare_sdk.cluster.cluster.Cluster.cluster_dashboard_uri",
255+
return_value="",
256+
)
257+
mocker.patch.object(client, "ApiClient")
258+
raycluster_details_command = """
259+
details raycluster quicktest
260+
"""
261+
result = runner.invoke(cli, raycluster_details_command)
262+
quicktest_details = (
263+
" ╭──────────────────────────────────────────────────────────────╮ \n"
264+
+ " │ Name │ \n"
265+
+ " │ quicktest Inactive ❌ │ \n"
266+
+ " │ │ \n"
267+
+ " │ URI: ray://quicktest-head-svc.ns.svc:10001 │ \n"
268+
+ " │ │ \n"
269+
+ " │ Dashboard🔗 │ \n"
270+
+ " │ │ \n"
271+
+ " │ Cluster Resources │ \n"
272+
+ " │ ╭─ Workers ──╮ ╭───────── Worker specs(each) ─────────╮ │ \n"
273+
+ " │ │ Min Max │ │ Memory CPU GPU │ │ \n"
274+
+ " │ │ │ │ │ │ \n"
275+
+ " │ │ 1 1 │ │ 2~2 1 0 │ │ \n"
276+
+ " │ │ │ │ │ │ \n"
277+
+ " │ ╰────────────╯ ╰──────────────────────────────────────╯ │ \n"
278+
+ " ╰──────────────────────────────────────────────────────────────╯ "
279+
)
280+
assert quicktest_details in result.output
281+
282+
283+
def test_raycluster_status_cli(mocker):
284+
runner = CliRunner()
285+
test_raycluster = RayCluster(
286+
"quicktest",
287+
RayClusterStatus.READY,
288+
1,
289+
1,
290+
"1",
291+
"1",
292+
1,
293+
1,
294+
"default",
295+
"dashboard-url",
296+
)
297+
mocker.patch(
298+
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
299+
side_effect=get_ray_obj,
300+
)
301+
mocker.patch(
302+
"codeflare_sdk.cluster.cluster.get_current_namespace",
303+
return_value="ns",
304+
)
305+
mocker.patch(
306+
"codeflare_sdk.cluster.cluster.Cluster.cluster_dashboard_uri",
307+
return_value="",
308+
)
309+
mocker.patch(
310+
"codeflare_sdk.cluster.cluster._app_wrapper_status",
311+
return_value=test_raycluster,
312+
)
313+
mocker.patch(
314+
"codeflare_sdk.cluster.cluster._ray_cluster_status",
315+
return_value=test_raycluster,
316+
)
317+
mocker.patch.object(client, "ApiClient")
318+
raycluster_status_command = """
319+
status raycluster quicktest
320+
"""
321+
result = runner.invoke(cli, raycluster_status_command)
322+
assert "Active" in result.output
323+
324+
325+
def test_raycluster_list_cli(mocker):
326+
runner = CliRunner()
327+
mocker.patch(
328+
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
329+
side_effect=get_ray_obj,
330+
)
331+
mocker.patch(
332+
"codeflare_sdk.cluster.cluster.get_current_namespace",
333+
return_value="ns",
334+
)
335+
mocker.patch(
336+
"codeflare_sdk.cluster.cluster.Cluster.status",
337+
return_value=(False, CodeFlareClusterStatus.UNKNOWN),
338+
)
339+
mocker.patch(
340+
"codeflare_sdk.cluster.cluster.Cluster.cluster_dashboard_uri",
341+
return_value="",
342+
)
343+
mocker.patch.object(client, "ApiClient")
344+
list_rayclusters_command = """
345+
list rayclusters --namespace=ns
346+
"""
347+
result = runner.invoke(cli, list_rayclusters_command)
348+
assert (
349+
" ╭──────────────────────────────────────────────────────────────╮ \n"
350+
+ " │ Name │ \n"
351+
+ " │ quicktest Active ✅ │ \n"
352+
+ " │ │ \n"
353+
+ " │ URI: ray://quicktest-head-svc.ns.svc:10001 │ \n"
354+
+ " │ │ \n"
355+
+ " │ Dashboard🔗 │ \n"
356+
+ " │ │ \n"
357+
+ " │ Cluster Resources │ \n"
358+
+ " │ ╭─ Workers ──╮ ╭───────── Worker specs(each) ─────────╮ │ \n"
359+
+ " │ │ Min Max │ │ Memory CPU GPU │ │ \n"
360+
+ " │ │ │ │ │ │ \n"
361+
+ " │ │ 1 1 │ │ 2G~2G 1 0 │ │ \n"
362+
+ " │ │ │ │ │ │ \n"
363+
+ " │ ╰────────────╯ ╰──────────────────────────────────────╯ │ \n"
364+
+ " ╰──────────────────────────────────────────────────────────────╯ "
365+
) in result.output
366+
367+
239368
# For mocking openshift client results
240369
fake_res = openshift.Result("fake")
241370

0 commit comments

Comments
 (0)