diff --git a/services/backup/docker-server/contents/server/CMakeLists.txt b/services/backup/docker-server/contents/server/CMakeLists.txt index 53fc4d4f6..6847e2066 100644 --- a/services/backup/docker-server/contents/server/CMakeLists.txt +++ b/services/backup/docker-server/contents/server/CMakeLists.txt @@ -1,132 +1,136 @@ PROJECT(backup C CXX) cmake_minimum_required(VERSION 3.16) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin) if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) endif(COMMAND cmake_policy) set(CMAKE_CXX_STANDARD 17) # FIND LIBS set(protobuf_MODULE_COMPATIBLE TRUE) find_package(Protobuf CONFIG REQUIRED) message(STATUS "Using protobuf ${Protobuf_VERSION}") set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf) set(_PROTOBUF_PROTOC $) # gRPC building parameters set(gRPC_BUILD_CSHARP_EXT OFF) set(gRPC_SSL_PROVIDER "package" CACHE STRING "SSL library provider") # Disable unused plugins set(gRPC_BUILD_GRPC_PHP_PLUGIN OFF) set(gRPC_BUILD_GRPC_RUBY_PLUGIN OFF) set(gRPC_BUILD_GRPC_PYTHON_PLUGIN OFF) set(gRPC_BUILD_GRPC_CSHARP_PLUGIN OFF) +if ($ENV{COMM_TEST_SERVICES} MATCHES 1) + add_compile_definitions(COMM_TEST_SERVICES) +endif() + # Find gRPC installation # Looks for gRPCConfig.cmake file installed by gRPC's cmake installation. find_package(gRPC CONFIG REQUIRED) message(STATUS "Using gRPC ${gRPC_VERSION}") set(_GRPC_GRPCPP gRPC::grpc++) set(_GRPC_CPP_PLUGIN_EXECUTABLE $) set(BUILD_TESTING OFF CACHE BOOL "Turn off tests" FORCE) find_package(AWSSDK REQUIRED COMPONENTS core dynamodb) find_package(Boost 1.40 COMPONENTS program_options REQUIRED) file(GLOB GENERATED_CODE "./_generated/*.cc") set(DEV_SOURCE_CODE "") set(DEV_HEADERS_PATH "") if ($ENV{COMM_SERVICES_DEV_MODE} MATCHES 1) file(GLOB DEV_SOURCE_CODE "./dev/*.cpp" "./src/*.dev.cpp") set(DEV_HEADERS_PATH "./dev") endif() file(GLOB SOURCE_CODE "./src/*.cpp" "./src/**/*.cpp") list(FILTER SOURCE_CODE EXCLUDE REGEX ".*.dev.cpp$") foreach (ITEM ${DEV_SOURCE_CODE}) string(REPLACE "/" ";" SPLIT_ITEM ${ITEM}) list(GET SPLIT_ITEM -1 FILE_FULL_NAME) string(REPLACE ".dev.cpp" ".cpp" FILE_NAME ${FILE_FULL_NAME}) list(FILTER SOURCE_CODE EXCLUDE REGEX ".*${FILE_NAME}$") list(APPEND SOURCE_CODE "${ITEM}") endforeach() include_directories( ./src ./src/DatabaseEntities ./_generated ${Boost_INCLUDE_DIR} ${DEV_HEADERS_PATH} ) set( LIBS ${_GRPC_GRPCPP} ${_PROTOBUF_LIBPROTOBUF} gRPC::grpc++_reflection ${AWSSDK_LINK_LIBRARIES} ${Boost_LIBRARIES} ) #SERVER add_executable( backup ${GENERATED_CODE} ${SOURCE_CODE} ) target_link_libraries( backup ${LIBS} ) install( TARGETS backup RUNTIME DESTINATION bin/ ) # TEST if ($ENV{COMM_TEST_SERVICES} MATCHES 1) file(GLOB TEST_CODE "./test/*.cpp") list(FILTER SOURCE_CODE EXCLUDE REGEX "./src/server.cpp") enable_testing() find_package(GTest REQUIRED) include_directories( ${GTEST_INCLUDE_DIR} ./test ) add_executable( runTests ${GENERATED_CODE} ${SOURCE_CODE} ${TEST_CODE} ) target_link_libraries( runTests ${LIBS} gtest gtest_main ) add_test( NAME runTests COMMAND runTests ) endif() diff --git a/services/backup/docker-server/contents/server/test/DatabaseManagerTest.cpp b/services/backup/docker-server/contents/server/test/DatabaseManagerTest.cpp new file mode 100644 index 000000000..88ff60c6d --- /dev/null +++ b/services/backup/docker-server/contents/server/test/DatabaseManagerTest.cpp @@ -0,0 +1,58 @@ +#include + +#include "DatabaseManager.h" +#include "Tools.h" + +#include + +#include +#include +#include + +using namespace comm::network::database; + +class DatabaseManagerTest : public testing::Test { +protected: + virtual void SetUp() { + Aws::InitAPI({}); + } + + virtual void TearDown() { + Aws::ShutdownAPI({}); + } +}; + +std::string generateName(const std::string prefix = "") { + return prefix + "-" + std::to_string(comm::network::getCurrentTimestamp()); +} + +TEST_F(DatabaseManagerTest, TestOperationsOnBackupItems) { + auto generateBackupItem = [](const std::string &userID, + const std::string &backupID) { + return BackupItem( + userID, + backupID, + comm::network::getCurrentTimestamp(), + "xxx", + "xxx", + {""}); + }; + + const std::string userID = generateName("user001"); + + std::vector backupIDs = {"backup001", "backup002", "backup003"}; + for (const std::string &backupID : backupIDs) { + DatabaseManager::getInstance().putBackupItem( + generateBackupItem(userID, backupID)); + } + + std::shared_ptr item; + while (!backupIDs.empty()) { + item = DatabaseManager::getInstance().findLastBackupItem(userID); + EXPECT_NE(item, nullptr); + EXPECT_EQ(item->getBackupID(), backupIDs.back()); + backupIDs.pop_back(); + DatabaseManager::getInstance().removeBackupItem(item); + }; + EXPECT_EQ(DatabaseManager::getInstance().findLastBackupItem(userID), nullptr); +}