Nested split (#962)
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.client;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.actuate.health.ReactiveHealthContributorRegistry;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.kubernetes.client.example.App;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
/**
|
||||
* @author wind57
|
||||
*/
|
||||
@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.endpoints.web.exposure.include=health" })
|
||||
class ActuatorDisabledHealthTest {
|
||||
|
||||
@Autowired
|
||||
private ReactiveHealthContributorRegistry registry;
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webClient;
|
||||
|
||||
@Value("${local.server.port}")
|
||||
private int port;
|
||||
|
||||
@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.not(Matchers.containsString("kubernetes")));
|
||||
|
||||
Assertions.assertNull(registry.getContributor("kubernetes"),
|
||||
"reactive kubernetes contributor must NOT be present when 'management.health.kubernetes.enabled=false'");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.client;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.actuate.health.ReactiveHealthContributorRegistry;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.kubernetes.client.example.App;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "management.health.kubernetes.enabled=true", "management.endpoint.health.show-details=always",
|
||||
"management.endpoint.health.show-components=always", "management.endpoints.web.exposure.include=health",
|
||||
"spring.main.cloud-platform=KUBERNETES" })
|
||||
class ActuatorEnabledHealthTest {
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webClient;
|
||||
|
||||
@Autowired
|
||||
private ReactiveHealthContributorRegistry registry;
|
||||
|
||||
@Value("${local.server.port}")
|
||||
private int port;
|
||||
|
||||
@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"));
|
||||
|
||||
Assertions.assertNotNull(registry.getContributor("kubernetes"),
|
||||
"reactive kubernetes contributor must be present when 'management.health.kubernetes.enabled=true'");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.client.default_api;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
|
||||
import io.kubernetes.client.openapi.ApiClient;
|
||||
import okhttp3.Request;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Robert McNees
|
||||
*
|
||||
* This tests that the apiClient created in KubernetesClientAutoConfiguration will not set
|
||||
* itself as the default apiClient. This is to avoid overwriting the user's
|
||||
* defaultApiClient if they include this project.
|
||||
*
|
||||
* kubernetes informer is disabled because KubernetesInformerAutoConfiguration creates a
|
||||
* defaultApiClient that will be autowired instead of the ApiClient created in
|
||||
* KubernetesClientAutoConfiguration
|
||||
*/
|
||||
@SpringBootTest(classes = App.class,
|
||||
properties = { "kubernetes.informer.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
|
||||
class ApiClientUserAgentDefaultHeader {
|
||||
|
||||
@Autowired
|
||||
private ApiClient apiClient;
|
||||
|
||||
@Test
|
||||
void testApiClientUserAgentDefaultHeader() throws MalformedURLException {
|
||||
assertThat(apiClient).isNotNull();
|
||||
Request.Builder builder = new Request.Builder();
|
||||
apiClient.processHeaderParams(Collections.emptyMap(), builder);
|
||||
assertThat(builder.url(new URL("http://example.com")).build().headers().get("User-Agent"))
|
||||
.isEqualTo("Spring-Cloud-Kubernetes-Application");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.client.default_api;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
|
||||
import io.kubernetes.client.openapi.ApiClient;
|
||||
import okhttp3.Request;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Robert McNees
|
||||
*
|
||||
* This tests that the apiClient created in KubernetesClientAutoConfiguration will not set
|
||||
* itself as the default apiClient. This is to avoid overwriting the user's
|
||||
* defaultApiClient if they include this project.
|
||||
*
|
||||
* kubernetes informer is disabled because KubernetesInformerAutoConfiguration creates a
|
||||
* defaultApiClient that will be autowired instead of the ApiClient created in
|
||||
* KubernetesClientAutoConfiguration
|
||||
*/
|
||||
@SpringBootTest(classes = App.class, properties = { "kubernetes.informer.enabled=false",
|
||||
"spring.cloud.kubernetes.client.userAgent=non-default", "spring.main.cloud-platform=KUBERNETES" })
|
||||
class ApiClientUserAgentNonDefaultHeader {
|
||||
|
||||
@Autowired
|
||||
private ApiClient apiClient;
|
||||
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@Test
|
||||
void testApiClientUserAgentDefaultHeader() throws MalformedURLException {
|
||||
assertThat(apiClient).isNotNull();
|
||||
Request.Builder builder = new Request.Builder();
|
||||
apiClient.processHeaderParams(Collections.emptyMap(), builder);
|
||||
assertThat(builder.url(new URL("http://example.com")).build().headers().get("User-Agent"))
|
||||
.isEqualTo("non-default");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.client.default_api;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
class App {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.client.default_api;
|
||||
|
||||
import io.kubernetes.client.openapi.ApiClient;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Robert McNees
|
||||
*
|
||||
* This tests that the apiClient created in KubernetesClientAutoConfiguration will not set
|
||||
* itself as the default apiClient. This is to avoid overwriting the user's
|
||||
* defaultApiClient if they include this project.
|
||||
*
|
||||
* kubernetes informer is disabled because KubernetesInformerAutoConfiguration creates a
|
||||
* defaultApiClient that will be autowired instead of the ApiClient created in
|
||||
* KubernetesClientAutoConfiguration
|
||||
*/
|
||||
@SpringBootTest(classes = App.class,
|
||||
properties = { "kubernetes.informer.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
|
||||
class DefaultApiClientNotSameAsApiClient {
|
||||
|
||||
@Autowired
|
||||
private ApiClient apiClient;
|
||||
|
||||
@Test
|
||||
void testCreatedApiClientIsNotDefault() {
|
||||
assertThat(apiClient).isNotNull();
|
||||
|
||||
ApiClient defaultApiClient = io.kubernetes.client.openapi.Configuration.getDefaultApiClient();
|
||||
assertThat(defaultApiClient).isNotNull();
|
||||
|
||||
assertThat(defaultApiClient).isNotSameAs(apiClient);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.client.default_api;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
|
||||
import io.kubernetes.client.openapi.ApiClient;
|
||||
import okhttp3.Request;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Robert McNees
|
||||
*
|
||||
* This tests that the apiClient created in KubernetesClientAutoConfiguration will not set
|
||||
* itself as the default apiClient. This is to avoid overwriting the user's
|
||||
* defaultApiClient if they include this project.
|
||||
*
|
||||
* kubernetes informer is disabled because KubernetesInformerAutoConfiguration creates a
|
||||
* defaultApiClient that will be autowired instead of the ApiClient created in
|
||||
* KubernetesClientAutoConfiguration
|
||||
*/
|
||||
|
||||
class KubernetesClientDefaultApiClientTests {
|
||||
|
||||
private static final String DISABLE_INFORMER = "kubernetes.informer.enabled=false";
|
||||
|
||||
private static final String USER_AGENT = "spring.cloud.kubernetes.client.userAgent=non-default";
|
||||
|
||||
private static final String ENABLED_K8S = "spring.main.cloud-platform=KUBERNETES";
|
||||
|
||||
@SpringBootTest(classes = KubernetesClientDefaultApiClientTests.App.class,
|
||||
properties = { DISABLE_INFORMER, ENABLED_K8S })
|
||||
@Nested
|
||||
class DefaultApiClientNotSameAsApiClient {
|
||||
|
||||
@Autowired
|
||||
private ApiClient apiClient;
|
||||
|
||||
@Autowired
|
||||
ConfigurableApplicationContext context;
|
||||
|
||||
@Test
|
||||
void testCreatedApiClientIsNotDefault() {
|
||||
assertThat(apiClient).isNotNull();
|
||||
|
||||
ApiClient defaultApiClient = io.kubernetes.client.openapi.Configuration.getDefaultApiClient();
|
||||
assertThat(defaultApiClient).isNotNull();
|
||||
|
||||
assertThat(defaultApiClient).isNotSameAs(apiClient);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SpringBootTest(classes = KubernetesClientDefaultApiClientTests.App.class,
|
||||
properties = { DISABLE_INFORMER, ENABLED_K8S })
|
||||
@Nested
|
||||
class ApiClientUserAgentDefaultHeader {
|
||||
|
||||
@Autowired
|
||||
private ApiClient apiClient;
|
||||
|
||||
@Autowired
|
||||
ConfigurableApplicationContext context;
|
||||
|
||||
@Test
|
||||
void testApiClientUserAgentDefaultHeader() throws MalformedURLException {
|
||||
assertThat(apiClient).isNotNull();
|
||||
Request.Builder builder = new Request.Builder();
|
||||
apiClient.processHeaderParams(Collections.emptyMap(), builder);
|
||||
assertThat(builder.url(new URL("http://example.com")).build().headers().get("User-Agent"))
|
||||
.isEqualTo("Spring-Cloud-Kubernetes-Application");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SpringBootTest(classes = KubernetesClientDefaultApiClientTests.App.class,
|
||||
properties = { DISABLE_INFORMER, USER_AGENT, ENABLED_K8S })
|
||||
@Nested
|
||||
class ApiClientUserAgentNonDefaultHeader {
|
||||
|
||||
@Autowired
|
||||
private ApiClient apiClient;
|
||||
|
||||
@Autowired
|
||||
ConfigurableApplicationContext context;
|
||||
|
||||
@Test
|
||||
void testApiClientUserAgentDefaultHeader() throws MalformedURLException {
|
||||
assertThat(apiClient).isNotNull();
|
||||
Request.Builder builder = new Request.Builder();
|
||||
apiClient.processHeaderParams(Collections.emptyMap(), builder);
|
||||
assertThat(builder.url(new URL("http://example.com")).build().headers().get("User-Agent"))
|
||||
.isEqualTo("non-default");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SpringBootApplication
|
||||
static class App {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user