diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f513ea3..fe733a1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 @@ -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 @@ -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() diff --git a/tests/e2e_testutils.cc b/tests/e2e_testutils.cc index 03049b1..943f5df 100644 --- a/tests/e2e_testutils.cc +++ b/tests/e2e_testutils.cc @@ -1,9 +1,11 @@ #include "e2e_testutils.h" #include #include +#include #include +#include -void DockerTest::SetUp() { +IggyRunner::IggyRunner() { // start the Docker process with stdout redirected to parent process std::vector arguments = {"docker", "run", "-d", "--name", "iggy_test", "iggyrs/iggy:latest"}; reproc::options options; @@ -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)}, @@ -28,4 +30,4 @@ void DockerTest::TearDown() { std::vector remove_arguments = {"docker", "rm", "-f", "iggy_test"}; remove_process.start(remove_arguments); remove_process.wait(reproc::milliseconds(5000)); -} \ No newline at end of file +} diff --git a/tests/e2e_testutils.h b/tests/e2e_testutils.h index 73b4cec..97fe722 100644 --- a/tests/e2e_testutils.h +++ b/tests/e2e_testutils.h @@ -1,20 +1,18 @@ #pragma once -#include #include /** - * @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(); }; \ No newline at end of file diff --git a/tests/model_test.cc b/tests/model_test.cc index 9b0ce56..4b3b82d 100644 --- a/tests/model_test.cc +++ b/tests/model_test.cc @@ -1,11 +1,8 @@ -#include +#define CATCH_CONFIG_MAIN +#include #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); } diff --git a/tests/ping_cmd_test.cc b/tests/ping_cmd_test.cc index c158eaa..767e7c8 100644 --- a/tests/ping_cmd_test.cc +++ b/tests/ping_cmd_test.cc @@ -1,7 +1,11 @@ +#include #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); diff --git a/vcpkg.json b/vcpkg.json index 810113e..6d55099 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,6 +1,7 @@ { "dependencies": [ "ada-url", + "catch2", "icu", "libsodium", "libuv",