Page MenuHomePhabricator

D3176.diff
No OneTemporary

D3176.diff

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,
- backupID,
- comm::network::getCurrentTimestamp(),
- "xxx",
- "xxx",
- {""});
- };
+BackupItem
+generateBackupItem(const std::string &userID, const std::string &backupID) {
+ return BackupItem(
+ userID,
+ backupID,
+ comm::network::getCurrentTimestamp(),
+ "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<std::string> 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<std::string> logIDs1 = {"log001", "log002", "log003"};
+ for (const std::string &logID : logIDs1) {
+ DatabaseManager::getInstance().putLogItem(
+ generateLogItem(backupID1, logID));
+ }
+ std::vector<std::string> logIDs2 = {"log021", "log022"};
+ for (const std::string &logID : logIDs2) {
+ DatabaseManager::getInstance().putLogItem(
+ generateLogItem(backupID2, logID));
+ }
+
+ std::vector<std::shared_ptr<LogItem>> items1 =
+ DatabaseManager::getInstance().findLogItemsForBackup(backupID1);
+
+ std::vector<std::shared_ptr<LogItem>> 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);
+}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 12:40 PM (22 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2575602
Default Alt Text
D3176.diff (2 KB)

Event Timeline