Move tests to use catch instead of googletest (#56)

* Port buffer test to use Catch2

* Move compacted topic processor test to Catch2

* Move configuration tests to Catch2

* Rename configuration test cases

* Move topic partition list test to Catch2

* Move handle base tests to Catch2

* Move producer tests to Catch2

* Move consumer tests to catch2

* Use CHECK on tests when appropriate

* Remove googletest

* Show tests' progress as they run

* Update message when Catch2 is not checked out

* Remove references to googletest

* Run cppkafka_tests manually on travis

* Print amount of time taken by each test case
This commit is contained in:
Matias Fontanini
2018-04-24 03:20:48 +01:00
committed by GitHub
parent 30b3652a94
commit cb2c8877d8
14 changed files with 528 additions and 530 deletions

View File

@@ -4,7 +4,7 @@
#include <set>
#include <map>
#include <condition_variable>
#include <gtest/gtest.h>
#include <catch.hpp>
#include "cppkafka/producer.h"
#include "cppkafka/consumer.h"
#include "cppkafka/utils/compacted_topic_processor.h"
@@ -29,28 +29,23 @@ using std::chrono::milliseconds;
using namespace cppkafka;
class CompactedTopicProcessorTest : public testing::Test {
public:
static const string KAFKA_TOPIC;
static const string KAFKA_TOPIC = "cppkafka_test1";
Configuration make_producer_config() {
Configuration config;
config.set("metadata.broker.list", KAFKA_TEST_INSTANCE);
return config;
}
static Configuration make_producer_config() {
Configuration config;
config.set("metadata.broker.list", KAFKA_TEST_INSTANCE);
return config;
}
Configuration make_consumer_config() {
Configuration config;
config.set("metadata.broker.list", KAFKA_TEST_INSTANCE);
config.set("enable.auto.commit", false);
config.set("group.id", "compacted_topic_test");
return config;
}
};
static Configuration make_consumer_config() {
Configuration config;
config.set("metadata.broker.list", KAFKA_TEST_INSTANCE);
config.set("enable.auto.commit", false);
config.set("group.id", "compacted_topic_test");
return config;
}
const string CompactedTopicProcessorTest::KAFKA_TOPIC = "cppkafka_test1";
TEST_F(CompactedTopicProcessorTest, Consume) {
TEST_CASE("consumption", "[consumer][compacted]") {
Consumer consumer(make_consumer_config());
// We'll use ints as the key, strings as the value
using CompactedConsumer = CompactedTopicProcessor<int, string>;
@@ -101,27 +96,27 @@ TEST_F(CompactedTopicProcessorTest, Consume) {
size_t set_count = 0;
size_t delete_count = 0;
ASSERT_FALSE(events.empty());
CHECK(events.empty() == false);
for (const Event& event : events) {
switch (event.get_type()) {
case Event::SET_ELEMENT:
{
auto iter = elements.find(to_string(event.get_key()));
ASSERT_NE(iter, elements.end());
EXPECT_EQ(iter->second.value, event.get_value());
EXPECT_EQ(iter->second.partition, event.get_partition());
REQUIRE(iter != elements.end());
CHECK(iter->second.value == event.get_value());
CHECK(iter->second.partition == event.get_partition());
set_count++;
}
break;
case Event::DELETE_ELEMENT:
EXPECT_EQ(0, event.get_partition());
EXPECT_EQ(42, event.get_key());
CHECK(event.get_partition() == 0);
CHECK(event.get_key() == 42);
delete_count++;
break;
default:
break;
}
}
EXPECT_EQ(2, set_count);
EXPECT_EQ(1, delete_count);
CHECK(set_count == 2);
CHECK(delete_count == 1);
}