Skip to content

Commit 8cc8958

Browse files
Add unit tests for LlamaErrorResponse to validate error handling from HTTP responses
1 parent da55903 commit 8cc8958

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.inference.services.llama.response;
9+
10+
import org.apache.http.HttpResponse;
11+
import org.elasticsearch.test.ESTestCase;
12+
import org.elasticsearch.xpack.inference.external.http.HttpResult;
13+
14+
import java.nio.charset.StandardCharsets;
15+
16+
import static org.mockito.Mockito.mock;
17+
18+
public class LlamaErrorResponseTests extends ESTestCase {
19+
20+
public static final String ERROR_RESPONSE_JSON = """
21+
{
22+
"error": "A valid user token is required"
23+
}
24+
""";
25+
26+
public void testFromResponse() {
27+
var errorResponse = LlamaErrorResponse.fromResponse(
28+
new HttpResult(mock(HttpResponse.class), ERROR_RESPONSE_JSON.getBytes(StandardCharsets.UTF_8))
29+
);
30+
assertNotNull(errorResponse);
31+
assertEquals(ERROR_RESPONSE_JSON, errorResponse.getErrorMessage());
32+
}
33+
34+
}

0 commit comments

Comments
 (0)