1414
1515import base64
1616import datetime
17+ import io
1718import json
1819import os
1920import shutil
@@ -1247,7 +1248,7 @@ def test_ssl_with_relative_ssl_files(self):
12471248 finally :
12481249 shutil .rmtree (temp_dir )
12491250
1250- def test_load_kube_config (self ):
1251+ def test_load_kube_config_from_file_path (self ):
12511252 expected = FakeConfig (host = TEST_HOST ,
12521253 token = BEARER_TOKEN_FORMAT % TEST_DATA_BASE64 )
12531254 config_file = self ._create_temp_file (
@@ -1257,10 +1258,32 @@ def test_load_kube_config(self):
12571258 client_configuration = actual )
12581259 self .assertEqual (expected , actual )
12591260
1260- def test_load_kube_config_from_dict (self ):
1261+ def test_load_kube_config_from_file_like_object (self ):
12611262 expected = FakeConfig (host = TEST_HOST ,
12621263 token = BEARER_TOKEN_FORMAT % TEST_DATA_BASE64 )
1264+ config_file_like_object = io .StringIO ()
1265+ # py3 (won't have unicode) vs py2 (requires it)
1266+ try :
1267+ unicode ('' )
1268+ config_file_like_object .write (
1269+ unicode (
1270+ yaml .safe_dump (
1271+ self .TEST_KUBE_CONFIG ),
1272+ errors = 'replace' ))
1273+ except NameError :
1274+ config_file_like_object .write (
1275+ yaml .safe_dump (
1276+ self .TEST_KUBE_CONFIG ))
1277+ actual = FakeConfig ()
1278+ load_kube_config (
1279+ config_file = config_file_like_object ,
1280+ context = "simple_token" ,
1281+ client_configuration = actual )
1282+ self .assertEqual (expected , actual )
12631283
1284+ def test_load_kube_config_from_dict (self ):
1285+ expected = FakeConfig (host = TEST_HOST ,
1286+ token = BEARER_TOKEN_FORMAT % TEST_DATA_BASE64 )
12641287 actual = FakeConfig ()
12651288 load_kube_config_from_dict (config_dict = self .TEST_KUBE_CONFIG ,
12661289 context = "simple_token" ,
0 commit comments