Skip to content

Commit

Permalink
refactor tests (#1789)
Browse files Browse the repository at this point in the history
Signed-off-by: wind57 <[email protected]>
  • Loading branch information
wind57 authored Nov 8, 2024
1 parent 19ee913 commit 18f9c41
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
Expand All @@ -38,9 +39,14 @@
@EnableKubernetesMockClient
class Fabric8ConfigMapPropertySourceLocatorTests {

private KubernetesMockServer mockServer;
private static KubernetesMockServer mockServer;

private KubernetesClient mockClient;
private static KubernetesClient mockClient;

@BeforeAll
static void beforeAll() {
mockClient.getConfiguration().setRequestRetryBackoffLimit(1);
}

@Test
void locateShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

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

@BeforeEach
void beforeEach() {
mockClient.getConfiguration().setRequestRetryBackoffLimit(1);
}

@AfterEach
void afterEach() {
new Fabric8ConfigMapsCache().discardAll();
Expand All @@ -51,7 +57,7 @@ void afterEach() {
void constructorShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
String name = "my-config";
String namespace = "default";
String path = String.format("/api/v1/namespaces/%s/configmaps", namespace);
String path = "/api/v1/namespaces/" + namespace + "/configmaps";

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
Expand All @@ -38,9 +39,14 @@
@EnableKubernetesMockClient
class Fabric8SecretsPropertySourceLocatorTests {

KubernetesMockServer mockServer;
private static KubernetesMockServer mockServer;

KubernetesClient mockClient;
private static KubernetesClient mockClient;

@BeforeAll
static void beforeAll() {
mockClient.getConfiguration().setRequestRetryBackoffInterval(1);
}

@Test
void locateShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

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

private static KubernetesClient client;

@BeforeAll
static void beforeAll() {
client.getConfiguration().setRequestRetryBackoffInterval(1);
}

@Test
void namedStrategyShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
final String name = "my-secret";
Expand Down

0 comments on commit 18f9c41

Please sign in to comment.