Skip to content

Commit

Permalink
Fixing org.opensearch.common.network.InetAddressesTests.testForString…
Browse files Browse the repository at this point in the history
…IPv6WithScopeIdInput (#1913) (#1914)

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
reta authored Jan 15, 2022
1 parent 67cfbb3 commit e80b0e4
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,18 @@
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 = {
Expand Down Expand Up @@ -147,11 +154,12 @@ public void testForStringIPv6WithScopeIdInput() throws java.io.IOException {
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);
Expand Down

0 comments on commit e80b0e4

Please sign in to comment.