
    X                         d dl Z d dlZd dlZddlmZ ddlmZ ddlmZ  G d dej                        Z
edk(  r ej                          yy)	    N   )ConfigException)ExecProvider)
ConfigNodec                      e Zd Zd Zd Z ej                  d      d        Z ej                  d      d        Z ej                  d      d        Z	 ej                  d      d        Z
 ej                  d      d        Zy	)
ExecProviderTestc                 B    t        ddg ddd d      | _        d| _        y )Ntestzaws-iam-authenticator)tokenz-idummyz$client.authentication.k8s.io/v1beta1)commandargs
apiVersionenvz
        {
            "apiVersion": "client.authentication.k8s.io/v1beta1",
            "kind": "ExecCredential",
            "status": {
                "token": "dummy"
            }
        }
        )r   input_ok	output_ok)selfs    7lib/third_party/kubernetes/config/exec_provider_test.pysetUpzExecProviderTest.setUp   s+    .,@	
DMDN    c                    t        di       t        dddi      t        dddi      g}|D ]T  }| j                  t              5 }t        |       d d d        | j	                  dj
                  j                  d          V y # 1 sw Y   5xY w)	Ntest1test2r    test3r   z$exec: malformed request. missing keyr   )r   assertRaisesr   r   assertIn	exceptionr   )r   exec_configsexec_configcontexts       r   test_missing_input_keysz(ExecProviderTest.test_missing_input_keys/   s    7B7YO,7\2./L
 $_-[! .
mm:%%**1-/ $--s   BB	zsubprocess.Popenc                 ~   |j                   }d|j                  _         d|j                  _         | j                  t              5 }t        | j                        }|j                          d d d        | j                  d|j                  j                   z  j                  j                  d          y # 1 sw Y   JxY w)Nr   r   r   zexec: process returned %dr   return_valuewaitcommunicater   r   r   r   runr   r   r   r   mockinstancer!   eps        r   test_error_code_returnedz)ExecProviderTest.test_error_code_returned;   s      H!"HMM(0H%			?	+w&bffh 
, 	MM-0J0JJ##((+- 
,	+s   &B33B<c                 P   |j                   }d|j                  _         d|j                  _         | j                  t              5 }t        | j                        }|j                          d d d        | j                  dj                  j                  d          y # 1 sw Y   3xY w)Nr   r$   z%exec: failed to decode process outputr%   r*   s        r   test_nonjson_output_returnedz-ExecProviderTest.test_nonjson_output_returnedF   s      H!"HMM(0H%			?	+w&bffh 
, 	MM9##((+- 
,	+s   &BB%c                 j   |j                   }d|j                  _         g d}|D ]  }|df|j                  _         | j                  t              5 }t        | j                        }|j                          d d d        | j                  dj                  j                  d           y # 1 sw Y   5xY w)Nr   )z
            {
                "kind": "ExecCredential",
                "status": {
                    "token": "dummy"
                }
            }
            z
            {
                "apiVersion": "client.authentication.k8s.io/v1beta1",
                "status": {
                    "token": "dummy"
                }
            }
            z
            {
                "apiVersion": "client.authentication.k8s.io/v1beta1",
                "kind": "ExecCredential"
            }
            r   z%exec: malformed response. missing keyr%   )r   r+   r,   outputsoutputr!   r-   s          r   test_missing_output_keysz)ExecProviderTest.test_missing_output_keysQ   s      H!"HMMG, +12,h'_-$--(
 . mm;%%**1-/ --s   &B))B2	c                 h   |j                   }d|j                  _         d}d|z  }|df|j                  _         | j                  t              5 }t        | j                        }|j                          d d d        | j                  d|z  j                  j                  d          y # 1 sw Y   6xY w)Nr   zclient.authentication.k8s.io/v1z
        {
            "apiVersion": "%s",
            "kind": "ExecCredential",
            "status": {
                "token": "dummy"
            }
        }
        r   z*exec: plugin api version %s does not matchr%   )r   r+   r,   wrong_api_versionr3   r!   r-   s          r   test_mismatched_api_versionz,ExecProviderTest.test_mismatched_api_versions   s      H!"HMM9   F *0H%			?	+w&bffh 
, 	MM47HHq!# 
,	+s   &B((B1c                 &   |j                   }d|j                  _         | j                  df|j                  _         t	        | j
                        }|j                         }| j                  t        |t                     | j                  d|v        y )Nr   r   r   )
r&   r'   r   r(   r   r   r)   
assertTrue
isinstancedict)r   r+   r,   r-   results        r   
test_ok_01zExecProviderTest.test_ok_01   sm      H!"HMM)-(<H%	dmm	$BVVXFOOJvt,-OOGv%&r   N)__name__
__module____qualname__r   r"   r+   patchr.   r0   r4   r7   r=    r   r   r   r      s    $
/ 4:: !- "- 4:: !- "- 4:: !/ "/B 4:: !# "#* 4:: !' "'r   r   __main__)osunittestr+   config_exceptionr   exec_providerr   kube_configr   TestCaser   r>   mainrB   r   r   <module>rK      sH   " 
   - ' #v'x(( v'r z(--/ r   