From 2dc759c8fa8eab9f0e9d13e7195060978f93199b Mon Sep 17 00:00:00 2001 From: Travis Downs Date: Mon, 4 Jul 2022 23:15:37 -0700 Subject: [PATCH] Add any_handler unit tests The any_handler already gets good functional coverage as it is added to the core request path in requests.cc, but we also include this unit test with basic coverage. --- src/v/kafka/server/tests/CMakeLists.txt | 4 +- src/v/kafka/server/tests/any_handler_test.cc | 49 ++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/v/kafka/server/tests/any_handler_test.cc diff --git a/src/v/kafka/server/tests/CMakeLists.txt b/src/v/kafka/server/tests/CMakeLists.txt index 875fc931d94b..2affe2b57245 100644 --- a/src/v/kafka/server/tests/CMakeLists.txt +++ b/src/v/kafka/server/tests/CMakeLists.txt @@ -8,11 +8,13 @@ rp_test( timeouts_conversion_test.cc types_conversion_tests.cc topic_utils_test.cc + any_handler_test.cc DEFINITIONS BOOST_TEST_DYN_LINK - LIBRARIES Boost::unit_test_framework v::kafka + LIBRARIES Boost::unit_test_framework v::kafka v::coproc LABELS kafka ) + set(srcs s3_imposter_fixture.cc consumer_groups_test.cc diff --git a/src/v/kafka/server/tests/any_handler_test.cc b/src/v/kafka/server/tests/any_handler_test.cc new file mode 100644 index 000000000000..8aa3946dd685 --- /dev/null +++ b/src/v/kafka/server/tests/any_handler_test.cc @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Redpanda Data, Inc. + * + * Use of this software is governed by the Business Source License + * included in the file licenses/BSL.md + * + * As of the Change Date specified in that file, in accordance with + * the Business Source License, use of this software will be governed + * by the Apache License, Version 2.0 + */ +#include "kafka/server/handlers/details/any_handler.h" +#include "kafka/server/handlers/handlers.h" + +#include + +template +void check_any_vs_static() { + BOOST_TEST_INFO("Testing " << H::api::name); + auto hopt = kafka::handler_for_key(H::api::key); + BOOST_REQUIRE(hopt.has_value()); + auto h = *hopt; + BOOST_CHECK_EQUAL(h->min_supported(), H::min_supported); + BOOST_CHECK_EQUAL(h->max_supported(), H::max_supported); + BOOST_CHECK_EQUAL(h->key(), H::api::key); + BOOST_CHECK_EQUAL(h->name(), H::api::name); +} + +template +void check_all_types(kafka::type_list) { + (check_any_vs_static(), ...); +} + +BOOST_AUTO_TEST_CASE(any_handler_all_types) { + check_all_types(kafka::request_types{}); +} + +BOOST_AUTO_TEST_CASE(any_handler_handler_for_key) { + // key too low + BOOST_CHECK(!kafka::handler_for_key(kafka::api_key(-1)).has_value()); + // key too high + const auto max_key = kafka::max_api_key(kafka::request_types{}); + BOOST_CHECK( + !kafka::handler_for_key(kafka::api_key(max_key + 1)).has_value()); + // last key should be present + BOOST_CHECK(kafka::handler_for_key(kafka::api_key(max_key)).has_value()); + // 34 is AlterReplicaLogDirs which we don't currently support, use it as a + // test case for handlers which fall in the valid range but we don't support + BOOST_CHECK(!kafka::handler_for_key(kafka::api_key(34)).has_value()); +}