
    L                         d dl Z d dlZd dlZddlmZ ddlmZmZmZm	Z	 dZ
dZdZdZd	Zd
ZdZeeeeiZeeeeiZ G d dej&                        Zedk(  r ej,                          yy)    N   )ConfigException)SERVICE_HOST_ENV_NAMESERVICE_PORT_ENV_NAMEInClusterConfigLoader_join_host_port
temp_token	temp_certz	127.0.0.180z127.0.0.1:80z::1z[::1]:80c                   p    e Zd Zd Zd ZddZddefdZd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zy)InClusterConfigTestc                     g | _         y N)_temp_filesselfs    :lib/third_party/kubernetes/config/incluster_config_test.pysetUpzInClusterConfigTest.setUp-   s
    D    c                 P    | j                   D ]  }t        j                  |        y r   )r   osremove)r   fs     r   tearDownzInClusterConfigTest.tearDown0   s    iil r   c                     t        j                         \  }}| j                  j                  |       t	        j
                  |t        j                  |             t	        j                  |       |S r   )	tempfilemkstempr   appendr   writestrencodeclose)r   contenthandlernames       r   _create_file_with_temp_contentz2InClusterConfigTest._create_file_with_temp_content4   sP    $$&MGTD!HHWcjj)*HHWKr   Nc                 z    |s| j                  t              }|s| j                  t              }t        |||      S )N)token_filenamecert_filenameenviron)r&   _TEST_TOKEN
_TEST_CERTr   )r   r(   r)   r*   s       r   get_test_loaderz#InClusterConfigTest.get_test_loader;   s@     ::;Gn99*Em %# r   c                     | j                  t        t        t        t                     | j                  t
        t        t        t                     y r   )assertEqual_TEST_HOST_PORTr   
_TEST_HOST
_TEST_PORT_TEST_IPV6_HOST_PORT_TEST_IPV6_HOSTr   s    r   test_join_host_portz'InClusterConfigTest.test_join_host_portH   s5    _oj*&MN)$_jACr   c                 0   | j                  t              }| j                  |      }|j                          | j	                  dt
        z   |j                         | j	                  ||j                         | j	                  t        |j                         y )Nr)   zhttps://)
r&   r,   r-   _load_configr/   r0   hostssl_ca_certr+   token)r   r)   loaders      r   test_load_configz$InClusterConfigTest.test_load_configM   st    77
CM!!!>F
Z/16;;?]F$6$67[&,,/r   c                 l    	 |j                          | j                  d|z         y # t        $ r Y y w xY w)NzShould fail because %s)load_and_setfailr   )r   config_loaderreasons      r   _should_fail_loadz%InClusterConfigTest._should_fail_loadU   s7      "
ii(612 
s   $' 	33c                 `    | j                  t        t        i      }| j                  |d       y )Nr*   zno port specified)r-   r   r1   rC   r   r<   s     r   test_no_portz InClusterConfigTest.test_no_port]   ,    !!+@**M!NF6#67r   c                 l    | j                  t        t        t        di      }| j	                  |d       y )N rE   zempty port specified)r-   r   r1   r   rC   rF   s     r   test_empty_portz#InClusterConfigTest.test_empty_porta   s7    !!zr+! F 	6#9:r   c                 `    | j                  t        t        i      }| j                  |d       y )NrE   zno host specified)r-   r   r2   rC   rF   s     r   test_no_hostz InClusterConfigTest.test_no_hosth   rH   r   c                 l    | j                  t        dt        t        i      }| j	                  |d       y )NrJ   rE   zempty host specified)r-   r   r   r2   rC   rF   s     r   test_empty_hostz#InClusterConfigTest.test_empty_hostl   s7    !!rz+! F 	6#9:r   c                 L    | j                  d      }| j                  |d       y )Nnot_exists_file_1123r7   zcert file does not existsr-   rC   rF   s     r   test_no_cert_filez%InClusterConfigTest.test_no_cert_files   s'    !!0F!GF6#>?r   c                 h    | j                  | j                               }| j                  |d       y )Nr7   zempty cert file providedr-   r&   rC   rF   s     r   test_empty_cert_filez(InClusterConfigTest.test_empty_cert_filew   s4    !!99; " =F6#=>r   c                 L    | j                  d      }| j                  |d       y )NrQ   r(   ztoken file does not existsrR   rF   s     r   test_no_token_filez&InClusterConfigTest.test_no_token_file|   s'    !!1G!HF6#?@r   c                 h    | j                  | j                               }| j                  |d       y )NrX   zempty token file providedrU   rF   s     r   test_empty_token_filez)InClusterConfigTest.test_empty_token_file   s4    !!::< " >F6#>?r   )rJ   )__name__
__module____qualname__r   r   r&   _TEST_ENVIRONr-   r5   r=   rC   rG   rK   rM   rO   rS   rV   rY   r[    r   r   r   r   +   s\     &*$(+C
08;8;@?
A@r   r   __main__)r   r   unittestconfig_exceptionr   incluster_configr   r   r   r   r+   r,   r1   r2   r0   r4   r3   r_   _TEST_IPV6_ENVIRONTestCaser   r\   mainr`   r   r   <module>rh      s   " 
   -G G 


 !  ::
 ?: X@(++ X@v z(--/ r   