mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
synced 2025-11-01 11:07:56 +00:00
Allow to pass-in via cmake all the kafka config options for testing: broker, partitions and topics
This commit is contained in:
@@ -1,12 +1,34 @@
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include/)
|
||||
include_directories(SYSTEM ${CATCH_INCLUDE})
|
||||
|
||||
set(KAFKA_TEST_INSTANCE "kafka-vm:9092"
|
||||
if (NOT KAFKA_TEST_INSTANCE)
|
||||
set(KAFKA_TEST_INSTANCE kafka-vm:9092
|
||||
CACHE STRING "The kafka instance to which to connect to run tests")
|
||||
endif()
|
||||
if (NOT KAFKA_NUM_PARTITIONS)
|
||||
set(KAFKA_NUM_PARTITIONS 3 CACHE STRING "Kafka Number of partitions")
|
||||
endif()
|
||||
if (NOT KAFKA_TOPICS)
|
||||
set(KAFKA_TOPICS "cppkafka_test1;cppkafka_test2" CACHE STRING "Kafka topics")
|
||||
endif()
|
||||
|
||||
# Convert list of topics into a C++ initializer list
|
||||
FOREACH(TOPIC ${KAFKA_TOPICS})
|
||||
if (NOT TOPIC_LIST)
|
||||
set(TOPIC_LIST "\"${TOPIC}\"")
|
||||
else()
|
||||
set(TOPIC_LIST "${TOPIC_LIST},\"${TOPIC}\"")
|
||||
endif()
|
||||
ENDFOREACH()
|
||||
|
||||
add_custom_target(tests)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_definitions("-DKAFKA_TEST_INSTANCE=\"${KAFKA_TEST_INSTANCE}\"")
|
||||
add_definitions(
|
||||
"-DKAFKA_TEST_INSTANCE=\"${KAFKA_TEST_INSTANCE}\""
|
||||
-DKAFKA_NUM_PARTITIONS=${KAFKA_NUM_PARTITIONS}
|
||||
-DKAFKA_TOPIC_NAMES=${TOPIC_LIST}
|
||||
)
|
||||
|
||||
add_executable(cppkafka_tests
|
||||
buffer_test.cpp
|
||||
@@ -25,6 +47,6 @@ add_executable(cppkafka_tests
|
||||
)
|
||||
|
||||
# In CMake >= 3.15 Boost::boost == Boost::headers
|
||||
target_link_libraries(cppkafka_tests cppkafka RdKafka::rdkafka Boost::boost Boost::program_options )
|
||||
target_link_libraries(cppkafka_tests cppkafka RdKafka::rdkafka Boost::boost Boost::program_options)
|
||||
add_dependencies(tests cppkafka_tests)
|
||||
add_test(cppkafka cppkafka_tests)
|
||||
|
||||
@@ -15,8 +15,7 @@ using Catch::TestCaseStats;
|
||||
using Catch::Totals;
|
||||
using Catch::Session;
|
||||
|
||||
std::vector<std::string> KAFKA_TOPICS = {"cppkafka_test1", "cppkafka_test2"};
|
||||
int KAFKA_NUM_PARTITIONS = 3;
|
||||
std::vector<std::string> KAFKA_TOPICS = {KAFKA_TOPIC_NAMES};
|
||||
|
||||
namespace cppkafka {
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "cppkafka/utils/consumer_dispatcher.h"
|
||||
|
||||
extern const std::vector<std::string> KAFKA_TOPICS;
|
||||
extern const int KAFKA_NUM_PARTITIONS;
|
||||
|
||||
using namespace cppkafka;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user