Fixing org.opensearch.common.network.InetAddressesTests.testForStringIPv6WithScopeIdInput (#1913)

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
This commit is contained in:
Andriy Redko 2022-01-14 16:23:33 -05:00 committed by GitHub
parent 524448fc41
commit dd8ad29770
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -33,11 +33,18 @@ import org.opensearch.common.collect.Tuple;
import org.opensearch.test.OpenSearchTestCase;
import org.hamcrest.Matchers;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.Enumeration;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assume.assumeThat;
public class InetAddressesTests extends OpenSearchTestCase {
public void testForStringBogusInput() {
String[] bogusInputs = {
@ -147,11 +154,12 @@ public class InetAddressesTests extends OpenSearchTestCase {
String scopeId = null;
while (interfaces.hasMoreElements()) {
final NetworkInterface nint = interfaces.nextElement();
if (nint.isLoopback()) {
if (nint.isLoopback() && Collections.list(nint.getInetAddresses()).stream().anyMatch(Inet6Address.class::isInstance)) {
scopeId = nint.getName();
break;
}
}
assumeThat("The loopback interface has no IPv6 address assigned", scopeId, is(not(nullValue())));
assertNotNull(scopeId);
String ipStr = "0:0:0:0:0:0:0:1%" + scopeId;
InetAddress ipv6Addr = InetAddress.getByName(ipStr);