@@ -19,6 +19,7 @@
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-kubernetes</artifactId>
|
||||
|
||||
@@ -19,9 +19,9 @@ package org.springframework.cloud.kubernetes;
|
||||
import io.fabric8.kubernetes.client.Config;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import io.fabric8.kubernetes.server.mock.KubernetesServer;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -42,14 +42,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
"spring.cloud.kubernetes.client.proxy-password=myproxypassword" })
|
||||
public class Fabric8AutoConfigurationTests {
|
||||
|
||||
@ClassRule
|
||||
public static KubernetesServer server = new KubernetesServer();
|
||||
|
||||
@Autowired
|
||||
ConfigurableApplicationContext context;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setUpBeforeClass() {
|
||||
server.before();
|
||||
KubernetesClient mockClient = server.getClient();
|
||||
|
||||
// Configure the kubernetes master url to point to the mock server
|
||||
@@ -61,6 +61,17 @@ public class Fabric8AutoConfigurationTests {
|
||||
System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true");
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void afterClass() {
|
||||
server.after();
|
||||
System.clearProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY);
|
||||
System.clearProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY);
|
||||
System.clearProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY);
|
||||
System.clearProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY);
|
||||
System.clearProperty(Config.KUBERNETES_NAMESPACE_SYSTEM_PROPERTY);
|
||||
System.clearProperty(Config.KUBERNETES_HTTP2_DISABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beansAreCreated() {
|
||||
assertThat(context.getBeanNamesForType(Config.class)).hasSize(1);
|
||||
|
||||
@@ -47,7 +47,6 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*
|
||||
* test proper fields being set in /actuator/info
|
||||
*/
|
||||
|
||||
@Import(Fabric8InsideInfoContributorTest.InfoContributorTestConfig.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "management.endpoint.health.show-details=always", "management.info.kubernetes.enabled=false" })
|
||||
@@ -82,7 +81,6 @@ public class Fabric8InsideInfoContributorTest {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* {
|
||||
* "kubernetes": {
|
||||
* "nodeName": "nodeName",
|
||||
* "podIp": "10.1.1.1",
|
||||
@@ -92,7 +90,6 @@ public class Fabric8InsideInfoContributorTest {
|
||||
* "serviceAccount": "serviceAccountName",
|
||||
* "inside": true
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -65,6 +65,12 @@ public class Fabric8NotInsideHealthIndicatorTest {
|
||||
@AfterAll
|
||||
public static void afterClass() {
|
||||
server.after();
|
||||
System.clearProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY);
|
||||
System.clearProperty(Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY);
|
||||
System.clearProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY);
|
||||
System.clearProperty(Config.KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY);
|
||||
System.clearProperty(Config.KUBERNETES_NAMESPACE_SYSTEM_PROPERTY);
|
||||
System.clearProperty(Config.KUBERNETES_HTTP2_DISABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,7 +81,14 @@ public class Fabric8NotInsideHealthIndicatorTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* kubernetes={ status=UP, details={ inside=false } }
|
||||
* <pre>
|
||||
* "kubernetes":{
|
||||
* "status":"UP",
|
||||
* "details":{
|
||||
* "inside":"false"
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void validateKubernetes(String input) {
|
||||
|
||||
@@ -21,7 +21,6 @@ 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.server.mock.KubernetesServer;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@@ -40,8 +39,6 @@ public class Fabric8NotInsideInfoContributorTest {
|
||||
|
||||
public static KubernetesServer server = new KubernetesServer();
|
||||
|
||||
private static KubernetesClient mockClient;
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webClient;
|
||||
|
||||
@@ -51,7 +48,6 @@ public class Fabric8NotInsideInfoContributorTest {
|
||||
@BeforeAll
|
||||
public static void setUpBeforeClass() {
|
||||
server.before();
|
||||
mockClient = server.getClient();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
@@ -65,7 +61,13 @@ public class Fabric8NotInsideInfoContributorTest {
|
||||
.exchange().expectStatus().isOk().expectBody(String.class).value(this::validateInfo);
|
||||
}
|
||||
|
||||
// {"kubernetes":{"inside":false}}
|
||||
/**
|
||||
* <pre>
|
||||
* "kubernetes":{
|
||||
* "inside":false
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void validateInfo(String input) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user