Skip to content

Commit 1560bb5

Browse files
committed
fix fabric8 tests
1 parent cd715b9 commit 1560bb5

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import org.springframework.boot.test.system.OutputCaptureExtension;
3434
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
3535
import org.springframework.cloud.kubernetes.commons.config.ConfigMapConfigProperties;
36+
import org.springframework.cloud.kubernetes.commons.config.Constants;
3637
import org.springframework.cloud.kubernetes.commons.config.RetryProperties;
37-
import org.springframework.cloud.kubernetes.commons.config.SourceData;
3838
import org.springframework.core.env.CompositePropertySource;
3939
import org.springframework.core.env.MapPropertySource;
4040
import org.springframework.core.env.PropertySource;
@@ -85,7 +85,7 @@ void namedSingleConfigMapFails() {
8585
.findAny()
8686
.orElseThrow();
8787

88-
assertThat(mapPropertySource.getName()).isEqualTo(SourceData.EMPTY_SOURCE_NAME_ON_ERROR);
88+
assertThat(mapPropertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
8989

9090
}
9191

@@ -123,8 +123,9 @@ void namedTwoConfigMapsOneFails() {
123123
CompositePropertySource propertySource = (CompositePropertySource) locator.locate(new MockEnvironment());
124124
List<String> names = propertySource.getPropertySources().stream().map(PropertySource::getName).toList();
125125

126-
// two sources are present, one being empty
127-
assertThat(names).containsExactly("configmap.two.default", SourceData.EMPTY_SOURCE_NAME_ON_ERROR);
126+
// two sources are present
127+
assertThat(names).containsExactly("configmap.two.default", "configmap..default");
128+
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
128129

129130
}
130131

@@ -157,7 +158,8 @@ void namedTwoConfigMapsBothFail() {
157158
CompositePropertySource propertySource = (CompositePropertySource) locator.locate(new MockEnvironment());
158159
List<String> names = propertySource.getPropertySources().stream().map(PropertySource::getName).toList();
159160

160-
assertThat(names).containsExactly(SourceData.EMPTY_SOURCE_NAME_ON_ERROR);
161+
assertThat(names).containsExactly("configmap..default");
162+
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
161163

162164
}
163165

@@ -188,7 +190,8 @@ void labeledSingleConfigMapFails(CapturedOutput output) {
188190
CompositePropertySource propertySource = (CompositePropertySource) locator.locate(new MockEnvironment());
189191
List<String> sourceNames = propertySource.getPropertySources().stream().map(PropertySource::getName).toList();
190192

191-
assertThat(sourceNames).containsExactly(SourceData.EMPTY_SOURCE_NAME_ON_ERROR);
193+
assertThat(sourceNames).containsExactly("configmap..spring-k8s");
194+
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
192195
assertThat(output).contains("failure in reading labeled sources");
193196
assertThat(output).contains("failure in reading named sources");
194197
}
@@ -234,7 +237,8 @@ void labeledTwoConfigMapsOneFails(CapturedOutput output) {
234237
List<String> names = propertySource.getPropertySources().stream().map(PropertySource::getName).toList();
235238

236239
// two sources are present, one being empty
237-
assertThat(names).containsExactly("configmap.two.default", SourceData.EMPTY_SOURCE_NAME_ON_ERROR);
240+
assertThat(names).containsExactly("configmap.two.default", "configmap..default");
241+
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
238242

239243
assertThat(output).contains("failure in reading labeled sources");
240244
assertThat(output).contains("failure in reading named sources");
@@ -272,8 +276,8 @@ void labeledTwoConfigMapsBothFail(CapturedOutput output) {
272276
CompositePropertySource propertySource = (CompositePropertySource) locator.locate(new MockEnvironment());
273277
List<String> names = propertySource.getPropertySources().stream().map(PropertySource::getName).toList();
274278

275-
// all 3 sources ('application' named source, and two labeled sources)
276-
assertThat(names).containsExactly(SourceData.EMPTY_SOURCE_NAME_ON_ERROR);
279+
assertThat(names).containsExactly("configmap..default");
280+
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
277281

278282
assertThat(output).contains("failure in reading labeled sources");
279283
assertThat(output).contains("failure in reading named sources");

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
import org.springframework.boot.test.system.CapturedOutput;
3333
import org.springframework.boot.test.system.OutputCaptureExtension;
3434
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
35+
import org.springframework.cloud.kubernetes.commons.config.Constants;
3536
import org.springframework.cloud.kubernetes.commons.config.RetryProperties;
3637
import org.springframework.cloud.kubernetes.commons.config.SecretsConfigProperties;
37-
import org.springframework.cloud.kubernetes.commons.config.SourceData;
3838
import org.springframework.core.env.CompositePropertySource;
3939
import org.springframework.core.env.MapPropertySource;
4040
import org.springframework.core.env.PropertySource;
@@ -85,7 +85,8 @@ void namedSingleSecretFails(CapturedOutput output) {
8585
.findAny()
8686
.orElseThrow();
8787

88-
assertThat(mapPropertySource.getName()).isEqualTo(SourceData.EMPTY_SOURCE_NAME_ON_ERROR);
88+
assertThat(mapPropertySource.getName()).isEqualTo("secret..spring-k8s");
89+
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
8990
assertThat(output).contains("failure in reading named sources");
9091

9192
}
@@ -121,7 +122,8 @@ void namedTwoSecretsOneFails() {
121122
List<String> names = propertySource.getPropertySources().stream().map(PropertySource::getName).toList();
122123

123124
// two sources are present, one being empty
124-
assertThat(names).containsExactly("secret.two.default", SourceData.EMPTY_SOURCE_NAME_ON_ERROR);
125+
assertThat(names).containsExactly("secret.two.default", "secret..default");
126+
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
125127

126128
}
127129

@@ -153,7 +155,8 @@ void namedTwoSecretsBothFail() {
153155
CompositePropertySource propertySource = (CompositePropertySource) locator.locate(new MockEnvironment());
154156
List<String> names = propertySource.getPropertySources().stream().map(PropertySource::getName).toList();
155157

156-
assertThat(names).containsExactly(SourceData.EMPTY_SOURCE_NAME_ON_ERROR);
158+
assertThat(names).containsExactly("secret..default");
159+
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
157160

158161
}
159162

@@ -184,7 +187,8 @@ void labeledSingleSecretFails(CapturedOutput output) {
184187
CompositePropertySource propertySource = (CompositePropertySource) locator.locate(new MockEnvironment());
185188
List<String> sourceNames = propertySource.getPropertySources().stream().map(PropertySource::getName).toList();
186189

187-
assertThat(sourceNames).containsExactly(SourceData.EMPTY_SOURCE_NAME_ON_ERROR);
190+
assertThat(sourceNames).containsExactly("secret..spring-k8s");
191+
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
188192
assertThat(output).contains("failure in reading labeled sources");
189193
assertThat(output).contains("failure in reading named sources");
190194
}
@@ -230,7 +234,8 @@ void labeledTwoSecretsOneFails(CapturedOutput output) {
230234
List<String> names = propertySource.getPropertySources().stream().map(PropertySource::getName).toList();
231235

232236
// two sources are present, one being empty
233-
assertThat(names).containsExactly("secret.two.default", SourceData.EMPTY_SOURCE_NAME_ON_ERROR);
237+
assertThat(names).containsExactly("secret.two.default", "secret..default");
238+
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
234239

235240
assertThat(output).contains("failure in reading labeled sources");
236241
assertThat(output).contains("failure in reading named sources");
@@ -268,8 +273,8 @@ void labeledTwoConfigMapsBothFail(CapturedOutput output) {
268273
CompositePropertySource propertySource = (CompositePropertySource) locator.locate(new MockEnvironment());
269274
List<String> names = propertySource.getPropertySources().stream().map(PropertySource::getName).toList();
270275

271-
// all 3 sources ('application' named source, and two labeled sources)
272-
assertThat(names).containsExactly(SourceData.EMPTY_SOURCE_NAME_ON_ERROR);
276+
assertThat(names).containsExactly("secret..default");
277+
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
273278

274279
assertThat(output).contains("failure in reading labeled sources");
275280
assertThat(output).contains("failure in reading named sources");

0 commit comments

Comments
 (0)