14
14
15
15
import base64
16
16
import datetime
17
+ import io
17
18
import json
18
19
import os
19
20
import shutil
@@ -1247,7 +1248,7 @@ def test_ssl_with_relative_ssl_files(self):
1247
1248
finally :
1248
1249
shutil .rmtree (temp_dir )
1249
1250
1250
- def test_load_kube_config (self ):
1251
+ def test_load_kube_config_from_file_path (self ):
1251
1252
expected = FakeConfig (host = TEST_HOST ,
1252
1253
token = BEARER_TOKEN_FORMAT % TEST_DATA_BASE64 )
1253
1254
config_file = self ._create_temp_file (
@@ -1257,10 +1258,32 @@ def test_load_kube_config(self):
1257
1258
client_configuration = actual )
1258
1259
self .assertEqual (expected , actual )
1259
1260
1260
- def test_load_kube_config_from_dict (self ):
1261
+ def test_load_kube_config_from_file_like_object (self ):
1261
1262
expected = FakeConfig (host = TEST_HOST ,
1262
1263
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 )
1263
1283
1284
+ def test_load_kube_config_from_dict (self ):
1285
+ expected = FakeConfig (host = TEST_HOST ,
1286
+ token = BEARER_TOKEN_FORMAT % TEST_DATA_BASE64 )
1264
1287
actual = FakeConfig ()
1265
1288
load_kube_config_from_dict (config_dict = self .TEST_KUBE_CONFIG ,
1266
1289
context = "simple_token" ,
0 commit comments