Fix 1338 main (#1344)

This commit is contained in:
erabii
2023-05-12 15:55:12 +03:00
committed by GitHub
parent 66c1446f0f
commit bf38b57a9c
16 changed files with 378 additions and 130 deletions

View File

@@ -1,80 +0,0 @@
/*
* Copyright 2013-2023 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.client.config;
import com.github.tomakehurst.wiremock.client.WireMock;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
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.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.kubernetes.client.config.applications.sources_order.SourcesOrderApp;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* The stub data for this test is in :
* {@link org.springframework.cloud.kubernetes.client.config.boostrap.stubs.SourcesOrderConfigurationStub}
*
* @author wind57
*/
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SourcesOrderApp.class,
properties = { "spring.cloud.bootstrap.name=retryable-sources-order", "sources.order.stub=true",
"spring.main.cloud-platform=KUBERNETES", "spring.cloud.bootstrap.enabled=true"})
@AutoConfigureWebTestClient
class RetryableKubernetesClientSourcesOrderTests {
@Autowired
private WebTestClient webClient;
@AfterEach
void afterEach() {
WireMock.reset();
}
@AfterAll
static void afterAll() {
WireMock.shutdownServer();
}
/**
* <pre>
* 1. There is one secret deployed: my-secret. It has two properties: {my.one=one, my.key=from-secret}
* 2. There is one configmap deployed: my-configmap. It has two properties: {my.two=two, my.key=from-configmap}
*
* We invoke three endpoints: /one, /two, /key.
* The first two prove that both the secret and configmap have been read, the last one proves that
* config maps have a higher precedence.
* </pre>
*/
@Test
void test() {
this.webClient.get().uri("/one").exchange().expectStatus().isOk().expectBody(String.class)
.value(Matchers.equalTo("one"));
this.webClient.get().uri("/two").exchange().expectStatus().isOk().expectBody(String.class)
.value(Matchers.equalTo("two"));
this.webClient.get().uri("/key").exchange().expectStatus().isOk().expectBody(String.class)
.value(Matchers.equalTo("from-configmap"));
}
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2013-2023 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.client.config.applications.sources_order;
import org.springframework.boot.test.context.SpringBootTest;
/**
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SourcesOrderApp.class,
properties = { "spring.cloud.bootstrap.name=retryable-sources-order", "sources.order.stub=true",
"spring.main.cloud-platform=KUBERNETES", "spring.cloud.bootstrap.enabled=true" })
class BootstrapRetryableSourcesOrderTests extends SourcesOrderTests {
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2013-2023 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.client.config.applications.sources_order;
import org.springframework.boot.test.context.SpringBootTest;
/**
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SourcesOrderApp.class,
properties = { "spring.cloud.bootstrap.name=sources-order", "sources.order.stub=true",
"spring.main.cloud-platform=KUBERNETES", "spring.cloud.bootstrap.enabled=true" })
class BootstrapSourcesOrderTests extends SourcesOrderTests {
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright 2013-2023 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.client.config.applications.sources_order;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import io.kubernetes.client.util.ClientBuilder;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.kubernetes.client.KubernetesClientUtils;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.mockito.Mockito.mockStatic;
import static org.springframework.cloud.kubernetes.client.config.boostrap.stubs.SourcesOrderConfigurationStub.stubConfigMapData;
import static org.springframework.cloud.kubernetes.client.config.boostrap.stubs.SourcesOrderConfigurationStub.stubSecretsData;
/**
* The stub data for this test is in :
* {@link org.springframework.cloud.kubernetes.client.config.boostrap.stubs.SourcesOrderConfigurationStub}
*
* @author wind57
*/
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SourcesOrderApp.class,
properties = { "spring.cloud.bootstrap.name=retryable-sources-order", "sources.order.stub=true",
"spring.main.cloud-platform=KUBERNETES", "spring.cloud.bootstrap.enabled=true" })
@AutoConfigureWebTestClient
class ConfigDataRetryableSourcesOrderTests extends SourcesOrderTests {
private static MockedStatic<KubernetesClientUtils> clientUtilsMock;
@BeforeAll
static void wireMock() {
WireMockServer server = new WireMockServer(options().dynamicPort());
server.start();
WireMock.configureFor("localhost", server.port());
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
stubConfigMapData();
stubSecretsData();
}
@AfterAll
static void teardown() {
clientUtilsMock.close();
}
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright 2013-2023 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.client.config.applications.sources_order;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import io.kubernetes.client.util.ClientBuilder;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.kubernetes.client.KubernetesClientUtils;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.mockito.Mockito.mockStatic;
import static org.springframework.cloud.kubernetes.client.config.boostrap.stubs.SourcesOrderConfigurationStub.stubConfigMapData;
import static org.springframework.cloud.kubernetes.client.config.boostrap.stubs.SourcesOrderConfigurationStub.stubSecretsData;
/**
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SourcesOrderApp.class,
properties = { "spring.cloud.application.name=sources-order", "sources.order.stub=true",
"spring.main.cloud-platform=KUBERNETES",
"spring.config.import=kubernetes:,classpath:./sources-order.yaml",
"spring.cloud.kubernetes.client.namespace=spring-k8s" })
class ConfigDataSourcesOrderTests extends SourcesOrderTests {
private static MockedStatic<KubernetesClientUtils> clientUtilsMock;
@BeforeAll
static void wireMock() {
WireMockServer server = new WireMockServer(options().dynamicPort());
server.start();
WireMock.configureFor("localhost", server.port());
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
stubConfigMapData();
stubSecretsData();
}
@AfterAll
static void teardown() {
clientUtilsMock.close();
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.kubernetes.client.config;
package org.springframework.cloud.kubernetes.client.config.applications.sources_order;
import com.github.tomakehurst.wiremock.client.WireMock;
import org.hamcrest.Matchers;
@@ -26,7 +26,6 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.kubernetes.client.config.applications.sources_order.SourcesOrderApp;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.reactive.server.WebTestClient;
@@ -39,9 +38,9 @@ import org.springframework.test.web.reactive.server.WebTestClient;
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SourcesOrderApp.class,
properties = { "spring.cloud.bootstrap.name=sources-order", "sources.order.stub=true",
"spring.main.cloud-platform=KUBERNETES", "spring.cloud.bootstrap.enabled=true"})
"spring.main.cloud-platform=KUBERNETES", "spring.cloud.bootstrap.enabled=true" })
@AutoConfigureWebTestClient
class KubernetesClientSourcesOrderTests {
abstract class SourcesOrderTests {
@Autowired
private WebTestClient webClient;

View File

@@ -64,7 +64,7 @@ public class SourcesOrderConfigurationStub {
return apiClient;
}
private void stubConfigMapData() {
public static void stubConfigMapData() {
Map<String, String> configMapData = new HashMap<>();
configMapData.put("my.key", "from-configmap");
@@ -82,7 +82,7 @@ public class SourcesOrderConfigurationStub {
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allConfigMaps))));
}
private void stubSecretsData() {
public static void stubSecretsData() {
Map<String, byte[]> secretData = new HashMap<>();
secretData.put("my.key", "from-secret".getBytes(StandardCharsets.UTF_8));

View File

@@ -43,13 +43,14 @@ public class KubernetesConfigDataLoader implements ConfigDataLoader<KubernetesCo
ConfigurableBootstrapContext bootstrapContext = context.getBootstrapContext();
Environment env = resource.getEnvironment();
if (bootstrapContext.isRegistered(ConfigMapPropertySourceLocator.class)) {
propertySources.add(bootstrapContext.get(ConfigMapPropertySourceLocator.class).locate(env));
}
if (bootstrapContext.isRegistered(SecretsPropertySourceLocator.class)) {
propertySources.add(bootstrapContext.get(SecretsPropertySourceLocator.class).locate(env));
}
if (bootstrapContext.isRegistered(ConfigMapPropertySourceLocator.class)) {
propertySources.add(bootstrapContext.get(ConfigMapPropertySourceLocator.class).locate(env));
}
// boot 2.4.5+
return new ConfigData(propertySources, propertySource -> {
String propertySourceName = propertySource.getName();

View File

@@ -137,8 +137,8 @@ class KubernetesConfigDataLoaderTests {
ConfigData configData = loader.load(CONTEXT, EMPTY_RESOURCE);
Assertions.assertNotNull(configData);
Assertions.assertEquals(2, configData.getPropertySources().size());
Assertions.assertEquals("k8s-config-map", configData.getPropertySources().get(0).getName());
Assertions.assertEquals("k8s-secrets", configData.getPropertySources().get(1).getName());
Assertions.assertEquals("k8s-secrets", configData.getPropertySources().get(0).getName());
Assertions.assertEquals("k8s-config-map", configData.getPropertySources().get(1).getName());
}
}

View File

@@ -19,19 +19,16 @@ package org.springframework.cloud.kubernetes.fabric8.config;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.kubernetes.fabric8.config.example.App;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Tests reading property from YAML document specified by profile expression.
*/
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
properties = { "spring.application.name=configmap-with-profile-example",
"spring.cloud.kubernetes.reload.enabled=false", "spring.main.cloud-platform=KUBERNETES",
@@ -39,12 +36,12 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@ActiveProfiles({ "production", "us-east" })
@AutoConfigureWebTestClient
@EnableKubernetesMockClient(crud = true, https = false)
public class BootstrapConfigMapsWithProfileExpressionTests extends ConfigMapsWithProfileExpressionTests {
class BootstrapConfigMapsWithProfileExpressionTests extends ConfigMapsWithProfileExpressionTests {
private static KubernetesClient mockClient;
@BeforeAll
public static void setUpBeforeClass() {
static void setUpBeforeClass() {
setUpBeforeClass(mockClient);
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright 2013-2023 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.retryable_sources_order;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = RetryableSourcesOrderApp.class,
properties = { "spring.cloud.bootstrap.name=retryable-sources-order", "spring.main.cloud-platform=KUBERNETES",
"spring.cloud.bootstrap.enabled=true" })
@EnableKubernetesMockClient(crud = true, https = false)
class BootstrapRetryableSourcesOrderTests extends RetryableSourcesOrderTests {
private static KubernetesClient mockClient;
@BeforeAll
static void setUp() {
setUpBeforeClass(mockClient);
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2013-2023 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.retryable_sources_order;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.boot.test.context.SpringBootTest;
/**
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = RetryableSourcesOrderApp.class,
properties = { "spring.application.name=sources-order", "spring.main.cloud-platform=KUBERNETES",
"spring.config.import=kubernetes:,classpath:./retryable-sources-order.yaml" })
@EnableKubernetesMockClient(crud = true, https = false)
class ConfigDataRetryableSourcesOrderTests extends RetryableSourcesOrderTests {
private static KubernetesClient mockClient;
@BeforeAll
static void setUp() {
setUpBeforeClass(mockClient);
}
}

View File

@@ -25,32 +25,21 @@ import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
import io.fabric8.kubernetes.api.model.SecretBuilder;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = RetryableSourcesOrderApp.class,
properties = { "spring.cloud.bootstrap.name=retryable-sources-order" })
@EnableKubernetesMockClient(crud = true, https = false)
class RetryableSourcesOrderTests {
abstract class RetryableSourcesOrderTests {
private static KubernetesClient mockClient;
@Autowired
private WebTestClient webClient;
@BeforeAll
static void setUpBeforeClass() {
static void setUpBeforeClass(KubernetesClient mockClient) {
RetryableSourcesOrderTests.mockClient = mockClient;
// Configure the kubernetes master url to point to the mock server
System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl());
System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true");
@@ -71,11 +60,6 @@ class RetryableSourcesOrderTests {
}
@AfterAll
static void afterAll() {
System.clearProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY);
}
private static void createSecret(String name, Map<String, String> data) {
mockClient.secrets().inNamespace("spring-k8s")
.create(new SecretBuilder().withNewMetadata().withName(name).endMetadata().addToData(data).build());

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2013-2023 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.sources_order;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.boot.test.context.SpringBootTest;
/**
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SourcesOrderApp.class,
properties = { "spring.cloud.bootstrap.name=sources-order", "spring.main.cloud-platform=KUBERNETES",
"spring.cloud.bootstrap.enabled=true" })
@EnableKubernetesMockClient(crud = true, https = false)
class BootstrapSourcesOrderTests extends SourcesOrderTests {
private static KubernetesClient mockClient;
@BeforeAll
static void setUp() {
setUpBeforeClass(mockClient);
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2013-2023 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.sources_order;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.boot.test.context.SpringBootTest;
/**
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SourcesOrderApp.class,
properties = { "spring.application.name=sources-order", "spring.main.cloud-platform=KUBERNETES",
"spring.config.import=kubernetes:,classpath:./sources-order.yaml" })
@EnableKubernetesMockClient(crud = true, https = false)
class ConfigDataSourcesOrderTests extends SourcesOrderTests {
private static KubernetesClient mockClient;
@BeforeAll
static void setUp() {
setUpBeforeClass(mockClient);
}
}

View File

@@ -25,31 +25,24 @@ import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
import io.fabric8.kubernetes.api.model.SecretBuilder;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* @author wind57
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SourcesOrderApp.class,
properties = { "spring.cloud.bootstrap.name=sources-order" })
@EnableKubernetesMockClient(crud = true, https = false)
class SourcesOrderTests {
abstract class SourcesOrderTests {
private static KubernetesClient mockClient;
@Autowired
private WebTestClient webClient;
@BeforeAll
static void setUpBeforeClass() {
static void setUpBeforeClass(KubernetesClient mockClient) {
SourcesOrderTests.mockClient = mockClient;
// Configure the kubernetes master url to point to the mock server
System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl());
@@ -71,11 +64,6 @@ class SourcesOrderTests {
}
@AfterAll
static void afterAll() {
System.clearProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY);
}
private static void createSecret(String name, Map<String, String> data) {
mockClient.secrets().inNamespace("spring-k8s")
.create(new SecretBuilder().withNewMetadata().withName(name).endMetadata().addToData(data).build());