Skip to content

Commit

Permalink
Switch from GoogleTest to Catch2
Browse files Browse the repository at this point in the history
  • Loading branch information
0xg0nz0 committed Feb 26, 2024
1 parent 721b4a5 commit 17ddbd7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 37 deletions.
23 changes: 5 additions & 18 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@

# set up GoogleTest
if(BUILD_TESTS)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/dddb219c3eb96d7f9200f09b0a381f016e6b4562.zip
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

# for E2E tests, controlling Docker containers
find_package(catch2 CONFIG REQUIRED)
find_package(reproc++ CONFIG REQUIRED)

# set up GoogleTest
enable_testing()

add_executable(
iggy_cpp_test

Expand All @@ -24,7 +12,8 @@ if(BUILD_TESTS)
iggy_cpp_test

iggy
GTest::gtest_main
Catch2::Catch2
Catch2::Catch2WithMain
libuv::uv_a
reproc++
unofficial-sodium::sodium
Expand All @@ -42,12 +31,10 @@ if(BUILD_TESTS)
PRIVATE

iggy
GTest::gtest_main
Catch2::Catch2
Catch2::Catch2WithMain
libuv::uv_a
reproc++
unofficial-sodium::sodium
)

include(GoogleTest)
gtest_discover_tests(iggy_cpp_test)
endif()
8 changes: 5 additions & 3 deletions tests/e2e_testutils.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "e2e_testutils.h"
#include <chrono>
#include <stdexcept>
#include <string>
#include <thread>
#include <vector>

void DockerTest::SetUp() {
IggyRunner::IggyRunner() {
// start the Docker process with stdout redirected to parent process
std::vector<std::string> arguments = {"docker", "run", "-d", "--name", "iggy_test", "iggyrs/iggy:latest"};
reproc::options options;
Expand All @@ -17,7 +19,7 @@ void DockerTest::SetUp() {
std::this_thread::sleep_for(std::chrono::seconds(5));
}

void DockerTest::TearDown() {
IggyRunner::~IggyRunner() {
// stop the Docker process
process.stop(reproc::stop_actions{{reproc::stop::terminate, reproc::milliseconds(5000)},
{reproc::stop::kill, reproc::milliseconds(2000)},
Expand All @@ -28,4 +30,4 @@ void DockerTest::TearDown() {
std::vector<std::string> remove_arguments = {"docker", "rm", "-f", "iggy_test"};
remove_process.start(remove_arguments);
remove_process.wait(reproc::milliseconds(5000));
}
}
14 changes: 6 additions & 8 deletions tests/e2e_testutils.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
#pragma once
#include <gtest/gtest.h>
#include <reproc++/reproc.hpp>

/**
* @class DockerTest
* @brief GoogleTest fixture that starts and stops a Docker container for each test.
* @brief Test fixture that starts and stops a Docker container for each test.
*
* This test fixture is meant for use in end-to-end (E2E) tests for the Iggy C++ client.
* It will start up the latest Iggy server inside a Docker container, allow you to
* interact with it, then stop and remove the container in the TearDown() method.
*/
class DockerTest : public ::testing::Test {
protected:
class IggyRunner {
private:
reproc::process process;

void SetUp() override;

void TearDown() override;
public:
IggyRunner();
~IggyRunner();
};
11 changes: 4 additions & 7 deletions tests/model_test.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#include <gtest/gtest.h>
#define CATCH_CONFIG_MAIN
#include <catch.hpp>
#include "../sdk/model.h"

TEST(ModelTest, DefaultConstructor) {
// Create a Message object using the default constructor
TEST_CASE("simple test for model objects", "[model]") {
iggy::model::system::Stats stats;

// Perform assertions to verify the expected behavior
// For example, you can check if the message object is not null
ASSERT_NE(nullptr, &stats);
REQUIRE(&stats != nullptr);
}
6 changes: 5 additions & 1 deletion tests/ping_cmd_test.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include <catch.hpp>
#include "e2e_testutils.h"
#include "../sdk/client.h"

TEST_F(DockerTest, BinaryPing) {
TEST_CASE("E2E test for ping command", "[ping]") {
// Start the Docker container; shuts down when this object goes out of scope
IggyRunner runner;

// Create a client object with all defaults
iggy::client::Options options;
iggy::client::Client client(options);
Expand Down
1 change: 1 addition & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"dependencies": [
"ada-url",
"catch2",
"icu",
"libsodium",
"libuv",
Expand Down

0 comments on commit 17ddbd7

Please sign in to comment.