Skip to content

Commit 78eb9a4

Browse files
committed
fix tests
1 parent 0d429a7 commit 78eb9a4

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientSourcesNamespaceBatched.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/**
3232
* @author wind57
3333
*/
34-
final class KubernetesClientSourcesNamespaceBatched implements SecretsCache, ConfigMapCache {
34+
public final class KubernetesClientSourcesNamespaceBatched implements SecretsCache, ConfigMapCache {
3535

3636
private static final LogAccessor LOG = new LogAccessor(
3737
LogFactory.getLog(KubernetesClientSourcesNamespaceBatched.class));

spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/test/java/org/springframework/cloud/kubernetes/configserver/KubernetesEnvironmentRepositoryTests.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
import org.junit.jupiter.api.AfterEach;
3131
import org.junit.jupiter.api.Assertions;
3232
import org.junit.jupiter.api.BeforeAll;
33+
import org.junit.jupiter.api.BeforeEach;
3334
import org.junit.jupiter.api.Test;
3435

3536
import org.springframework.cloud.config.environment.Environment;
3637
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigContext;
3738
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigMapPropertySource;
38-
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigMapsCache;
3939
import org.springframework.cloud.kubernetes.client.config.KubernetesClientSecretsPropertySource;
40+
import org.springframework.cloud.kubernetes.client.config.KubernetesClientSourcesNamespaceBatched;
4041
import org.springframework.cloud.kubernetes.commons.config.ConfigUtils;
4142
import org.springframework.cloud.kubernetes.commons.config.Constants;
4243
import org.springframework.cloud.kubernetes.commons.config.NamedConfigMapNormalizedSource;
@@ -128,13 +129,13 @@ public static void before() {
128129
NormalizedSource defaultSource = new NamedConfigMapNormalizedSource(applicationName, "default", false,
129130
true);
130131
KubernetesClientConfigContext defaultContext = new KubernetesClientConfigContext(coreApi, defaultSource,
131-
"default", springEnv);
132+
"default", springEnv, true, true);
132133
propertySources.add(new KubernetesClientConfigMapPropertySource(defaultContext));
133134

134135
if ("stores".equals(applicationName) && "dev".equals(namespace)) {
135136
NormalizedSource devSource = new NamedConfigMapNormalizedSource(applicationName, "dev", false, true);
136137
KubernetesClientConfigContext devContext = new KubernetesClientConfigContext(coreApi, devSource, "dev",
137-
springEnv);
138+
springEnv, true, true);
138139
propertySources.add(new KubernetesClientConfigMapPropertySource(devContext));
139140
}
140141
return propertySources;
@@ -144,20 +145,27 @@ public static void before() {
144145

145146
NormalizedSource source = new NamedSecretNormalizedSource(applicationName, "default", false, true);
146147
KubernetesClientConfigContext context = new KubernetesClientConfigContext(coreApi, source, "default",
147-
springEnv);
148+
springEnv, true, true);
148149

149150
propertySources.add(new KubernetesClientSecretsPropertySource(context));
150151
return propertySources;
151152
});
152153
}
153154

