subkanthi commented on a change in pull request #18563:
URL: https://github.com/apache/airflow/pull/18563#discussion_r718518978



##########
File path: tests/kubernetes/test_refresh_config.py
##########
@@ -35,3 +43,64 @@ def 
test_parse_timestamp_should_convert_regular_timezone_to_unix_timestamp(self)
     def test_parse_timestamp_should_throw_exception(self):
         with pytest.raises(ParserError):
             _parse_timestamp("foobar")
+
+    def test_get_kube_config_loader_for_yaml_file(self):
+        refresh_kube_config_loader = 
_get_kube_config_loader_for_yaml_file('./kube_config')
+
+        assert refresh_kube_config_loader is not None
+
+        assert refresh_kube_config_loader.current_context['name'] == 
'federal-context'
+
+        context = refresh_kube_config_loader.current_context['context']
+        assert context is not None
+        assert context['cluster'] == 'horse-cluster'
+        assert context['namespace'] == 'chisel-ns'
+        assert context['user'] == 'green-user'
+
+    def test_get_api_key_with_prefix(self):
+
+        refresh_config = RefreshConfiguration()
+        refresh_config.api_key['key'] = '1234'
+        assert refresh_config is not None
+
+        api_key = refresh_config.get_api_key_with_prefix("key")
+
+        assert api_key == '1234'
+
+    def test_refresh_kube_config_loader(self):
+
+        current_context = 
_get_kube_config_loader_for_yaml_file('./kube_config').current_context
+
+        config_dict = {}
+        config_dict['current-context'] = 'federal-context'
+        config_dict['contexts'] = []
+        config_dict['contexts'].append(current_context)
+
+        config_dict['clusters'] = []
+
+        cluster_config = {}
+        cluster_config['api-version'] = 'v1'
+        cluster_config['server'] = 'http://cow.org:8080'
+        cluster_config['name'] = 'horse-cluster'
+        cluster_root_config = {}
+        cluster_root_config['cluster'] = cluster_config
+        cluster_root_config['name'] = 'horse-cluster'
+        config_dict['clusters'].append(cluster_root_config)
+
+        refresh_kube_config_loader = 
RefreshKubeConfigLoader(config_dict=config_dict)
+        refresh_kube_config_loader._user = {}
+        refresh_kube_config_loader._user['exec'] = 'test'
+
+        config_node = ConfigNode('command', 'test')
+        config_node.__dict__['apiVersion'] = '2.0'
+        config_node.__dict__['command'] = 'test'
+
+        ExecProvider.__init__ = Mock()
+        ExecProvider.__init__.return_value = None
+
+        ExecProvider.run = Mock()
+        ExecProvider.run.return_value = {'token': '1234'}
+
+        result = refresh_kube_config_loader._load_from_exec_plugin()

Review comment:
       For some reason with this approach, the ExecProvider is not replaced 
with the Mock and its calling the __init__. Trying to figure it out.
   
   `    def __init__(self, exec_config):
   
           for key in ['command', 'apiVersion']:
               if key not in exec_config:
                   raise ConfigException(
                       'exec: malformed request. missing key \'%s\'' % key)
           self.api_version = exec_config['apiVersion']
           self.args = [exec_config['command']]
           if exec_config.safe_get('args'):
               self.args.extend(exec_config['args'])
           self.env = os.environ.copy()
           if exec_config.safe_get('env'):
               additional_vars = {}
               for item in exec_config['env']:
                   name = item['name']
                   value = item['value']
                   additional_vars[name] = value
               self.env.update(additional_vars)`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to