From 8448aa60c1f5da64be1a6a8bf873708f441589f3 Mon Sep 17 00:00:00 2001 From: erabii Date: Mon, 1 Nov 2021 11:14:33 -0400 Subject: [PATCH] split core test (#897) * split test * trigger build --- .../kubernetes/fabric8/config/CoreTest.java | 16 +----- .../CoreTestClientViaSystemProperties.java | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/CoreTestClientViaSystemProperties.java diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/CoreTest.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/CoreTest.java index 4100bedd..12dc99ec 100644 --- a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/CoreTest.java +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/CoreTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import java.util.HashMap; import java.util.Map; import io.fabric8.kubernetes.client.Config; -import io.fabric8.kubernetes.client.DefaultKubernetesClient; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import org.junit.jupiter.api.BeforeAll; @@ -50,13 +49,6 @@ public class CoreTest { @Autowired private Config config; - // not a fan of changing the type from KubernetesClient, but because of: - // https://github.com/fabric8io/kubernetes-client/issues/3145 - // there is no way to do it otherwise at this time. When that is fixed, I will fix - // this also - @Autowired - private DefaultKubernetesClient client; - @BeforeAll public static void setUpBeforeClass() { @@ -87,12 +79,6 @@ public class CoreTest { assertThat(config.isTrustCerts()).isTrue(); } - @Test - public void kubernetesClientBeanShouldBeConfigurableViaSystemProperties() { - assertThat(client).isNotNull(); - assertThat(client.getConfiguration().getMasterUrl()).isEqualTo(mockClient.getConfiguration().getMasterUrl()); - } - @Test public void propertiesShouldBeReadFromConfigMap() { assertThat(environment.getProperty("spring.kubernetes.test.value")).isEqualTo("value1"); diff --git a/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/CoreTestClientViaSystemProperties.java b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/CoreTestClientViaSystemProperties.java new file mode 100644 index 00000000..93ad572d --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/CoreTestClientViaSystemProperties.java @@ -0,0 +1,52 @@ +/* + * Copyright 2013-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.kubernetes.fabric8.config; + +import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.KubernetesClient; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(SpringExtension.class) +@SpringBootTest(classes = TestApplication.class, + properties = { "spring.application.name=testapp", "spring.cloud.kubernetes.client.namespace=testns", + "spring.cloud.kubernetes.client.trustCerts=true", "spring.cloud.kubernetes.config.namespace=testns", + "spring.cloud.kubernetes.secrets.enableApi=true" }) +public class CoreTestClientViaSystemProperties { + + @Autowired + private KubernetesClient client; + + @BeforeAll + public static void setUpBeforeClass() { + System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, "masterURL"); + } + + @Test + public void kubernetesClientBeanShouldBeConfigurableViaSystemProperties() { + assertThat(client).isNotNull(); + assertThat(client.getConfiguration().getMasterUrl()).isEqualTo("http://masterURL/"); + } + +}