Skip to content

Commit 5a2ad73

Browse files
add unit tests for generate_cert.py
1 parent 068d4e4 commit 5a2ad73

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/unit_test.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
DDPJob,
5555
torchx_runner,
5656
)
57+
from codeflare_sdk.utils.generate_cert import (
58+
generate_ca_cert,
59+
generate_tls_cert,
60+
export_env,
61+
)
62+
5763
import openshift
5864
from openshift import OpenShiftPythonException
5965
from openshift.selector import Selector
@@ -1980,6 +1986,35 @@ def test_AWManager_submit_remove(mocker, capsys):
19801986
assert testaw.submitted == False
19811987

19821988

1989+
def test_generate_ca_cert():
1990+
"""
1991+
test the function codeflare_sdk.utils.generate_ca_cert generates the correct outputs
1992+
"""
1993+
key, certificate = generate_ca_cert()
1994+
assert type(key) == str
1995+
assert type(certificate) == str
1996+
1997+
1998+
def test_generate_tls_cert(mocker):
1999+
"""
2000+
test the function codeflare_sdk.utils.generate_ca_cert generates the correct outputs
2001+
"""
2002+
ca_private_key_bytes, _ = generate_ca_cert()
2003+
2004+
mocker.patch("openshift.invoke", return_value=openshift.Result("fake"))
2005+
mocker.patch("openshift.Result.out", return_value=ca_private_key_bytes)
2006+
generate_tls_cert("cluster", "namespace")
2007+
assert os.path.exists("tls-cluster-namespace")
2008+
2009+
2010+
def test_export_env():
2011+
"""
2012+
test the function codeflare_sdk.utils.export_ev generates the correct outputs
2013+
"""
2014+
export_env("cluster_name", "namespace")
2015+
assert os.environ["RAY_USE_TLS"] == "1"
2016+
2017+
19832018
# Make sure to keep this function and the following function at the end of the file
19842019
def test_cmd_line_generation():
19852020
os.system(

0 commit comments

Comments
 (0)