Skip to content

Commit

Permalink
Fix AFVSOCKSocketAddress.toSocatAddressString test
Browse files Browse the repository at this point in the history
AFSocketAddress.toSocatAddressString may throw a SocketException if the
address is not natively supported on the target system. The unit test
didn't catch that.
  • Loading branch information
kohlschuetter committed Jan 27, 2023
1 parent 5a10f38 commit 96c9f4f
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.newsclub.net.unix;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -96,12 +96,19 @@ public void testNamedCIDs() throws Exception {

@Test
public void testSocatString() throws Exception {
String socatString = AFVSOCKSocketAddress.ofPortAndCID(123, 4).toSocatAddressString(
AFSocketType.SOCK_STREAM, AFSocketProtocol.DEFAULT);
if (socatString == null) {
assertFalse(AFSocket.supports(AFSocketCapability.CAPABILITY_VSOCK));
} else {
assertTrue(socatString.contains(":"));
String socatString;
try {
socatString = AFVSOCKSocketAddress.ofPortAndCID(123, 4).toSocatAddressString(
AFSocketType.SOCK_STREAM, AFSocketProtocol.DEFAULT);
assertNotNull(socatString);
} catch (SocketException e) {
if (AFSocket.supports(AFSocketCapability.CAPABILITY_VSOCK)) {
throw e;
} else {
// expected
return;
}
}
assertTrue(socatString.contains(":"));
}
}

0 comments on commit 96c9f4f

Please sign in to comment.