Skip to content

Commit d3411d6

Browse files
Added random string generation in unit test
1 parent 214de5f commit d3411d6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/huggingface/request/HuggingFaceUnifiedChatCompletionRequestTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.elasticsearch.xpack.inference.services.huggingface.request.completion.HuggingFaceUnifiedChatCompletionRequest;
1616

1717
import java.io.IOException;
18-
import java.net.URISyntaxException;
1918
import java.util.List;
2019
import java.util.Map;
2120

@@ -27,7 +26,7 @@
2726
public class HuggingFaceUnifiedChatCompletionRequestTests extends ESTestCase {
2827

2928
public void testCreateRequest_WithStreaming() throws IOException {
30-
var request = createRequest("url", "secret", "abcd", "model", true);
29+
var request = createRequest("url", "secret", randomAlphaOfLength(15), "model", true);
3130
var httpRequest = request.createHttpRequest();
3231

3332
assertThat(httpRequest.httpRequestBase(), instanceOf(HttpPost.class));
@@ -37,8 +36,9 @@ public void testCreateRequest_WithStreaming() throws IOException {
3736
assertThat(requestMap.get("stream"), is(true));
3837
}
3938

40-
public void testTruncate_DoesNotReduceInputTextSize() throws URISyntaxException, IOException {
41-
var request = createRequest("url", "secret", "abcd", "model", true);
39+
public void testTruncate_DoesNotReduceInputTextSize() throws IOException {
40+
String input = randomAlphaOfLength(5);
41+
var request = createRequest("url", "secret", input, "model", true);
4242
var truncatedRequest = request.truncate();
4343
assertThat(request.getURI().toString(), is("url"));
4444

@@ -50,15 +50,15 @@ public void testTruncate_DoesNotReduceInputTextSize() throws URISyntaxException,
5050
assertThat(requestMap, aMapWithSize(5));
5151

5252
// We do not truncate for Hugging Face chat completions
53-
assertThat(requestMap.get("messages"), is(List.of(Map.of("role", "user", "content", "abcd"))));
53+
assertThat(requestMap.get("messages"), is(List.of(Map.of("role", "user", "content", input))));
5454
assertThat(requestMap.get("model"), is("model"));
5555
assertThat(requestMap.get("n"), is(1));
5656
assertTrue((Boolean) requestMap.get("stream"));
5757
assertThat(requestMap.get("stream_options"), is(Map.of("include_usage", true)));
5858
}
5959

6060
public void testTruncationInfo_ReturnsNull() {
61-
var request = createRequest("url", "secret", "abcd", "model", true);
61+
var request = createRequest("url", "secret", randomAlphaOfLength(5), "model", true);
6262
assertNull(request.getTruncationInfo());
6363
}
6464

0 commit comments

Comments
 (0)