Fix reactive discovery client tests (#1069)
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.client;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -33,7 +32,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "management.health.kubernetes.enabled=false", "management.endpoint.health.show-details=always",
|
||||
"management.endpoint.health.show-components=always",
|
||||
"management.endpoint.health.show-components=always", "spring.main.cloud-platform=KUBERNETES",
|
||||
"management.endpoints.web.exposure.include=health" })
|
||||
class ActuatorDisabledHealthTest {
|
||||
|
||||
@@ -47,10 +46,10 @@ class ActuatorDisabledHealthTest {
|
||||
private int port;
|
||||
|
||||
@Test
|
||||
void healthEndpointShouldContainKubernetes() {
|
||||
void healthEndpointShouldNotContainKubernetes() {
|
||||
this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port)
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody(String.class)
|
||||
.value(Matchers.not(Matchers.containsString("kubernetes")));
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("components.kubernetes").doesNotExist();
|
||||
|
||||
Assertions.assertNull(registry.getContributor("kubernetes"),
|
||||
"reactive kubernetes contributor must NOT be present when 'management.health.kubernetes.enabled=false'");
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.client;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -46,8 +45,8 @@ class ActuatorEnabledHealthTest {
|
||||
@Test
|
||||
void healthEndpointShouldContainKubernetes() {
|
||||
this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port)
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody(String.class)
|
||||
.value(Matchers.containsString("kubernetes"));
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("components.kubernetes").exists();
|
||||
|
||||
Assertions.assertNotNull(registry.getContributor("kubernetes"),
|
||||
"reactive kubernetes contributor must be present when 'management.health.kubernetes.enabled=true'");
|
||||
|
||||
@@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.client.password=mypassword",
|
||||
"spring.cloud.kubernetes.client.proxy-password=myproxypassword" })
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class Fabric8AutoConfigurationTests {
|
||||
class Fabric8AutoConfigurationTests {
|
||||
|
||||
private static KubernetesClient mockClient;
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Fabric8AutoConfigurationTests {
|
||||
ConfigurableApplicationContext context;
|
||||
|
||||
@BeforeAll
|
||||
public static void setUpBeforeClass() {
|
||||
static void setUpBeforeClass() {
|
||||
// Configure the kubernetes master url to point to the mock server
|
||||
System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl());
|
||||
System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true");
|
||||
@@ -57,7 +57,7 @@ public class Fabric8AutoConfigurationTests {
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void afterClass() {
|
||||
static void afterClass() {
|
||||
System.clearProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY);
|
||||
System.clearProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY);
|
||||
System.clearProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY);
|
||||
@@ -67,7 +67,7 @@ public class Fabric8AutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beansAreCreated() {
|
||||
void beansAreCreated() {
|
||||
assertThat(context.getBeanNamesForType(Config.class)).hasSize(1);
|
||||
assertThat(context.getBeanNamesForType(KubernetesClient.class)).hasSize(1);
|
||||
assertThat(context.getBeanNamesForType(Fabric8PodUtils.class)).hasSize(1);
|
||||
|
||||
@@ -29,13 +29,10 @@ import org.springframework.cloud.kubernetes.example.App;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "management.health.kubernetes.enabled=false" })
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class Fabric8HealthIndicatorDisabledTest {
|
||||
class Fabric8HealthIndicatorDisabledTest {
|
||||
|
||||
private static KubernetesClient mockClient;
|
||||
|
||||
@@ -46,7 +43,7 @@ public class Fabric8HealthIndicatorDisabledTest {
|
||||
private int port;
|
||||
|
||||
@BeforeAll
|
||||
public static void setUpBeforeClass() {
|
||||
static void setUpBeforeClass() {
|
||||
// Configure the kubernetes master url to point to the mock server
|
||||
System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl());
|
||||
System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true");
|
||||
@@ -56,10 +53,10 @@ public class Fabric8HealthIndicatorDisabledTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthEndpointShouldContainKubernetes() {
|
||||
void healthEndpointShouldContainKubernetes() {
|
||||
this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port)
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody(String.class)
|
||||
.value(not(containsString("kubernetes")));
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("components.kubernetes").doesNotExist();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,16 +17,11 @@
|
||||
package org.springframework.cloud.kubernetes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.fabric8.kubernetes.api.model.Pod;
|
||||
import io.fabric8.kubernetes.api.model.PodBuilder;
|
||||
import io.fabric8.kubernetes.api.model.PodSpec;
|
||||
import io.fabric8.kubernetes.api.model.PodStatus;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@@ -51,7 +46,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
@Import(Fabric8InsideHealthIndicatorTest.KubernetesActuatorTestConfiguration.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "management.endpoint.health.show-details=always" })
|
||||
public class Fabric8InsideHealthIndicatorTest {
|
||||
class Fabric8InsideHealthIndicatorTest {
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webClient;
|
||||
@@ -59,28 +54,6 @@ public class Fabric8InsideHealthIndicatorTest {
|
||||
@Value("${local.server.port}")
|
||||
private int port;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port)
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody(String.class)
|
||||
.value(Fabric8InsideHealthIndicatorTest::validateKubernetes);
|
||||
}
|
||||
|
||||
private static Pod stubPod() {
|
||||
|
||||
PodStatus status = new PodStatus();
|
||||
status.setPodIP("10.1.1.1");
|
||||
status.setHostIP("192.160.10.3");
|
||||
|
||||
PodSpec spec = new PodSpec();
|
||||
spec.setServiceAccountName("serviceAccountName");
|
||||
spec.setNodeName("nodeName");
|
||||
|
||||
return new PodBuilder().withNewMetadata().withName("pod").withNamespace("namespace")
|
||||
.withLabels(Collections.singletonMap("labelName", "labelValue")).endMetadata().withStatus(status)
|
||||
.withSpec(spec).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* "stubKubernetes": {
|
||||
@@ -99,31 +72,34 @@ public class Fabric8InsideHealthIndicatorTest {
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void validateKubernetes(String input) {
|
||||
try {
|
||||
Map<String, Object> map = new ObjectMapper().readValue(input, new TypeReference<Map<String, Object>>() {
|
||||
@Test
|
||||
void test() {
|
||||
this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port)
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("components.stubKubernetes.status").isEqualTo("UP")
|
||||
.jsonPath("components.stubKubernetes.details.nodeName").isEqualTo("nodeName")
|
||||
.jsonPath("components.stubKubernetes.details.podIp").isEqualTo("10.1.1.1")
|
||||
.jsonPath("components.stubKubernetes.details.hostIp").isEqualTo("192.160.10.3")
|
||||
.jsonPath("components.stubKubernetes.details.namespace").isEqualTo("namespace")
|
||||
.jsonPath("components.stubKubernetes.details.podName").isEqualTo("pod")
|
||||
.jsonPath("components.stubKubernetes.details.serviceAccount").isEqualTo("serviceAccountName")
|
||||
.jsonPath("components.stubKubernetes.details.inside").isEqualTo("true")
|
||||
.jsonPath("components.stubKubernetes.details.labels.labelName").isEqualTo("labelValue");
|
||||
}
|
||||
|
||||
});
|
||||
Map<String, Object> kubernetesProperties = (Map<String, Object>) ((Map<String, Object>) map
|
||||
.get("components")).get("stubKubernetes");
|
||||
Assertions.assertEquals("UP", kubernetesProperties.get("status"));
|
||||
private static Pod stubPod() {
|
||||
|
||||
Map<String, Object> details = (Map<String, Object>) kubernetesProperties.get("details");
|
||||
Assertions.assertEquals("nodeName", details.get("nodeName"));
|
||||
Assertions.assertEquals("10.1.1.1", details.get("podIp"));
|
||||
Assertions.assertEquals("192.160.10.3", details.get("hostIp"));
|
||||
Assertions.assertEquals("namespace", details.get("namespace"));
|
||||
Assertions.assertEquals("pod", details.get("podName"));
|
||||
Assertions.assertEquals("serviceAccountName", details.get("serviceAccount"));
|
||||
Assertions.assertTrue((Boolean) details.get("inside"));
|
||||
PodStatus status = new PodStatus();
|
||||
status.setPodIP("10.1.1.1");
|
||||
status.setHostIP("192.160.10.3");
|
||||
|
||||
Map<String, String> labels = (Map<String, String>) details.get("labels");
|
||||
Assertions.assertEquals("labelValue", labels.get("labelName"));
|
||||
}
|
||||
catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
PodSpec spec = new PodSpec();
|
||||
spec.setServiceAccountName("serviceAccountName");
|
||||
spec.setNodeName("nodeName");
|
||||
|
||||
return new PodBuilder().withNewMetadata().withName("pod").withNamespace("namespace")
|
||||
.withLabels(Collections.singletonMap("labelName", "labelValue")).endMetadata().withStatus(status)
|
||||
.withSpec(spec).build();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -16,16 +16,10 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.fabric8.kubernetes.api.model.Pod;
|
||||
import io.fabric8.kubernetes.api.model.PodBuilder;
|
||||
import io.fabric8.kubernetes.api.model.PodSpec;
|
||||
import io.fabric8.kubernetes.api.model.PodStatus;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@@ -49,7 +43,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "management.endpoints.web.exposure.include=info",
|
||||
"management.endpoint.info.show-details=always", "management.info.kubernetes.enabled=true" })
|
||||
public class Fabric8InsideInfoContributorTest {
|
||||
class Fabric8InsideInfoContributorTest {
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webClient;
|
||||
@@ -57,11 +51,31 @@ public class Fabric8InsideInfoContributorTest {
|
||||
@Value("${local.server.port}")
|
||||
private int port;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* "kubernetes": {
|
||||
* "nodeName": "nodeName",
|
||||
* "podIp": "10.1.1.1",
|
||||
* "hostIp": "192.160.10.3",
|
||||
* "namespace": "namespace",
|
||||
* "podName": "pod",
|
||||
* "serviceAccount": "serviceAccountName",
|
||||
* "inside": true
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
public void test() {
|
||||
void test() {
|
||||
this.webClient.get().uri("http://localhost:{port}/actuator/info", this.port).accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk().expectBody(String.class)
|
||||
.value(Fabric8InsideInfoContributorTest::validateInfo);
|
||||
.exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("kubernetes.nodeName").isEqualTo("nodeName")
|
||||
.jsonPath("kubernetes.podIp").isEqualTo("10.1.1.1")
|
||||
.jsonPath("kubernetes.hostIp").isEqualTo("192.160.10.3")
|
||||
.jsonPath("kubernetes.namespace").isEqualTo("namespace")
|
||||
.jsonPath("kubernetes.podName").isEqualTo("pod")
|
||||
.jsonPath("kubernetes.serviceAccount").isEqualTo("serviceAccountName")
|
||||
.jsonPath("kubernetes.inside").isEqualTo("true");
|
||||
|
||||
}
|
||||
|
||||
private static Pod stubPod() {
|
||||
@@ -78,41 +92,6 @@ public class Fabric8InsideInfoContributorTest {
|
||||
.withStatus(status).withSpec(spec).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* "kubernetes": {
|
||||
* "nodeName": "nodeName",
|
||||
* "podIp": "10.1.1.1",
|
||||
* "hostIp": "192.160.10.3",
|
||||
* "namespace": "namespace",
|
||||
* "podName": "pod",
|
||||
* "serviceAccount": "serviceAccountName",
|
||||
* "inside": true
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void validateInfo(String input) {
|
||||
try {
|
||||
Map<String, Object> map = new ObjectMapper().readValue(input, new TypeReference<Map<String, Object>>() {
|
||||
|
||||
});
|
||||
Map<String, Object> infoProperties = (Map<String, Object>) map.get("kubernetes");
|
||||
|
||||
Assertions.assertEquals("nodeName", infoProperties.get("nodeName"));
|
||||
Assertions.assertEquals("10.1.1.1", infoProperties.get("podIp"));
|
||||
Assertions.assertEquals("192.160.10.3", infoProperties.get("hostIp"));
|
||||
Assertions.assertEquals("namespace", infoProperties.get("namespace"));
|
||||
Assertions.assertEquals("pod", infoProperties.get("podName"));
|
||||
Assertions.assertEquals("serviceAccountName", infoProperties.get("serviceAccount"));
|
||||
Assertions.assertTrue((Boolean) infoProperties.get("inside"));
|
||||
|
||||
}
|
||||
catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class InfoContributorTestConfig {
|
||||
|
||||
|
||||
@@ -16,16 +16,10 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.fabric8.kubernetes.client.Config;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -39,7 +33,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "management.endpoint.health.show-details=always" })
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class Fabric8NotInsideHealthIndicatorTest {
|
||||
class Fabric8NotInsideHealthIndicatorTest {
|
||||
|
||||
private static KubernetesClient mockClient;
|
||||
|
||||
@@ -50,7 +44,7 @@ public class Fabric8NotInsideHealthIndicatorTest {
|
||||
private int port;
|
||||
|
||||
@BeforeAll
|
||||
public static void setUpBeforeClass() {
|
||||
static void setUpBeforeClass() {
|
||||
// Configure the kubernetes master url to point to the mock server
|
||||
System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl());
|
||||
System.setProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, "true");
|
||||
@@ -61,7 +55,7 @@ public class Fabric8NotInsideHealthIndicatorTest {
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void afterClass() {
|
||||
static void afterClass() {
|
||||
System.clearProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY);
|
||||
System.clearProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY);
|
||||
System.clearProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY);
|
||||
@@ -70,13 +64,6 @@ public class Fabric8NotInsideHealthIndicatorTest {
|
||||
System.clearProperty(Config.KUBERNETES_HTTP2_DISABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthEndpointShouldContainKubernetes() {
|
||||
this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port)
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody(String.class)
|
||||
.value(this::validateKubernetes);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* "kubernetes":{
|
||||
@@ -87,22 +74,14 @@ public class Fabric8NotInsideHealthIndicatorTest {
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void validateKubernetes(String input) {
|
||||
try {
|
||||
Map<String, Object> map = new ObjectMapper().readValue(input, new TypeReference<Map<String, Object>>() {
|
||||
@Test
|
||||
void healthEndpointShouldContainKubernetes() {
|
||||
|
||||
});
|
||||
Map<String, Object> kubernetesProperties = (Map<String, Object>) ((Map<String, Object>) map
|
||||
.get("components")).get("kubernetes");
|
||||
Assertions.assertEquals("UP", kubernetesProperties.get("status"));
|
||||
this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port)
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("components.kubernetes.status").isEqualTo("UP")
|
||||
.jsonPath("components.kubernetes.details.inside").isEqualTo("false");
|
||||
|
||||
Map<String, Object> details = (Map<String, Object>) kubernetesProperties.get("details");
|
||||
Assertions.assertFalse((Boolean) details.get("inside"));
|
||||
}
|
||||
catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,14 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -37,7 +31,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "management.endpoints.web.exposure.include=info",
|
||||
"management.endpoint.info.show-details=always", "management.info.kubernetes.enabled=true" })
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class Fabric8NotInsideInfoContributorTest {
|
||||
class Fabric8NotInsideInfoContributorTest {
|
||||
|
||||
private static KubernetesClient client;
|
||||
|
||||
@@ -47,12 +41,6 @@ public class Fabric8NotInsideInfoContributorTest {
|
||||
@Value("${local.server.port}")
|
||||
private int port;
|
||||
|
||||
@Test
|
||||
public void infoEndpointShouldContainKubernetes() {
|
||||
this.webClient.get().uri("http://localhost:{port}/actuator/info", this.port).accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk().expectBody(String.class).value(this::validateInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* "kubernetes":{
|
||||
@@ -60,18 +48,10 @@ public class Fabric8NotInsideInfoContributorTest {
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void validateInfo(String input) {
|
||||
try {
|
||||
Map<String, Object> map = new ObjectMapper().readValue(input, new TypeReference<Map<String, Object>>() {
|
||||
|
||||
});
|
||||
Map<String, Object> kubernetesProperties = (Map<String, Object>) map.get("kubernetes");
|
||||
Assertions.assertFalse((Boolean) kubernetesProperties.get("inside"));
|
||||
}
|
||||
catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@Test
|
||||
void infoEndpointShouldContainKubernetes() {
|
||||
this.webClient.get().uri("http://localhost:{port}/actuator/info", this.port).accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk().expectBody().jsonPath("kubernetes.inside").isEqualTo("false");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.cloud.kubernetes.commons.EnvReader;
|
||||
import org.springframework.cloud.kubernetes.fabric8.Fabric8PodUtils;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class Fabric8PodUtilsTest {
|
||||
class Fabric8PodUtilsTest {
|
||||
|
||||
private static final String KUBERNETES_SERVICE_HOST = Fabric8PodUtils.KUBERNETES_SERVICE_HOST;
|
||||
|
||||
@@ -73,26 +73,26 @@ public class Fabric8PodUtilsTest {
|
||||
private MockedStatic<Paths> paths;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
void before() {
|
||||
envReader = Mockito.mockStatic(EnvReader.class);
|
||||
paths = Mockito.mockStatic(Paths.class);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void after() {
|
||||
void after() {
|
||||
envReader.close();
|
||||
paths.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorThrowsIllegalArgumentExceptionWhenKubeClientNull() {
|
||||
void constructorThrowsIllegalArgumentExceptionWhenKubeClientNull() {
|
||||
// expect an IllegalArgumentException if KubernetesClient argument is
|
||||
// null
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> new Fabric8PodUtils(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceHostNotPresent() {
|
||||
void serviceHostNotPresent() {
|
||||
mockHost(null);
|
||||
Fabric8PodUtils util = new Fabric8PodUtils(client);
|
||||
Supplier<Pod> sup = util.currentPod();
|
||||
@@ -101,7 +101,7 @@ public class Fabric8PodUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hostnameNotPresent() {
|
||||
void hostnameNotPresent() {
|
||||
mockHost(HOST);
|
||||
mockHostname(null);
|
||||
Fabric8PodUtils util = new Fabric8PodUtils(client);
|
||||
@@ -111,7 +111,7 @@ public class Fabric8PodUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceAccountPathNotPresent() {
|
||||
void serviceAccountPathNotPresent() {
|
||||
mockTokenPath(false);
|
||||
mockHostname(HOST);
|
||||
mockHostname(POD_HOSTNAME);
|
||||
@@ -122,7 +122,7 @@ public class Fabric8PodUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceAccountCertPathNotPresent() {
|
||||
void serviceAccountCertPathNotPresent() {
|
||||
mockTokenPath(true);
|
||||
mockCertPath(false);
|
||||
mockHostname(HOST);
|
||||
@@ -134,7 +134,7 @@ public class Fabric8PodUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allPresent() {
|
||||
void allPresent() {
|
||||
mockTokenPath(true);
|
||||
mockCertPath(true);
|
||||
mockHost(HOST);
|
||||
|
||||
@@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@SpringBootTest(classes = App.class, properties = { "spring.cloud.kubernetes.client.userAgent=non-default",
|
||||
"spring.main.cloud-platform=KUBERNETES" })
|
||||
class Fabric8UserAgentPropertiesConfiguration {
|
||||
class Fabric8UserAgentPropertiesConfigurationTests {
|
||||
|
||||
@Autowired
|
||||
private KubernetesClient client;
|
||||
@@ -21,23 +21,18 @@ import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.kubernetes.fabric8.config.example.App;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "management.endpoint.health.show-details=always" })
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class HealthIndicatorTest {
|
||||
class HealthIndicatorTest {
|
||||
|
||||
private static KubernetesClient mockClient;
|
||||
|
||||
@@ -48,7 +43,7 @@ public class HealthIndicatorTest {
|
||||
private WebTestClient webClient;
|
||||
|
||||
@BeforeAll
|
||||
public static void setUpBeforeClass() {
|
||||
static void setUpBeforeClass() {
|
||||
|
||||
// Configure the kubernetes master url to point to the mock server
|
||||
System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, mockClient.getConfiguration().getMasterUrl());
|
||||
@@ -60,10 +55,10 @@ public class HealthIndicatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthEndpointShouldContainKubernetes() {
|
||||
void healthEndpointShouldContainKubernetes() {
|
||||
this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port)
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody(String.class)
|
||||
.value(containsString("kubernetes"));
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("components.kubernetes").exists();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,9 +27,6 @@ import org.springframework.cloud.kubernetes.fabric8.config.example.App;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
/**
|
||||
* @author wind57
|
||||
*/
|
||||
@@ -51,8 +48,8 @@ class DisabledHealthTest {
|
||||
@Test
|
||||
void healthEndpointShouldContainKubernetes() {
|
||||
this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port)
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody(String.class)
|
||||
.value(not(containsString("kubernetes")));
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("components.kubernetes").doesNotExist();
|
||||
|
||||
Assertions.assertNull(registry.getContributor("kubernetes"),
|
||||
"reactive kubernetes contributor must NOT be present when 'management.health.kubernetes.enabled=false'");
|
||||
|
||||
@@ -27,8 +27,6 @@ import org.springframework.cloud.kubernetes.fabric8.config.example.App;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
/**
|
||||
* @author wind57
|
||||
*/
|
||||
@@ -49,9 +47,10 @@ class EnabledHealthTest {
|
||||
|
||||
@Test
|
||||
void healthEndpointShouldContainKubernetes() {
|
||||
|
||||
this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port)
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody(String.class)
|
||||
.value(containsString("kubernetes"));
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("components.kubernetes").exists();
|
||||
|
||||
Assertions.assertNotNull(registry.getContributor("kubernetes"),
|
||||
"reactive kubernetes contributor must be present when 'management.health.kubernetes.enabled=true'");
|
||||
|
||||
Reference in New Issue
Block a user