Drop more overlapping tests (3) (#1846)
* easier to read code Signed-off-by: wind57 <eugen.rabii@gmail.com> * drop tests Signed-off-by: wind57 <eugen.rabii@gmail.com> * drop test Signed-off-by: wind57 <eugen.rabii@gmail.com> * drop test Signed-off-by: wind57 <eugen.rabii@gmail.com> * inline a test Signed-off-by: wind57 <eugen.rabii@gmail.com> * rename a test Signed-off-by: wind57 <eugen.rabii@gmail.com> * re-trigger Signed-off-by: wind57 <eugen.rabii@gmail.com> --------- Signed-off-by: wind57 <eugen.rabii@gmail.com>
This commit is contained in:
@@ -20,13 +20,16 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.web.server.LocalManagementPort;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static org.springframework.cloud.kubernetes.fabric8.client.discovery.TestAssertions.assertBlockingConfiguration;
|
||||
import static org.springframework.cloud.kubernetes.fabric8.client.discovery.TestAssertions.assertPodMetadata;
|
||||
|
||||
/**
|
||||
* @author wind57
|
||||
@@ -39,6 +42,9 @@ class Fabric8DiscoveryBlockingIT extends Fabric8DiscoveryBase {
|
||||
@LocalManagementPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private DiscoveryClient discoveryClient;
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
Images.loadBusybox(K3S);
|
||||
@@ -51,8 +57,20 @@ class Fabric8DiscoveryBlockingIT extends Fabric8DiscoveryBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void test(CapturedOutput output) {
|
||||
void test(CapturedOutput output) throws Exception {
|
||||
|
||||
String[] busyboxPods = K3S.execInContainer("sh", "-c", "kubectl get pods -l app=busybox -o=name --no-headers")
|
||||
.getStdout()
|
||||
.split("\n");
|
||||
|
||||
String podOne = busyboxPods[0].split("/")[1];
|
||||
String podTwo = busyboxPods[1].split("/")[1];
|
||||
|
||||
K3S.execInContainer("sh", "-c", "kubectl label pods " + podOne + " my-label=my-value");
|
||||
K3S.execInContainer("sh", "-c", "kubectl annotate pods " + podTwo + " my-annotation=my-value");
|
||||
|
||||
assertBlockingConfiguration(output, port);
|
||||
assertPodMetadata(discoveryClient);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2024 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.fabric8.client.discovery;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.web.server.LocalManagementPort;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static org.springframework.cloud.kubernetes.fabric8.client.discovery.TestAssertions.testDefaultConfiguration;
|
||||
|
||||
/**
|
||||
* @author wind57
|
||||
*/
|
||||
@TestPropertySource(properties = { "logging.level.org.springframework.cloud.client.discovery.health.reactive=DEBUG",
|
||||
"logging.level.org.springframework.cloud.client.discovery.health=DEBUG",
|
||||
"logging.level.org.springframework.cloud.kubernetes.fabric8.discovery.reactive=DEBUG",
|
||||
"logging.level.org.springframework.cloud.kubernetes.fabric8.discovery=DEBUG",
|
||||
"logging.level.org.springframework.cloud.kubernetes.commons.discovery=DEBUG" })
|
||||
class Fabric8DiscoveryDefaultConfigurationIT extends Fabric8DiscoveryBase {
|
||||
|
||||
@LocalManagementPort
|
||||
private int port;
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
Images.loadBusybox(K3S);
|
||||
util.busybox(NAMESPACE, Phase.CREATE);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void afterEach() {
|
||||
util.busybox(NAMESPACE, Phase.DELETE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void test(CapturedOutput output) {
|
||||
testDefaultConfiguration(output, port);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,7 +35,7 @@ import static org.springframework.cloud.kubernetes.fabric8.client.discovery.Test
|
||||
"spring.cloud.kubernetes.discovery.namespaces[1]=b-uat",
|
||||
"spring.cloud.kubernetes.discovery.filter=#root.metadata.namespace matches '^.*uat$'",
|
||||
"logging.level.org.springframework.cloud.kubernetes.fabric8.discovery=DEBUG" })
|
||||
class Fabric8DiscoveryFilterMatchTwoNamespacesIT extends Fabric8DiscoveryBase {
|
||||
class Fabric8DiscoveryFilterIT extends Fabric8DiscoveryBase {
|
||||
|
||||
private static final String NAMESPACE_A_UAT = "a-uat";
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2024 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.fabric8.client.discovery;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static org.springframework.cloud.kubernetes.fabric8.client.discovery.TestAssertions.filterMatchesOneNamespaceViaThePredicate;
|
||||
|
||||
/**
|
||||
* @author wind57
|
||||
*/
|
||||
@TestPropertySource(properties = { "spring.cloud.kubernetes.discovery.namespaces[0]=a-uat",
|
||||
"spring.cloud.kubernetes.discovery.namespaces[1]=b-uat",
|
||||
"spring.cloud.kubernetes.discovery.filter=#root.metadata.namespace matches 'a-uat$'",
|
||||
"logging.level.org.springframework.cloud.kubernetes.fabric8.discovery=DEBUG" })
|
||||
class Fabric8DiscoveryFilterMatchOneNamespaceIT extends Fabric8DiscoveryBase {
|
||||
|
||||
private static final String NAMESPACE_A_UAT = "a-uat";
|
||||
|
||||
private static final String NAMESPACE_B_UAT = "b-uat";
|
||||
|
||||
@Autowired
|
||||
private DiscoveryClient discoveryClient;
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
Images.loadWiremock(K3S);
|
||||
|
||||
util.createNamespace(NAMESPACE_A_UAT);
|
||||
util.createNamespace(NAMESPACE_B_UAT);
|
||||
|
||||
util.wiremock(NAMESPACE_A_UAT, Phase.CREATE);
|
||||
util.wiremock(NAMESPACE_B_UAT, Phase.CREATE);
|
||||
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void afterEach() {
|
||||
|
||||
util.wiremock(NAMESPACE_A_UAT, Phase.DELETE);
|
||||
util.wiremock(NAMESPACE_B_UAT, Phase.DELETE);
|
||||
|
||||
util.deleteNamespace(NAMESPACE_A_UAT);
|
||||
util.deleteNamespace(NAMESPACE_B_UAT);
|
||||
}
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
filterMatchesOneNamespaceViaThePredicate(discoveryClient);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2024 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.fabric8.client.discovery;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
|
||||
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
|
||||
|
||||
import static org.springframework.cloud.kubernetes.fabric8.client.discovery.TestAssertions.assertPodMetadata;
|
||||
|
||||
/**
|
||||
* @author wind57
|
||||
*/
|
||||
class Fabric8DiscoveryPodMetadataIT extends Fabric8DiscoveryBase {
|
||||
|
||||
@Autowired
|
||||
private DiscoveryClient discoveryClient;
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
Images.loadBusybox(K3S);
|
||||
util.busybox(NAMESPACE, Phase.CREATE);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void afterEach() {
|
||||
util.busybox(NAMESPACE, Phase.DELETE);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* - there is a 'busybox-service' service deployed with two pods
|
||||
* - find each of the pod, add annotation to one, and labels to another
|
||||
* - call DiscoveryClient::getInstances with this serviceId and assert fields returned
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
void test() throws Exception {
|
||||
String[] busyboxPods = K3S.execInContainer("sh", "-c", "kubectl get pods -l app=busybox -o=name --no-headers")
|
||||
.getStdout()
|
||||
.split("\n");
|
||||
|
||||
String podOne = busyboxPods[0].split("/")[1];
|
||||
String podTwo = busyboxPods[1].split("/")[1];
|
||||
|
||||
K3S.execInContainer("sh", "-c", "kubectl label pods " + podOne + " my-label=my-value");
|
||||
K3S.execInContainer("sh", "-c", "kubectl annotate pods " + podTwo + " my-annotation=my-value");
|
||||
|
||||
assertPodMetadata(discoveryClient);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -279,39 +279,6 @@ final class TestAssertions {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* - service "wiremock" is present in namespace "a-uat"
|
||||
* - service "wiremock" is present in namespace "b-uat"
|
||||
*
|
||||
* - we search with a predicate : "#root.metadata.namespace matches 'a-uat$'"
|
||||
*
|
||||
* As such, only service from 'a-uat' namespace matches.
|
||||
* </pre>
|
||||
*/
|
||||
static void filterMatchesOneNamespaceViaThePredicate(DiscoveryClient discoveryClient) {
|
||||
|
||||
List<String> services = discoveryClient.getServices();
|
||||
assertThat(services.size()).isEqualTo(1);
|
||||
assertThat(services).contains("service-wiremock");
|
||||
|
||||
List<DefaultKubernetesServiceInstance> serviceInstances = discoveryClient.getInstances("service-wiremock")
|
||||
.stream()
|
||||
.map(x -> (DefaultKubernetesServiceInstance) x)
|
||||
.toList();
|
||||
|
||||
assertThat(serviceInstances.size()).isEqualTo(1);
|
||||
|
||||
DefaultKubernetesServiceInstance first = serviceInstances.get(0);
|
||||
assertThat(first.getServiceId()).isEqualTo("service-wiremock");
|
||||
assertThat(first.getInstanceId()).isNotNull();
|
||||
assertThat(first.getPort()).isEqualTo(8080);
|
||||
assertThat(first.getNamespace()).isEqualTo("a-uat");
|
||||
assertThat(first.getMetadata()).isEqualTo(
|
||||
Map.of("app", "service-wiremock", "port.http", "8080", "k8s_namespace", "a-uat", "type", "ClusterIP"));
|
||||
|
||||
}
|
||||
|
||||
private static void waitForLogStatement(CapturedOutput output, String message) {
|
||||
await().pollInterval(Duration.ofSeconds(1))
|
||||
.atMost(Duration.ofSeconds(30))
|
||||
|
||||
@@ -11,4 +11,3 @@ spring:
|
||||
strategy: refresh
|
||||
mode: polling
|
||||
period: 5s
|
||||
|
||||
|
||||
Reference in New Issue
Block a user