1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ import json
1516import os
1617import unittest
1718
@@ -31,6 +32,13 @@ def setUp(self):
3132 'apiVersion' : 'client.authentication.k8s.io/v1beta1' ,
3233 'env' : None
3334 })
35+ self .input_with_cluster = ConfigNode ('test' , {
36+ 'command' : 'aws-iam-authenticator' ,
37+ 'args' : ['token' , '-i' , 'dummy' ],
38+ 'apiVersion' : 'client.authentication.k8s.io/v1beta1' ,
39+ 'provideClusterInfo' : True ,
40+ 'env' : None
41+ })
3442 self .output_ok = """
3543 {
3644 "apiVersion": "client.authentication.k8s.io/v1beta1",
@@ -162,6 +170,19 @@ def test_ok_no_console_attached(self, mock):
162170 self .assertTrue (isinstance (result , dict ))
163171 self .assertTrue ('token' in result )
164172
173+ @mock .patch ('subprocess.Popen' )
174+ def test_with_cluster_info (self , mock ):
175+ instance = mock .return_value
176+ instance .wait .return_value = 0
177+ instance .communicate .return_value = (self .output_ok , '' )
178+ ep = ExecProvider (self .input_with_cluster , None , {'server' : 'name.company.com' })
179+ result = ep .run ()
180+ self .assertTrue (isinstance (result , dict ))
181+ self .assertTrue ('token' in result )
182+
183+ obj = json .loads (mock .call_args .kwargs ['env' ]['KUBERNETES_EXEC_INFO' ])
184+ self .assertEqual (obj ['spec' ]['cluster' ]['server' ], 'name.company.com' )
185+
165186
166187if __name__ == '__main__' :
167188 unittest .main ()
0 commit comments