Skip to content

Commit

Permalink
add unit tests (#1104)
Browse files Browse the repository at this point in the history
One for EndpointTest that checks for the GetRequest.id() being correctly encoded. One for PathEncodingTesst to verify that ":" is being encoded.

Updated for spotless.

Signed-off-by: Al Niessner <[email protected]>
Co-authored-by: Al Niessner <[email protected]>
  • Loading branch information
al-niessner and Al Niessner authored Jul 24, 2024
1 parent eff1ae1 commit c098d8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@
import org.junit.Assert;
import org.junit.Test;
import org.opensearch.client.opensearch._types.ExpandWildcard;
import org.opensearch.client.opensearch.core.GetRequest;
import org.opensearch.client.opensearch.indices.RefreshRequest;

public class EndpointTest extends Assert {
@Test
public void testIdEncoding() {
GetRequest req = new GetRequest.Builder().index("db").id("a:b:c::2.0").build();
assertEquals("/db/_doc/a%3Ab%3Ac%3A%3A2.0", GetRequest._ENDPOINT.requestUrl(req));
}

@Test
public void testArrayPathParameter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,10 @@ public void testEncode() {
String multiSegmentString = "a/b/c/_refresh";
String encodedMultiSegmentString = PathEncoder.encode(multiSegmentString);
assertEquals("a%2Fb%2Fc%2F_refresh", encodedMultiSegmentString);

// Test with a string that contains colon segment
String colonSegmentString = "a:b:c::2.0";
String encodedColonSegmentString = PathEncoder.encode(colonSegmentString);
assertEquals("a%3Ab%3Ac%3A%3A2.0", encodedColonSegmentString);
}
}

0 comments on commit c098d8b

Please sign in to comment.