Skip to content

Commit

Permalink
Add any_handler unit tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
travisdowns committed Jul 5, 2022
1 parent db9de3c commit 72ee787
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/v/kafka/server/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
consumer_groups_test.cc
member_test.cc
Expand Down
49 changes: 49 additions & 0 deletions src/v/kafka/server/tests/any_handler_test.cc
Original file line number Diff line number Diff line change
@@ -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 <boost/test/unit_test.hpp>

template<kafka::KafkaApiHandlerAny H>
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<typename... Ts>
void check_all_types(kafka::type_list<Ts...>) {
(check_any_vs_static<Ts>(), ...);
}

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());
}

0 comments on commit 72ee787

Please sign in to comment.