diff --git a/services/backup/docker-server/contents/server/test/DatabaseManagerTest.cpp b/services/backup/docker-server/contents/server/test/DatabaseManagerTest.cpp --- a/services/backup/docker-server/contents/server/test/DatabaseManagerTest.cpp +++ b/services/backup/docker-server/contents/server/test/DatabaseManagerTest.cpp @@ -26,18 +26,22 @@ 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", - {""}); - }; +BackupItem +generateBackupItem(const std::string &userID, const std::string &backupID) { + return BackupItem( + userID, + comm::network::getCurrentTimestamp(), + backupID, + "xxx", + "xxx", + {""}); +} + +LogItem generateLogItem(const std::string &backupID, const std::string &logID) { + return LogItem(backupID, logID, false, "xxx", {""}); +} +TEST_F(DatabaseManagerTest, TestOperationsOnBackupItems) { const std::string userID = generateName("user001"); std::vector backupIDs = {"backup001", "backup002", "backup003"}; @@ -56,3 +60,44 @@ }; EXPECT_EQ(DatabaseManager::getInstance().findLastBackupItem(userID), nullptr); } + +TEST_F(DatabaseManagerTest, TestOperationsOnLogItems) { + const std::string backupID1 = generateName("backup001"); + const std::string backupID2 = generateName("backup002"); + + std::vector logIDs1 = {"log001", "log002", "log003"}; + for (const std::string &logID : logIDs1) { + DatabaseManager::getInstance().putLogItem( + generateLogItem(backupID1, logID)); + } + std::vector logIDs2 = {"log021", "log022"}; + for (const std::string &logID : logIDs2) { + DatabaseManager::getInstance().putLogItem( + generateLogItem(backupID2, logID)); + } + + std::vector> items1 = + DatabaseManager::getInstance().findLogItemsForBackup(backupID1); + + std::vector> items2 = + DatabaseManager::getInstance().findLogItemsForBackup(backupID2); + + EXPECT_EQ(items1.size(), 3); + EXPECT_EQ(items2.size(), 2); + + for (size_t i = 0; i < items1.size(); ++i) { + EXPECT_EQ(logIDs1.at(i), items1.at(i)->getLogID()); + DatabaseManager::getInstance().removeLogItem(items1.at(i)); + } + EXPECT_EQ( + DatabaseManager::getInstance().findLogItemsForBackup(backupID1).size(), + 0); + + for (size_t i = 0; i < items2.size(); ++i) { + EXPECT_EQ(logIDs2.at(i), items2.at(i)->getLogID()); + DatabaseManager::getInstance().removeLogItem(items2.at(i)); + } + EXPECT_EQ( + DatabaseManager::getInstance().findLogItemsForBackup(backupID2).size(), + 0); +}