3737 TokenAuthentication ,
3838 Authentication ,
3939 KubeConfigFileAuthentication ,
40+ config_check ,
41+ api_config_handler ,
4042)
4143from codeflare_sdk .utils .pretty_print import (
4244 print_no_resources_found ,
@@ -150,6 +152,46 @@ def test_token_auth_login_tls(mocker):
150152 assert token_auth .login () == ("Logged into testserver:6443" )
151153
152154
155+ def test_config_check_no_config_file (mocker ):
156+ mocker .patch ("os.path.expanduser" , return_value = "/mock/home/directory" )
157+ mocker .patch ("os.path.isfile" , return_value = False )
158+ mocker .patch ("codeflare_sdk.cluster.auth.config_path" , None )
159+ mocker .patch ("codeflare_sdk.cluster.auth.api_client" , None )
160+
161+ with pytest .raises (PermissionError ) as e :
162+ config_check ()
163+
164+
165+ def test_config_check_with_incluster_config (mocker ):
166+ mocker .patch ("os.path.expanduser" , return_value = "/mock/home/directory" )
167+ mocker .patch ("os.path.isfile" , return_value = False )
168+ mocker .patch .dict (os .environ , {"KUBERNETES_PORT" : "number" })
169+ mocker .patch ("kubernetes.config.load_incluster_config" , side_effect = None )
170+ mocker .patch ("codeflare_sdk.cluster.auth.config_path" , None )
171+ mocker .patch ("codeflare_sdk.cluster.auth.api_client" , None )
172+
173+ result = config_check ()
174+ assert result == None
175+
176+
177+ def test_config_check_with_existing_config_file (mocker ):
178+ mocker .patch ("os.path.expanduser" , return_value = "/mock/home/directory" )
179+ mocker .patch ("os.path.isfile" , return_value = True )
180+ mocker .patch ("kubernetes.config.load_kube_config" , side_effect = None )
181+ mocker .patch ("codeflare_sdk.cluster.auth.config_path" , None )
182+ mocker .patch ("codeflare_sdk.cluster.auth.api_client" , None )
183+
184+ result = config_check ()
185+ assert result == None
186+
187+
188+ def test_config_check_with_config_path_and_no_api_client (mocker ):
189+ mocker .patch ("codeflare_sdk.cluster.auth.config_path" , "/mock/config/path" )
190+ mocker .patch ("codeflare_sdk.cluster.auth.api_client" , None )
191+ result = config_check ()
192+ assert result == "/mock/config/path"
193+
194+
153195def test_load_kube_config (mocker ):
154196 mocker .patch .object (config , "load_kube_config" )
155197 kube_config_auth = KubeConfigFileAuthentication (
@@ -162,6 +204,10 @@ def test_load_kube_config(mocker):
162204 == "Loaded user config file at path %s" % kube_config_auth .kube_config_path
163205 )
164206
207+ kube_config_auth = KubeConfigFileAuthentication (kube_config_path = None )
208+ response = kube_config_auth .load_kube_config ()
209+ assert response == "Please specify a config file path"
210+
165211
166212def test_auth_coverage ():
167213 abstract = Authentication ()
0 commit comments