feat: add CMake build configuration and unit tests for XRabbitMQClient
This commit is contained in:
19
test/CMakeLists.txt
Normal file
19
test/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
find_package(xgoogletest CONFIG REQUIRED)
|
||||
|
||||
add_executable(xrabbitmqclient_test
|
||||
test_rabbitmq_client.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(xrabbitmqclient_test PRIVATE
|
||||
xrabbitmqclient
|
||||
xgoogletest::xgoogletest
|
||||
)
|
||||
|
||||
# Important for MSVC encoding issues
|
||||
if(MSVC)
|
||||
target_compile_options(xrabbitmqclient_test PRIVATE /utf-8)
|
||||
endif()
|
||||
|
||||
# Register with CTest
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(xrabbitmqclient_test)
|
||||
26
test/test_rabbitmq_client.cpp
Normal file
26
test/test_rabbitmq_client.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "RabbitMQClient.h"
|
||||
|
||||
// Note: A real RabbitMQ broker is needed to fully test this wrapper.
|
||||
// Since we might not have a broker running locally on the build server,
|
||||
// these tests will check for proper failure handling or basic instantiations.
|
||||
// For full integration tests, a mocked simpleamqpclient or a local broker is required.
|
||||
|
||||
TEST(RabbitMQClientTest, InvalidCredentialsFail) {
|
||||
RabbitMQClient client("localhost", 5672, "invalid_user", "invalid_password");
|
||||
// Connect should fail with incorrect credentials or no server
|
||||
EXPECT_FALSE(client.Connect());
|
||||
}
|
||||
|
||||
TEST(RabbitMQClientTest, DisconnectedPublish) {
|
||||
RabbitMQClient client("localhost", 5672, "guest", "guest");
|
||||
// Without a successful connection, publish must fail
|
||||
EXPECT_FALSE(client.Publish("test_queue", "Hello World"));
|
||||
}
|
||||
|
||||
TEST(RabbitMQClientTest, DisconnectedConsume) {
|
||||
RabbitMQClient client("localhost", 5672, "guest", "guest");
|
||||
// Consume without connection should probably throw or return empty
|
||||
std::string msg = client.Consume("test_queue");
|
||||
EXPECT_TRUE(msg.empty());
|
||||
}
|
||||
Reference in New Issue
Block a user