Copilot commented on code in PR #8167:
URL: https://github.com/apache/incubator-seata/pull/8167#discussion_r3601362905
##########
common/src/test/java/org/apache/seata/common/util/NetUtilTest.java:
##########
@@ -227,6 +227,25 @@ public void testIsValidIp() {
.hasMessageContaining("UnknownHostException");
}
+ @Test
+ public void testConvertIpIfNecessary() {
+ // an ip literal is returned as is
+
assertThat(NetUtil.convertIpIfNecessary("127.0.0.1")).isEqualTo("127.0.0.1");
+
assertThat(NetUtil.convertIpIfNecessary("8.210.212.91")).isEqualTo("8.210.212.91");
+
assertThat(NetUtil.convertIpIfNecessary("2000:0000:0000:0000:0001:2345:6789:abcd"))
+ .isEqualTo("2000:0000:0000:0000:0001:2345:6789:abcd");
+
+ // a host name is resolved to its ip address
+
assertThat(NetUtil.convertIpIfNecessary("localhost")).isIn("127.0.0.1",
"0:0:0:0:0:0:0:1");
Review Comment:
`InetAddress#getHostAddress()` may return the IPv6 loopback as either
`0:0:0:0:0:0:0:1` or the compressed form `::1` depending on JDK/OS. The current
assertion can be flaky on environments that return `::1`.
##########
common/src/test/java/org/apache/seata/common/util/NetUtilTest.java:
##########
@@ -227,6 +227,25 @@ public void testIsValidIp() {
.hasMessageContaining("UnknownHostException");
}
+ @Test
+ public void testConvertIpIfNecessary() {
+ // an ip literal is returned as is
+
assertThat(NetUtil.convertIpIfNecessary("127.0.0.1")).isEqualTo("127.0.0.1");
+
assertThat(NetUtil.convertIpIfNecessary("8.210.212.91")).isEqualTo("8.210.212.91");
+
assertThat(NetUtil.convertIpIfNecessary("2000:0000:0000:0000:0001:2345:6789:abcd"))
+ .isEqualTo("2000:0000:0000:0000:0001:2345:6789:abcd");
+
+ // a host name is resolved to its ip address
+
assertThat(NetUtil.convertIpIfNecessary("localhost")).isIn("127.0.0.1",
"0:0:0:0:0:0:0:1");
+
+ // a reserved name from RFC 2606, so it cannot be resolved by a dns
search domain
+ assertThatThrownBy(() -> {
+ NetUtil.convertIpIfNecessary("unresolvable.invalid");
+ })
Review Comment:
`unresolvable.invalid` can still be affected by DNS search domains (e.g.
resolving `unresolvable.invalid.<searchDomain>`). Adding a trailing dot forces
an absolute FQDN and makes the test more robust.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]