reswqa commented on code in PR #22598:
URL: https://github.com/apache/flink/pull/22598#discussion_r1195476076


##########
flink-kubernetes/src/test/java/org/apache/flink/kubernetes/KubernetesExtension.java:
##########
@@ -22,40 +22,54 @@
 import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions;
 import org.apache.flink.kubernetes.kubeclient.FlinkKubeClient;
 import org.apache.flink.kubernetes.kubeclient.FlinkKubeClientFactory;
+import org.apache.flink.util.StringUtils;
 
+import org.assertj.core.api.Assertions;
 import org.junit.jupiter.api.extension.AfterAllCallback;
 import org.junit.jupiter.api.extension.BeforeAllCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
 import org.junit.rules.ExternalResource;
 
-import static org.assertj.core.api.Assumptions.assumeThat;
-
 /**
  * {@link ExternalResource} which has a configured real Kubernetes cluster and 
client. We assume
  * that one already has a running Kubernetes cluster. And all the ITCases 
assume that the
  * environment ITCASE_KUBECONFIG is set with a valid kube config file. In the 
E2E tests, we will use
  * a minikube for the testing.
+ *
+ * <p>If a test depends on this extension, please annotation it with {@code 
@EnabledIf(value =
+ * "org.apache.flink.kubernetes.KubernetesExtension#checkEnv", disabledReason 
= "Disabled as " +
+ * KubernetesExtension.KUBE_CONF_ENV + " is not set.")} to avoid failure in 
the environment without
+ * Kubernetes cluster.
  */
 public class KubernetesExtension implements BeforeAllCallback, 
AfterAllCallback {
 
     private static final String CLUSTER_ID = "flink-itcase-cluster";
+
+    public static final String KUBE_CONF_ENV = "ITCASE_KUBECONFIG";
     private static final int KUBERNETES_TRANSACTIONAL_OPERATION_MAX_RETRIES = 
100;
 
     private static String kubeConfigFile;
     private Configuration configuration;
     private FlinkKubeClient flinkKubeClient;
 
-    public static void checkEnv() {
-        final String kubeConfigEnv = System.getenv("ITCASE_KUBECONFIG");
-        assumeThat(kubeConfigEnv)
-                .withFailMessage("ITCASE_KUBECONFIG environment is not set.")
-                .isNotBlank();
-        kubeConfigFile = kubeConfigEnv;
+    public static boolean checkEnv() {
+        final String kubeConfigEnv = System.getenv(KUBE_CONF_ENV);
+        return !StringUtils.isNullOrWhitespaceOnly(kubeConfigEnv);
+    }
+
+    private void checkAndSetKubeConfigFile() {
+        Assertions.assertThat(checkEnv())
+                .withFailMessage(
+                        "This extension can be used only when"
+                                + KUBE_CONF_ENV
+                                + " environment is set.")
+                .isTrue();

Review Comment:
   I have tested that `AssertionError` can be reported correctly from 
`beforeAll`.



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