Skip to content

Commit

Permalink
Feat add a test case in AbstractHttpClientTest.java (#12924)
Browse files Browse the repository at this point in the history
Co-authored-by: Lauri Tulmin <[email protected]>
  • Loading branch information
shalk and laurit authored Jan 13, 2025
1 parent 7ae8069 commit 8c0aafb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public int sendRequest(
response = proxy.put_success(param, isTestServer, requestId);
} else if (proxyMethodName.equals("get_error")) {
response = proxy.get_error(param, isTestServer, requestId);
} else if (proxyMethodName.equals("get_client_error")) {
response = proxy.get_client_error(param, isTestServer, requestId);
} else {
throw new IllegalArgumentException("Unknown method: " + proxyMethodName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ Response get_error(
@HeaderParam("is-test-server") String isTestServer,
@HeaderParam("test-request-id") String requestId);

@GET
@Path("client-error")
Response get_client_error(
@QueryParam("with") String param,
@HeaderParam("is-test-server") String isTestServer,
@HeaderParam("test-request-id") String requestId);

@GET
@Path("success")
Response get_success(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,14 @@ abstract class HttpClientTest<REQUEST> extends InstrumentationSpecification {
junitTest.redirectToSecuredCopiesAuthHeader()
}
def "error span"() {
def "error span for #path"() {
expect:
junitTest.errorSpan()
junitTest.errorSpan(path, statusCode)
where:
path | statusCode
"/client-error" | 400
"/error" | 500
}
def "reuse request"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
Expand Down Expand Up @@ -437,10 +438,11 @@ void redirectToSecuredCopiesAuthHeader() throws Exception {

// TODO: add basic auth scenario

@Test
void errorSpan() {
@ParameterizedTest
@CsvSource({"/error,500", "/client-error,400"})
void errorSpan(String path, int responseCode) {
String method = "GET";
URI uri = resolveAddress("/error");
URI uri = resolveAddress(path);

testing.runWithSpan(
"parent",
Expand All @@ -456,7 +458,9 @@ void errorSpan() {
trace -> {
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(),
span -> assertClientSpan(span, uri, method, 500, null).hasParent(trace.getSpan(0)),
span ->
assertClientSpan(span, uri, method, responseCode, null)
.hasParent(trace.getSpan(0)),
span -> assertServerSpan(span).hasParent(trace.getSpan(1)));
});
}
Expand Down

0 comments on commit 8c0aafb

Please sign in to comment.