
    Ig)                         d dl Z d dlZd dlm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)mock   )ConfigException)ExecProvider)
ConfigNodec                   h   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 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    a/var/www/html/answerous/venv/lib/python3.12/site-packages/kubernetes/config/exec_provider_test.pysetUpzExecProviderTest.setUp   s*    "6.,@	,
     c                    t        di       t        dddi      t        dddi      g}|D ]U  }| j                  t              5 }t        |d        d d d        | j	                  dj
                  j                  d          W 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,>?A ( 	5K""?3 0w[$/0MM@!++0035	50 0s   BB	zsubprocess.Popenc                    |j                   }d|j                  _         d|j                  _         | j                  t              5 }t        | j                  d       }|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   r   instancer"   eps        r   test_error_code_returnedz)ExecProviderTest.test_error_code_returned6   s    $$%&",4)/ 	7dmmT2BFFH	 	1mm001292C2C2H2H2K	M	 	s   'B44B=c                 R   |j                   }d|j                  _         d|j                  _         | j                  t              5 }t        | j                  d       }|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_returnedA   s    $$%&",4)/ 	7dmmT2BFFH	 	='',,Q/	1	 	s   'BB&c                 l   |j                   }d|j                  _         g d}|D ]  }|df|j                  _         | j                  t              5 }t        | j                  d       }|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_keysL   s    $$%&"
,  	5F17H  -""?3 w!$--6 MMA!++0035	5 s   'B**B3	c                 j   |j                   }d|j                  _         d}d|z  }|df|j                  _         | j                  t              5 }t        | j                  d       }|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_versionn   s    $$%&"=    .4RL)/ 	7dmmT2BFFH	 	8""1%	'	 	s   'B))B2c                 (   |j                   }d|j                  _         | j                  df|j                  _         t	        | j
                  d       }|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   so    $$%&"-1^^R,@)$--.
64016)*r   c                    |j                   }d|j                  _         | j                  df|j                  _         t	        | j
                  d      }|j                          | j                  |j                  d   d   d       y )Nr   r   z/some/directoryr   cwd)	r'   r(   r   r)   r   r   r*   assertEqual	call_args)r   r   r,   r-   s       r   test_run_in_dirz ExecProviderTest.test_run_in_dir   si    $$%&"-1^^R,@)$--):;
*513DEr   c                    |j                   }d|j                  _         | j                  df|j                  _         t        j
                  j                  dd       }|5  t        | j                  d       }|j                         }| j                  t        |t                     | j                  d|v        d d d        y # 1 sw Y   y xY w)Nr   r   z
sys.stdout)newr   )r'   r(   r   r)   unittestr   patchr   r   r*   r9   r:   r;   )r   r   r,   mock_stdoutr-   r<   s         r   test_ok_no_console_attachedz,ExecProviderTest.test_ok_no_console_attached   s    $$%&"-1^^R,@)mm))d * $ 	/dmmT2BVVXFOOJvt45OOGv-.		/ 	/ 	/s   AC  C	N)__name__
__module____qualname__r   r#   r   rF   r.   r0   r4   r7   r=   rB   rH    r   r   r	   r	      s    "5 TZZ"#M $M TZZ"#1 $1 TZZ"#5 $5B TZZ"#' $', TZZ"#+ $+ TZZ"#F $F TZZ"#
/ $
/r   r	   __main__)osrE   r   config_exceptionr   exec_providerr   kube_configr   TestCaser	   rI   mainrL   r   r   <module>rT      sH    
   - ' #J/x(( J/Z zHMMO r   