From feb800d054464f90fe735831189490aa2e6f0900 Mon Sep 17 00:00:00 2001 From: Diego Molina Date: Sun, 4 Mar 2018 09:58:02 -0800 Subject: [PATCH] Handling possible null (#462) * Debugging null in unit test * Improving mock to avoid flaky test, attempt 1 * Improving mock to avoid flaky test, attempt 2 --- .../container/kubernetes/KubernetesContainerClient.java | 2 +- .../de/zalando/ep/zalenium/util/KubernetesContainerMock.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/zalando/ep/zalenium/container/kubernetes/KubernetesContainerClient.java b/src/main/java/de/zalando/ep/zalenium/container/kubernetes/KubernetesContainerClient.java index 24640651db..2fef1cf5ec 100755 --- a/src/main/java/de/zalando/ep/zalenium/container/kubernetes/KubernetesContainerClient.java +++ b/src/main/java/de/zalando/ep/zalenium/container/kubernetes/KubernetesContainerClient.java @@ -323,7 +323,7 @@ public ContainerCreationStatus createContainer(String zaleniumContainerName, Str // Create the container Pod createdPod = doneablePod.done(); - String containerName = createdPod.getMetadata().getName(); + String containerName = createdPod.getMetadata() == null ? containerIdPrefix : createdPod.getMetadata().getName(); return new ContainerCreationStatus(true, containerName, nodePort); } diff --git a/src/test/java/de/zalando/ep/zalenium/util/KubernetesContainerMock.java b/src/test/java/de/zalando/ep/zalenium/util/KubernetesContainerMock.java index daaf592aa3..902fb7021e 100644 --- a/src/test/java/de/zalando/ep/zalenium/util/KubernetesContainerMock.java +++ b/src/test/java/de/zalando/ep/zalenium/util/KubernetesContainerMock.java @@ -61,7 +61,9 @@ public static KubernetesContainerClient getMockedKubernetesContainerClient() { Pod zaleniumPod = new PodBuilder() .withNewMetadata() .withLabels(zaleniumPodLabels) + .addToLabels(zaleniumPodLabels) .withNamespace("test") + .withGenerateName(hostName) .withName(hostName) .and().build();