difin commented on code in PR #5729: URL: https://github.com/apache/hive/pull/5729#discussion_r2031344688
########## common/src/test/org/apache/hive/common/IPStackUtilsTest.java: ########## @@ -180,4 +180,72 @@ void testWildcardWhenHostnameIsProvided() { String result = IPStackUtils.adaptWildcardAddress("example.com"); assertEquals("example.com", result); } + + // Test cases for splitHostPort method + + @Test + void testSplitHostPortWithIPv4() { + IPStackUtils.HostPort result = IPStackUtils.splitHostPort("192.168.1.1:8080"); + assertEquals("192.168.1.1", result.getHostname()); + assertEquals(8080, result.getPort()); + } + + @Test + void testSplitHostPortWithValidIPv6WithSquaredBrackets() { + IPStackUtils.HostPort result = IPStackUtils.splitHostPort("[2001:0db8::1]:8080"); + assertEquals("2001:0db8::1", result.getHostname()); + assertEquals(8080, result.getPort()); + } + + @Test + void testSplitHostPortWithValidIPv6WithoutSquaredBrackets() { + IPStackUtils.HostPort result = IPStackUtils.splitHostPort("2001:0db8::1:8080"); + assertEquals("2001:0db8::1", result.getHostname()); + assertEquals(8080, result.getPort()); + } + + @Test + void testSplitHostPortWithHostname() { + IPStackUtils.HostPort result = IPStackUtils.splitHostPort("example.com:80"); + assertEquals("example.com", result.getHostname()); + assertEquals(80, result.getPort()); + } + + @Test + void testSplitHostPortWithInvalidPort() { + assertThrows(IllegalArgumentException.class, () -> IPStackUtils.splitHostPort("192.168.1.1:70000")); + } + + @Test + void testSplitHostPortWithMissingPort() { + assertThrows(IllegalArgumentException.class, () -> IPStackUtils.splitHostPort("192.168.1.1")); + } + + @Test + void testSplitHostPortWithMissingIP() { + assertThrows(IllegalArgumentException.class, () -> IPStackUtils.splitHostPort(":8080")); + } Review Comment: Done -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org