From fdce3caad80476450fa00661dec30b8a95ff0f96 Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Thu, 19 Oct 2023 15:46:35 +0530 Subject: [PATCH] test (kubernetes-client-api) : Add test in AbstractHttpLoggingInterceptor to not consume response bytes (#5251) Add a unit test in AbstractHttpLoggingInterceptor to verify response bytes are not consumed after they've been processed by HttpLoggingInterceptor. I've verified that test fails when I revert https://github.com/fabric8io/kubernetes-client/pull/5250 in httpclient-okhttp and httpclient-vertx modules Signed-off-by: Rohan Kumar --- .../http/AbstractHttpLoggingInterceptorTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpLoggingInterceptorTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpLoggingInterceptorTest.java index 6a4ba33221b..0e3a86f62b0 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpLoggingInterceptorTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpLoggingInterceptorTest.java @@ -43,6 +43,7 @@ import java.util.Queue; import java.util.concurrent.TimeUnit; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; @@ -181,6 +182,18 @@ public void httpResponseBodyLogged() throws Exception { inOrder.verify(logger).trace("-HTTP END-"); } + @Test + @DisplayName("Interceptor doesn't consume response bytes") + public void responseBodyIsNotConsumed() throws Exception { + server.expect().withPath("/response-body") + .andReturn(200, "This is the response body") + .always(); + HttpResponse httpResponse = httpClient.sendAsync(httpClient.newHttpRequestBuilder() + .uri(server.url("/response-body")) + .build(), String.class).get(10, TimeUnit.SECONDS); + assertThat(httpResponse.bodyString()).isEqualTo("This is the response body"); + } + @Test @DisplayName("HTTP large response body is logged") public void httpLargeResponseBodyLogged() throws Exception {