Fixing org.opensearch.common.network.InetAddressesTests.testForStringIPv6WithScopeIdInput (#1913)
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
This commit is contained in:
parent
524448fc41
commit
dd8ad29770
|
@ -33,11 +33,18 @@ import org.opensearch.common.collect.Tuple;
|
||||||
import org.opensearch.test.OpenSearchTestCase;
|
import org.opensearch.test.OpenSearchTestCase;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
|
|
||||||
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Enumeration;
|
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 class InetAddressesTests extends OpenSearchTestCase {
|
||||||
public void testForStringBogusInput() {
|
public void testForStringBogusInput() {
|
||||||
String[] bogusInputs = {
|
String[] bogusInputs = {
|
||||||
|
@ -147,11 +154,12 @@ public class InetAddressesTests extends OpenSearchTestCase {
|
||||||
String scopeId = null;
|
String scopeId = null;
|
||||||
while (interfaces.hasMoreElements()) {
|
while (interfaces.hasMoreElements()) {
|
||||||
final NetworkInterface nint = interfaces.nextElement();
|
final NetworkInterface nint = interfaces.nextElement();
|
||||||
if (nint.isLoopback()) {
|
if (nint.isLoopback() && Collections.list(nint.getInetAddresses()).stream().anyMatch(Inet6Address.class::isInstance)) {
|
||||||
scopeId = nint.getName();
|
scopeId = nint.getName();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
assumeThat("The loopback interface has no IPv6 address assigned", scopeId, is(not(nullValue())));
|
||||||
assertNotNull(scopeId);
|
assertNotNull(scopeId);
|
||||||
String ipStr = "0:0:0:0:0:0:0:1%" + scopeId;
|
String ipStr = "0:0:0:0:0:0:0:1%" + scopeId;
|
||||||
InetAddress ipv6Addr = InetAddress.getByName(ipStr);
|
InetAddress ipv6Addr = InetAddress.getByName(ipStr);
|
||||||
|
|
Loading…
Reference in New Issue