From 6a0d9069300ee2bb93d574e878b35e222cbbfe5c Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 26 Jun 2024 15:00:00 +0300 Subject: [PATCH] test/http: Generalize simple request sending There are several tests that call client::make_request() with some simple pre-defined request that's supposed to fail. Next patches will want to do the same, so prepare the helper function in advance. Signed-off-by: Pavel Emelyanov --- tests/unit/httpd_test.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/unit/httpd_test.cc b/tests/unit/httpd_test.cc index 96f58278685..d6e95c08934 100644 --- a/tests/unit/httpd_test.cc +++ b/tests/unit/httpd_test.cc @@ -891,6 +891,12 @@ static void read_simple_http_request(input_stream& in) { } } +static future<> make_failing_http_request(http::experimental::client& cln) { + return cln.make_request(http::request::make("GET", "test", "/test"), [] (const http::reply& rep, input_stream&& in) { + return make_exception_future<>(std::runtime_error("Shouldn't happen")); + }, http::reply::status_type::ok); +} + SEASTAR_TEST_CASE(test_client_response_eof) { return seastar::async([] { loopback_connection_factory lcf(1); @@ -908,10 +914,7 @@ SEASTAR_TEST_CASE(test_client_response_eof) { future<> client = seastar::async([&lcf] { auto cln = http::experimental::client(std::make_unique(lcf)); - auto req = http::request::make("GET", "test", "/test"); - BOOST_REQUIRE_EXCEPTION(cln.make_request(std::move(req), [] (const http::reply& rep, input_stream&& in) { - return make_exception_future<>(std::runtime_error("Shouldn't happen")); - }, http::reply::status_type::ok).get(), std::system_error, [] (auto& ex) { + BOOST_REQUIRE_EXCEPTION(make_failing_http_request(cln).get(), std::system_error, [] (auto& ex) { return ex.code().value() == ECONNABORTED; }); @@ -940,9 +943,7 @@ SEASTAR_TEST_CASE(test_client_response_parse_error) { future<> client = seastar::async([&lcf] { auto cln = http::experimental::client(std::make_unique(lcf)); auto req = http::request::make("GET", "test", "/test"); - BOOST_REQUIRE_EXCEPTION(cln.make_request(std::move(req), [] (const http::reply& rep, input_stream&& in) { - return make_exception_future<>(std::runtime_error("Shouldn't happen")); - }, http::reply::status_type::ok).get(), std::runtime_error, [] (auto& ex) { + BOOST_REQUIRE_EXCEPTION(make_failing_http_request(cln).get(), std::runtime_error, [] (auto& ex) { return sstring(ex.what()).contains("Invalid http server response"); });