romsharon98 commented on code in PR #39249:
URL: https://github.com/apache/airflow/pull/39249#discussion_r1580705916


##########
tests/providers/cncf/kubernetes/hooks/test_kubernetes.py:
##########
@@ -279,6 +279,55 @@ def test_kube_config_path(
         mock_kube_config_loader.assert_called_once()
         assert isinstance(api_conn, kubernetes.client.api_client.ApiClient)
 
+    @pytest.mark.parametrize(
+        "conn_id, kube_config, has_conn_id, has_kube_config",
+        (
+            (None, None, False, False),
+            (None, "content of kubeconfig file", False, True),
+            ("kube_config", None, True, False),
+            ("kube_config", "content of kubeconfig file", True, True),
+        ),
+    )
+    @patch("kubernetes.config.kube_config.KubeConfigLoader")
+    @patch("kubernetes.config.kube_config.KubeConfigMerger")
+    @patch.object(tempfile, "NamedTemporaryFile")
+    def test_kube_config(
+        self,
+        mock_tempfile,
+        mock_kube_config_merger,
+        mock_kube_config_loader,
+        conn_id,
+        kube_config,
+        has_conn_id,
+        has_kube_config,
+    ):
+        """
+        Verifies whether temporary kube config file is created.
+        """
+        mock_tempfile.return_value.__enter__.return_value.name = 
"fake-temp-file"
+        mock_kube_config_merger.return_value.config = {"fake_config": "value"}
+        kubernetes_hook = KubernetesHook(conn_id=conn_id, 
kube_config=kube_config)
+        api_conn = kubernetes_hook.get_conn()
+        if has_conn_id:
+            if has_kube_config:
+                mock_tempfile.is_called_once()
+                mock_kube_config_loader.assert_called_once()
+                
mock_kube_config_merger.assert_called_once_with("fake-temp-file")
+            else:
+                mock_tempfile.is_called_once()

Review Comment:
   If there is no kubeconfig this function should be called?
   The code under if and else blocks is the same..



-- 
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