diff --git a/services/backup/docker-server/contents/server/CMakeLists.txt b/services/backup/docker-server/contents/server/CMakeLists.txt --- a/services/backup/docker-server/contents/server/CMakeLists.txt +++ b/services/backup/docker-server/contents/server/CMakeLists.txt @@ -27,6 +27,10 @@ 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) 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 --- /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, + comm::network::getCurrentTimestamp(), + backupID, + "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); +}