3 L(Yt@sddlZddlZddlZddlmZddlmZmZmZm Z dZ dZ dZ dZ d Zd Zd Zee ee iZeeee iZGd d d ejZedkrejdS)N)ConfigException)SERVICE_HOST_ENV_NAMESERVICE_PORT_ENV_NAMEInClusterConfigLoader_join_host_portZ temp_tokenZ temp_certz 127.0.0.180z 127.0.0.1:80z::1z[::1]:80c@seZdZddZddZd!ddZddefd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd ZdS)"InClusterConfigTestcCs g|_dS)N) _temp_files)selfr U/private/tmp/pip-build-nl73fm5q/kubernetes/kubernetes/config/incluster_config_test.pysetUp'szInClusterConfigTest.setUpcCsx|jD]}tj|qWdS)N)r osremove)r fr r r tearDown*s zInClusterConfigTest.tearDowncCs8tj\}}|jj|tj|tj|tj||S)N) tempfilemkstempr appendrwritestrencodeclose)r contenthandlernamer r r _create_file_with_temp_content.s    z2InClusterConfigTest._create_file_with_temp_contentNcCs*|s|jt}|s|jt}t|||dS)N)token_filename cert_filenameenviron)r _TEST_TOKEN _TEST_CERTr)r rr r!r r r get_test_loader5s  z#InClusterConfigTest.get_test_loadercCs(|jtttt|jttttdS)N) assertEqual_TEST_HOST_PORTr _TEST_HOST _TEST_PORT_TEST_IPV6_HOST_PORT_TEST_IPV6_HOST)r r r r test_join_host_portCs z'InClusterConfigTest.test_join_host_portcCsP|jt}|j|d}|j|jdt|j|j||j|jt|j dS)N)r zhttps://) rr#r$Z _load_configr%r&hostZ ssl_ca_certr"token)r r loaderr r r test_load_configIs   z$InClusterConfigTest.test_load_configc Cs4y|j|jd|Wntk r.YnXdS)NzShould fail because %s)Z load_and_setZfailr)r Z config_loaderreasonr r r _should_fail_loadQs z%InClusterConfigTest._should_fail_loadcCs |jttid}|j|ddS)N)r!zno port specified)r$rr'r1)r r.r r r test_no_portYs z InClusterConfigTest.test_no_portcCs$|jtttdid}|j|ddS)Nr)r!zempty port specified)r$rr'rr1)r r.r r r test_empty_port^s z#InClusterConfigTest.test_empty_portcCs |jttid}|j|ddS)N)r!zno host specified)r$rr(r1)r r.r r r test_no_hostds z InClusterConfigTest.test_no_hostcCs$|jtdttid}|j|ddS)Nr)r!zempty host specified)r$rrr(r1)r r.r r r test_empty_hostis z#InClusterConfigTest.test_empty_hostcCs|jdd}|j|ddS)Nnot_exists_file_1123)r zcert file does not exists)r$r1)r r.r r r test_no_cert_fileos z%InClusterConfigTest.test_no_cert_filecCs |j|jd}|j|ddS)N)r zempty cert file provided)r$rr1)r r.r r r test_empty_cert_filess z(InClusterConfigTest.test_empty_cert_filecCs|jdd}|j|ddS)Nr6)rztoken file does not exists)r$r1)r r.r r r test_no_token_filexs z&InClusterConfigTest.test_no_token_filecCs |j|jd}|j|ddS)N)rzempty token file provided)r$rr1)r r.r r r test_empty_token_file|s z)InClusterConfigTest.test_empty_token_file)r)__name__ __module__ __qualname__rrr _TEST_ENVIRONr$r+r/r1r2r3r4r5r7r8r9r:r r r r r %s"  r __main__)rrZunittestZconfig_exceptionrZincluster_configrrrrr"r#r'r(r&r*r)r>Z_TEST_IPV6_ENVIRONZTestCaser r;mainr r r r s$ ]