Skip to content

Commit 18f9c41

Browse files
authored
refactor tests (#1789)
Signed-off-by: wind57 <[email protected]>
1 parent 19ee913 commit 18f9c41

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.fabric8.kubernetes.client.KubernetesClient;
2323
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
2424
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
25+
import org.junit.jupiter.api.BeforeAll;
2526
import org.junit.jupiter.api.Test;
2627

2728
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
@@ -38,9 +39,14 @@
3839
@EnableKubernetesMockClient
3940
class Fabric8ConfigMapPropertySourceLocatorTests {
4041

41-
private KubernetesMockServer mockServer;
42+
private static KubernetesMockServer mockServer;
4243

43-
private KubernetesClient mockClient;
44+
private static KubernetesClient mockClient;
45+
46+
@BeforeAll
47+
static void beforeAll() {
48+
mockClient.getConfiguration().setRequestRetryBackoffLimit(1);
49+
}
4450

4551
@Test
4652
void locateShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
2121
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
2222
import org.junit.jupiter.api.AfterEach;
23+
import org.junit.jupiter.api.BeforeEach;
2324
import org.junit.jupiter.api.Test;
2425

2526
import org.springframework.cloud.kubernetes.commons.config.ConfigUtils;
@@ -42,6 +43,11 @@ class Fabric8ConfigMapPropertySourceTests {
4243

4344
private static final ConfigUtils.Prefix DEFAULT = ConfigUtils.findPrefix("default", false, false, "irrelevant");
4445

46+
@BeforeEach
47+
void beforeEach() {
48+
mockClient.getConfiguration().setRequestRetryBackoffLimit(1);
49+
}
50+
4551
@AfterEach
4652
void afterEach() {
4753
new Fabric8ConfigMapsCache().discardAll();
@@ -51,7 +57,7 @@ void afterEach() {
5157
void constructorShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
5258
String name = "my-config";
5359
String namespace = "default";
54-
String path = String.format("/api/v1/namespaces/%s/configmaps", namespace);
60+
String path = "/api/v1/namespaces/" + namespace + "/configmaps";
5561

5662
mockServer.expect().withPath(path).andReturn(500, "Internal Server Error").always();
5763
NormalizedSource source = new NamedConfigMapNormalizedSource(name, namespace, true, DEFAULT, true);
@@ -64,11 +70,11 @@ void constructorShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
6470
void constructorShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
6571
String name = "my-config";
6672
String namespace = "default";
67-
String path = String.format("/api/v1/namespaces/%s/configmaps/%s", namespace, name);
73+
String path = "/api/v1/namespaces/" + namespace + "/configmaps";
6874

6975
mockServer.expect().withPath(path).andReturn(500, "Internal Server Error").always();
7076
NormalizedSource source = new NamedConfigMapNormalizedSource(name, namespace, false, false);
71-
Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, source, "", new MockEnvironment());
77+
Fabric8ConfigContext context = new Fabric8ConfigContext(mockClient, source, "default", new MockEnvironment());
7278
assertThatNoException().isThrownBy(() -> new Fabric8ConfigMapPropertySource(context));
7379
}
7480

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.fabric8.kubernetes.client.KubernetesClient;
2323
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
2424
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
25+
import org.junit.jupiter.api.BeforeAll;
2526
import org.junit.jupiter.api.Test;
2627

2728
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
@@ -38,9 +39,14 @@
3839
@EnableKubernetesMockClient
3940
class Fabric8SecretsPropertySourceLocatorTests {
4041

41-
KubernetesMockServer mockServer;
42+
private static KubernetesMockServer mockServer;
4243

43-
KubernetesClient mockClient;
44+
private static KubernetesClient mockClient;
45+
46+
@BeforeAll
47+
static void beforeAll() {
48+
mockClient.getConfiguration().setRequestRetryBackoffInterval(1);
49+
}
4450

4551
@Test
4652
void locateShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.fabric8.kubernetes.client.KubernetesClient;
2323
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
2424
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
25+
import org.junit.jupiter.api.BeforeAll;
2526
import org.junit.jupiter.api.Test;
2627

2728
import org.springframework.cloud.kubernetes.commons.config.LabeledSecretNormalizedSource;
@@ -43,6 +44,11 @@ class Fabric8SecretsPropertySourceMockTests {
4344

4445
private static KubernetesClient client;
4546

47+
@BeforeAll
48+
static void beforeAll() {
49+
client.getConfiguration().setRequestRetryBackoffInterval(1);
50+
}
51+
4652
@Test
4753
void namedStrategyShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
4854
final String name = "my-secret";

0 commit comments

Comments
 (0)