From cbde3a12fc93b35388796c153b0f54b628f0cdc6 Mon Sep 17 00:00:00 2001 From: Haotian Zhang <928016560@qq.com> Date: Mon, 23 Mar 2026 15:10:01 +0800 Subject: [PATCH] fix: replace hardcoded IP 10.0.0.1 with 127.0.0.1 in tests CI hardcoded IP detection rejects non-loopback IPs. Use 127.0.0.1 with different ports to distinguish addresses in test cases. Co-Authored-By: Claude Opus 4.6 Signed-off-by: Haotian Zhang <928016560@qq.com> --- .../config/ConfigurationModifierTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/ConfigurationModifierTest.java b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/ConfigurationModifierTest.java index fc9278bd6..97769656b 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/ConfigurationModifierTest.java +++ b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/ConfigurationModifierTest.java @@ -498,7 +498,7 @@ class ConfigurationModifierTest { when(polarisContextProperties.getEnabled()).thenReturn(true); when(polarisConfigProperties.isEnabled()).thenReturn(true); when(polarisConfigProperties.getDataSource()).thenReturn("polaris"); - when(polarisConfigProperties.getAddress()).thenReturn("grpc://10.0.0.1:8093"); + when(polarisConfigProperties.getAddress()).thenReturn("grpc://127.0.0.1:9093"); when(polarisConfigProperties.isCheckAddress()).thenReturn(false); when(polarisConfigProperties.isEmptyProtectionEnabled()).thenReturn(true); when(polarisConfigProperties.getEmptyProtectionExpiredInterval()).thenReturn(604800000L); @@ -507,11 +507,11 @@ class ConfigurationModifierTest { when(polarisContextProperties.getAddressLbPolicy()).thenReturn("roundRobin"); when(polarisContextProperties.getServerSwitchInterval()).thenReturn(600000L); - List parsedConfigAddresses = Collections.singletonList("10.0.0.1:8093"); + List parsedConfigAddresses = Collections.singletonList("127.0.0.1:9093"); try (MockedStatic mockedAddressUtils = Mockito.mockStatic(AddressUtils.class); MockedStatic mockedTsf = Mockito.mockStatic(TsfContextUtils.class)) { - mockedAddressUtils.when(() -> AddressUtils.parseAddressList("grpc://10.0.0.1:8093")) + mockedAddressUtils.when(() -> AddressUtils.parseAddressList("grpc://127.0.0.1:9093")) .thenReturn(parsedConfigAddresses); mockedTsf.when(TsfContextUtils::isOnlyTsfConsulEnabled).thenReturn(false); @@ -520,7 +520,7 @@ class ConfigurationModifierTest { // Assert ServerConnectorConfigImpl reportConnector = configuration.getGlobal().getServerConnector(); - verify(reportConnector).setAddresses(Collections.singletonList("10.0.0.1:8091")); + verify(reportConnector).setAddresses(Collections.singletonList("127.0.0.1:8091")); } } @@ -790,16 +790,16 @@ class ConfigurationModifierTest { try (MockedStatic mockedAddressUtils = Mockito.mockStatic(AddressUtils.class)) { mockedAddressUtils.when(() -> AddressUtils.parseAddressList(anyString())) - .thenReturn(Arrays.asList("127.0.0.1:8091", "10.0.0.1:8091")); + .thenReturn(Arrays.asList("127.0.0.1:8091", "127.0.0.1:9091")); // Act - List result = invokeResolveConfigAddressFromPolarisAddress("grpc://127.0.0.1:8091,grpc://10.0.0.1:8091"); + List result = invokeResolveConfigAddressFromPolarisAddress("grpc://127.0.0.1:8091,grpc://127.0.0.1:9091"); // Assert assertThat(result).isNotNull(); assertThat(result).hasSize(2); assertThat(result.get(0)).isEqualTo("127.0.0.1:8093"); - assertThat(result.get(1)).isEqualTo("10.0.0.1:8093"); + assertThat(result.get(1)).isEqualTo("127.0.0.1:8093"); } } @@ -839,16 +839,16 @@ class ConfigurationModifierTest { try (MockedStatic mockedAddressUtils = Mockito.mockStatic(AddressUtils.class)) { mockedAddressUtils.when(() -> AddressUtils.parseAddressList(anyString())) - .thenReturn(Arrays.asList("127.0.0.1:8091", " ", "10.0.0.1:8091")); + .thenReturn(Arrays.asList("127.0.0.1:8091", " ", "127.0.0.1:9091")); // Act - List result = invokeResolveConfigAddressFromPolarisAddress("grpc://127.0.0.1:8091, ,grpc://10.0.0.1:8091"); + List result = invokeResolveConfigAddressFromPolarisAddress("grpc://127.0.0.1:8091, ,grpc://127.0.0.1:9091"); // Assert assertThat(result).isNotNull(); assertThat(result).hasSize(2); assertThat(result.get(0)).isEqualTo("127.0.0.1:8093"); - assertThat(result.get(1)).isEqualTo("10.0.0.1:8093"); + assertThat(result.get(1)).isEqualTo("127.0.0.1:8093"); } }