Skip to content

Commit b08280c

Browse files
committed
fix
1 parent 5d593c1 commit b08280c

File tree

6 files changed

+84
-11
lines changed

6 files changed

+84
-11
lines changed

spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigMapPropertySourceLocatorTests.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.cloud.kubernetes.client.config;
1818

19+
import java.util.ArrayList;
1920
import java.util.Collections;
2021
import java.util.List;
2122
import java.util.Map;
@@ -35,11 +36,15 @@
3536
import org.junit.jupiter.api.BeforeAll;
3637
import org.junit.jupiter.api.Test;
3738

39+
import org.junit.jupiter.api.extension.ExtendWith;
40+
import org.springframework.boot.test.system.CapturedOutput;
41+
import org.springframework.boot.test.system.OutputCaptureExtension;
3842
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
3943
import org.springframework.cloud.kubernetes.commons.config.ConfigMapConfigProperties;
4044
import org.springframework.cloud.kubernetes.commons.config.Constants;
4145
import org.springframework.cloud.kubernetes.commons.config.NamespaceResolutionFailedException;
4246
import org.springframework.cloud.kubernetes.commons.config.RetryProperties;
47+
import org.springframework.core.env.CompositePropertySource;
4348
import org.springframework.core.env.PropertySource;
4449
import org.springframework.mock.env.MockEnvironment;
4550

@@ -55,6 +60,7 @@
5560
* @author Ryan Baxter
5661
* @author Isik Erhan
5762
*/
63+
@ExtendWith(OutputCaptureExtension.class)
5864
class KubernetesClientConfigMapPropertySourceLocatorTests {
5965

6066
private static final V1ConfigMapList PROPERTIES_CONFIGMAP_LIST = new V1ConfigMapList()
@@ -185,7 +191,7 @@ public void locateShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
185191
}
186192

187193
@Test
188-
public void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
194+
public void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled(CapturedOutput output) {
189195
CoreV1Api api = new CoreV1Api();
190196
stubFor(get("/api/v1/namespaces/default/configmaps")
191197
.willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
@@ -196,7 +202,18 @@ public void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
196202
KubernetesClientConfigMapPropertySourceLocator locator = new KubernetesClientConfigMapPropertySourceLocator(api,
197203
configMapConfigProperties, new KubernetesNamespaceProvider(new MockEnvironment()));
198204

199-
assertThatNoException().isThrownBy(() -> locator.locate(new MockEnvironment()));
205+
List<PropertySource<?>> result = new ArrayList<>();
206+
assertThatNoException().isThrownBy(() -> {
207+
PropertySource<?> source = locator.locate(new MockEnvironment());
208+
result.add(source);
209+
});
210+
211+
assertThat(result.get(0)).isInstanceOf(CompositePropertySource.class);
212+
CompositePropertySource composite = (CompositePropertySource) result.get(0);
213+
assertThat(composite.getPropertySources()).hasSize(0);
214+
assertThat(output.getOut()).contains("Failed to load source:");
215+
216+
200217
}
201218

202219
}

spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientSecretsPropertySourceLocatorTests.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.cloud.kubernetes.client.config;
1818

19+
import java.util.ArrayList;
1920
import java.util.Collections;
2021
import java.util.List;
2122
import java.util.Map;
@@ -31,10 +32,14 @@
3132
import org.junit.jupiter.api.BeforeAll;
3233
import org.junit.jupiter.api.Test;
3334

35+
import org.junit.jupiter.api.extension.ExtendWith;
36+
import org.springframework.boot.test.system.CapturedOutput;
37+
import org.springframework.boot.test.system.OutputCaptureExtension;
3438
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
3539
import org.springframework.cloud.kubernetes.commons.config.NamespaceResolutionFailedException;
3640
import org.springframework.cloud.kubernetes.commons.config.RetryProperties;
3741
import org.springframework.cloud.kubernetes.commons.config.SecretsConfigProperties;
42+
import org.springframework.core.env.CompositePropertySource;
3843
import org.springframework.core.env.PropertySource;
3944
import org.springframework.mock.env.MockEnvironment;
4045