154155
@AfterEach
155-
public void after() {
156-
new KubernetesClientConfigMapsCache().discardAll();
156+
void afterEach() {
157+
new KubernetesClientSourcesNamespaceBatched().discardConfigMaps();
158+
new KubernetesClientSourcesNamespaceBatched().discardSecrets();
159+
}
160+
161+
@BeforeEach
162+
void beforeEach() {
163+
new KubernetesClientSourcesNamespaceBatched().discardConfigMaps();
164+
new KubernetesClientSourcesNamespaceBatched().discardSecrets();
157165
}
158166

159167
@Test
160-
public void testApplicationCase() throws ApiException {
168+
void testApplicationCase() throws ApiException {
161169
CoreV1Api coreApi = mock(CoreV1Api.class);
162170
when(coreApi.listNamespacedConfigMap(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null),
163171
eq(null), eq(null), eq(null), eq(null), eq(null)))
@@ -191,7 +199,7 @@ public void testApplicationCase() throws ApiException {
191199
}
192200

193201
@Test
194-
public void testStoresCase() throws ApiException {
202+
void testStoresCase() throws ApiException {
195203
CoreV1Api coreApi = mock(CoreV1Api.class);
196204
when(coreApi.listNamespacedConfigMap(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null),
197205
eq(null), eq(null), eq(null), eq(null), eq(null)))
@@ -238,7 +246,7 @@ public void testStoresCase() throws ApiException {
238246
}
239247

240248
@Test
241-
public void testStoresProfileCase() throws ApiException {
249+
void testStoresProfileCase() throws ApiException {
242250
CoreV1Api coreApi = mock(CoreV1Api.class);
243251
when(coreApi.listNamespacedConfigMap(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null),
244252
eq(null), eq(null), eq(null), eq(null), eq(null)))
@@ -302,7 +310,7 @@ else if (propertySource.getName().equals("secret.stores.default")) {
302310
}
303311

304312
@Test
305-
public void testApplicationPropertiesAnSecretsOverride() throws ApiException {
313+
void testApplicationPropertiesAnSecretsOverride() throws ApiException {
306314
CoreV1Api coreApi = mock(CoreV1Api.class);
307315
when(coreApi.listNamespacedConfigMap(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null),
308316
eq(null), eq(null), eq(null), eq(null), eq(null)))
@@ -343,7 +351,7 @@ public void testApplicationPropertiesAnSecretsOverride() throws ApiException {
343351
}
344352

345353
@Test
346-
public void testSingleConfigMapMultipleSources() throws ApiException {
354+
void testSingleConfigMapMultipleSources() throws ApiException {
347355
CoreV1Api coreApi = mock(CoreV1Api.class);
348356
when(coreApi.listNamespacedConfigMap(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null),
349357
eq(null), eq(null), eq(null), eq(null), eq(null)))
@@ -357,7 +365,7 @@ public void testSingleConfigMapMultipleSources() throws ApiException {
357365
NormalizedSource devSource = new NamedConfigMapNormalizedSource(name, namespace, false,
358366
ConfigUtils.Prefix.DEFAULT, true, true);
359367
KubernetesClientConfigContext devContext = new KubernetesClientConfigContext(coreApi, devSource, "default",
360-
environment);
368+
environment, true, true);
361369
propertySources.add(new KubernetesClientConfigMapPropertySource(devContext));
362370
return propertySources;
363371
});

spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/test/java/org/springframework/cloud/kubernetes/configserver/KubernetesPropertySourceSupplierTests.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@
2828
import io.kubernetes.client.openapi.models.V1SecretBuilder;
2929
import io.kubernetes.client.openapi.models.V1SecretList;
3030
import io.kubernetes.client.openapi.models.V1SecretListBuilder;
31+
import org.junit.jupiter.api.AfterAll;
32+
import org.junit.jupiter.api.AfterEach;
3133
import org.junit.jupiter.api.BeforeAll;
34+
import org.junit.jupiter.api.BeforeEach;
3235
import org.junit.jupiter.api.Test;
3336

37+
import org.mockito.Mockito;
3438
import org.springframework.cloud.config.environment.Environment;
39+
import org.springframework.cloud.kubernetes.client.config.KubernetesClientSourcesNamespaceBatched;
3540
import org.springframework.cloud.kubernetes.commons.config.Constants;
3641

3742
import static org.assertj.core.api.Assertions.assertThat;
@@ -71,7 +76,7 @@ class KubernetesPropertySourceSupplierTests {
7176
.build();
7277

7378
@BeforeAll
74-
public static void before() throws ApiException {
79+
static void beforeAll() throws ApiException {
7580
when(coreApi.listNamespacedConfigMap(eq("default"), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null),
7681
eq(null), eq(null), eq(null), eq(null), eq(null)))
7782
.thenReturn(CONFIGMAP_DEFAULT_LIST);
@@ -93,6 +98,23 @@ public static void before() throws ApiException {
9398
.thenReturn(SECRET_TEAM_B_LIST);
9499
}
95100

101+
@AfterAll
102+
static void afterAll() {
103+
Mockito.reset(coreApi);
104+
}
105+
106+
@AfterEach
107+
void afterEach() {
108+
new KubernetesClientSourcesNamespaceBatched().discardConfigMaps();
109+
new KubernetesClientSourcesNamespaceBatched().discardSecrets();
110+
}
111+
112+
@BeforeEach
113+
void beforeEach() {
114+
new KubernetesClientSourcesNamespaceBatched().discardConfigMaps();
115+
new KubernetesClientSourcesNamespaceBatched().discardSecrets();
116+
}
117+
96118
@Test
97119
void whenCurrentAndExtraNamespacesAddedThenAllConfigMapsAreIncluded() {
98120
KubernetesConfigServerProperties kubernetesConfigServerProperties = new KubernetesConfigServerProperties();

0 commit comments

Comments
 (0)