From 445385900d6080458c6bddc826db3143dc311642 Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Mon, 4 Jan 2021 16:42:04 -0800 Subject: [PATCH] Add resiliency to the test. --- .../client/e2e/basic/CoreV1ApiTest.groovy | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/e2e/src/test/groovy/io/kubernetes/client/e2e/basic/CoreV1ApiTest.groovy b/e2e/src/test/groovy/io/kubernetes/client/e2e/basic/CoreV1ApiTest.groovy index 22b5ccdf5b..16d6ab0ff0 100644 --- a/e2e/src/test/groovy/io/kubernetes/client/e2e/basic/CoreV1ApiTest.groovy +++ b/e2e/src/test/groovy/io/kubernetes/client/e2e/basic/CoreV1ApiTest.groovy @@ -13,7 +13,9 @@ limitations under the License. package io.kubernetes.client.e2e.basic +import com.google.gson.JsonSyntaxException import io.kubernetes.client.openapi.Configuration +import io.kubernetes.client.openapi.apis.ApiException import io.kubernetes.client.openapi.apis.CoreV1Api import io.kubernetes.client.openapi.models.V1Namespace import io.kubernetes.client.openapi.models.V1ObjectMeta @@ -22,6 +24,20 @@ import io.kubernetes.client.util.ClientBuilder import spock.lang.Specification class CoreV1ApiTest extends Specification { + public deleteNamespace(CoreV1Api api, String namespace) { + try { + CoreV1Api coreV1Api = new CoreV1Api(apiClient); + coreV1Api.deleteNamespace(namespace, null, null, null, null, null, null); + } catch (ApiException ex) { + if (ex.getCode() != HttpURLConnection.HTTP_NOT_FOUND) { + throw ex; + } + } catch (JsonSyntaxException ex) { + // Delete returned v1Status, try again. + deleteNamespace(api, namespace); + } + } + def "Create Namespace then Delete should work"() { given: def apiClient = ClientBuilder.defaultClient() @@ -33,9 +49,9 @@ class CoreV1ApiTest extends Specification { then: created != null when: - V1Status deleted = corev1api.deleteNamespace("e2e-basic", null, null, null, null, null, null) + boolean deleted = deleteNamespace(corev1api, "e2e-basic"); then: - deleted != null + deleted == true } }