@@ -50,6 +55,7 @@
5055
* @author Ryan Baxter
5156
* @author Isik Erhan
5257
*/
58+
@ExtendWith(OutputCaptureExtension.class)
5359
class KubernetesClientSecretsPropertySourceLocatorTests {
5460

5561
private static final String LIST_API = "/api/v1/namespaces/default/secrets";
@@ -200,7 +206,7 @@ void locateShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
200206
}
201207

202208
@Test
203-
void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
209+
void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled(CapturedOutput output) {
204210
CoreV1Api api = new CoreV1Api();
205211
stubFor(get(LIST_API).willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
206212

@@ -210,7 +216,16 @@ void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
210216
KubernetesClientSecretsPropertySourceLocator locator = new KubernetesClientSecretsPropertySourceLocator(api,
211217
new KubernetesNamespaceProvider(new MockEnvironment()), secretsConfigProperties);
212218

213-
assertThatNoException().isThrownBy(() -> locator.locate(new MockEnvironment()));
219+
List<PropertySource<?>> result = new ArrayList<>();
220+
assertThatNoException().isThrownBy(() -> {
221+
PropertySource<?> source = locator.locate(new MockEnvironment());
222+
result.add(source);
223+
});
224+
225+
assertThat(result.get(0)).isInstanceOf(CompositePropertySource.class);
226+
CompositePropertySource composite = (CompositePropertySource) result.get(0);
227+
assertThat(composite.getPropertySources()).hasSize(0);
228+
assertThat(output.getOut()).contains("Failed to load source:");
214229
}
215230

216231
}

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigMapPropertySourceLocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public PropertySource<?> locate(Environment environment) {
8585
sources.forEach(s -> {
8686
MapPropertySource propertySource = getMapPropertySource(s, env);
8787
if ("true".equals(propertySource.getProperty(Constants.ERROR_PROPERTY))) {
88-
LOG.warn("Failed to load config map: " + s.name());
88+
LOG.warn("Failed to load source: " + s);
8989
}
9090
else {
9191
LOG.debug("Adding config map property source " + propertySource.getName());

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/SecretsPropertySourceLocator.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,14 @@ public PropertySource<?> locate(Environment environment) {
9090
if (this.properties.enableApi()) {
9191
uniqueSources.forEach(s -> {
9292
MapPropertySource propertySource = getSecretsPropertySourceForSingleSecret(env, s);
93-
LOG.debug("Adding secret property source " + propertySource.getName());
94-
composite.addFirstPropertySource(propertySource);
93+
94+
if ("true".equals(propertySource.getProperty(Constants.ERROR_PROPERTY))) {
95+
LOG.warn("Failed to load source: " + s);
96+
}
97+
else {
98+
LOG.debug("Adding secret property source " + propertySource.getName());
99+
composite.addFirstPropertySource(propertySource);
100+
}
95101
});
96102
}
97103

spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8ConfigMapPropertySourceLocatorTests.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.cloud.kubernetes.fabric8.config;
1818

19+
import java.util.ArrayList;
1920
import java.util.List;
2021
import java.util.Map;
2122

@@ -25,18 +26,25 @@
2526
import org.junit.jupiter.api.BeforeAll;
2627
import org.junit.jupiter.api.Test;
2728

29+
import org.junit.jupiter.api.extension.ExtendWith;
30+
import org.springframework.boot.test.system.CapturedOutput;
31+
import org.springframework.boot.test.system.OutputCaptureExtension;
2832
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
2933
import org.springframework.cloud.kubernetes.commons.config.ConfigMapConfigProperties;
3034
import org.springframework.cloud.kubernetes.commons.config.RetryProperties;
35+
import org.springframework.core.env.CompositePropertySource;
36+
import org.springframework.core.env.PropertySource;
3137
import org.springframework.mock.env.MockEnvironment;
3238

39+
import static org.assertj.core.api.Assertions.assertThat;
3340
import static org.assertj.core.api.Assertions.assertThatNoException;
3441
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3542

3643
/**
3744
* @author Isik Erhan
3845
*/
3946
@EnableKubernetesMockClient
47+
@ExtendWith(OutputCaptureExtension.class)
4048
class Fabric8ConfigMapPropertySourceLocatorTests {
4149

4250
private static KubernetesMockServer mockServer;
@@ -67,7 +75,7 @@ void locateShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
6775
}
6876

6977
@Test
70-
void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
78+
void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled(CapturedOutput output) {
7179
String name = "my-config";
7280
String namespace = "default";
7381
String path = "/api/v1/namespaces/default/configmaps";
@@ -80,7 +88,16 @@ void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
8088
Fabric8ConfigMapPropertySourceLocator locator = new Fabric8ConfigMapPropertySourceLocator(mockClient,
8189
configMapConfigProperties, new KubernetesNamespaceProvider(new MockEnvironment()));
8290

83-
assertThatNoException().isThrownBy(() -> locator.locate(new MockEnvironment()));
91+
List<PropertySource<?>> result = new ArrayList<>();
92+
assertThatNoException().isThrownBy(() -> {
93+
PropertySource<?> source = locator.locate(new MockEnvironment());
94+
result.add(source);
95+
});
96+
97+
assertThat(result.get(0)).isInstanceOf(CompositePropertySource.class);
98+
CompositePropertySource composite = (CompositePropertySource) result.get(0);
99+
assertThat(composite.getPropertySources()).hasSize(0);
100+
assertThat(output.getOut()).contains("Failed to load source:");
84101
}
85102

86103
}

spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/Fabric8SecretsPropertySourceLocatorTests.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.cloud.kubernetes.fabric8.config;
1818

19+
import java.util.ArrayList;
1920
import java.util.List;
2021
import java.util.Map;
2122

@@ -25,18 +26,25 @@
2526
import org.junit.jupiter.api.BeforeAll;
2627
import org.junit.jupiter.api.Test;
2728

29+
import org.junit.jupiter.api.extension.ExtendWith;
30+
import org.springframework.boot.test.system.CapturedOutput;
31+
import org.springframework.boot.test.system.OutputCaptureExtension;
2832
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
2933
import org.springframework.cloud.kubernetes.commons.config.RetryProperties;
3034
import org.springframework.cloud.kubernetes.commons.config.SecretsConfigProperties;
35+
import org.springframework.core.env.CompositePropertySource;
36+
import org.springframework.core.env.PropertySource;
3137
import org.springframework.mock.env.MockEnvironment;
3238

39+
import static org.assertj.core.api.Assertions.assertThat;
3340
import static org.assertj.core.api.Assertions.assertThatNoException;
3441
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3542

3643
/**
3744
* @author Isik Erhan
3845
*/
3946
@EnableKubernetesMockClient
47+
@ExtendWith(OutputCaptureExtension.class)
4048
class Fabric8SecretsPropertySourceLocatorTests {
4149

4250
private static KubernetesMockServer mockServer;
@@ -67,7 +75,7 @@ void locateShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
6775
}
6876

6977
@Test
70-
void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
78+
void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled(CapturedOutput output) {
7179
String name = "my-secret";
7280
String namespace = "default";
7381
String path = "/api/v1/namespaces/default/secrets/my-secret";
@@ -80,7 +88,17 @@ void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
8088
Fabric8SecretsPropertySourceLocator locator = new Fabric8SecretsPropertySourceLocator(mockClient,
8189
configMapConfigProperties, new KubernetesNamespaceProvider(new MockEnvironment()));
8290

83-
assertThatNoException().isThrownBy(() -> locator.locate(new MockEnvironment()));
91+
List<PropertySource<?>> result = new ArrayList<>();
92+
assertThatNoException().isThrownBy(() -> {
93+
PropertySource<?> source = locator.locate(new MockEnvironment());
94+
result.add(source);
95+
});
96+
97+
assertThat(result.get(0)).isInstanceOf(CompositePropertySource.class);
98+
CompositePropertySource composite = (CompositePropertySource) result.get(0);
99+
assertThat(composite.getPropertySources()).hasSize(0);
100+
assertThat(output.getOut()).contains("Failed to load source:");
101+
84102
}
85103

86104
}

0 commit comments

Comments
 (0)