meta db unit tests and fixes
This commit is contained in:
		| @@ -375,12 +375,14 @@ auto rdb_meta_db::update_item_meta(const std::string &api_path, json json_data) | ||||
|  | ||||
|     auto directory = | ||||
|         utils::string::to_bool(json_data.at(META_DIRECTORY).get<std::string>()); | ||||
|     auto pinned = | ||||
|         utils::string::to_bool(json_data.at(META_PINNED).get<std::string>()); | ||||
|     auto pinned = directory ? false | ||||
|                             : utils::string::to_bool( | ||||
|                                   json_data.at(META_PINNED).get<std::string>()); | ||||
|     auto size = directory ? std::uint64_t(0U) | ||||
|                           : utils::string::to_uint64( | ||||
|                                 json_data.at(META_SIZE).get<std::string>()); | ||||
|     auto source_path = json_data.at(META_SOURCE).get<std::string>(); | ||||
|     auto source_path = | ||||
|         directory ? "" : json_data.at(META_SOURCE).get<std::string>(); | ||||
|     if (orig_source_path != source_path && not orig_source_path.empty()) { | ||||
|       ret = perform_action(function_name, [&]() -> rocksdb::Status { | ||||
|         return db_->Delete(rocksdb::WriteOptions(), source_family_, | ||||
|   | ||||
| @@ -318,10 +318,11 @@ auto sqlite_meta_db::update_item_meta(const std::string &api_path, | ||||
|     } | ||||
|  | ||||
|     auto directory = utils::string::to_bool(meta.at(META_DIRECTORY)); | ||||
|     auto pinned = utils::string::to_bool(meta.at(META_PINNED)); | ||||
|     auto pinned = | ||||
|         directory ? false : utils::string::to_bool(meta.at(META_PINNED)); | ||||
|     auto size = directory ? std::uint64_t(0U) | ||||
|                           : utils::string::to_uint64(meta.at(META_SIZE)); | ||||
|     auto source_path = meta.at(META_SOURCE); | ||||
|     auto source_path = directory ? "" : meta.at(META_SOURCE); | ||||
|  | ||||
|     meta.erase(META_DIRECTORY); | ||||
|     meta.erase(META_PINNED); | ||||
|   | ||||
| @@ -76,7 +76,7 @@ TYPED_TEST(meta_db_test, can_change_source_path) { | ||||
| } | ||||
|  | ||||
| TYPED_TEST(meta_db_test, | ||||
|            get_api_path_return_item_not_found_if_source_does_not_exist) { | ||||
|            get_api_path_returns_item_not_found_if_source_does_not_exist) { | ||||
|   std::string api_path; | ||||
|   EXPECT_EQ(api_error::item_not_found, | ||||
|             this->meta_db->get_api_path(create_test_file(), api_path)); | ||||
| @@ -93,4 +93,80 @@ TYPED_TEST(meta_db_test, set_item_meta_fails_with_missing_directory_meta) { | ||||
|   EXPECT_EQ(api_error::error, | ||||
|             this->meta_db->set_item_meta(test_file, META_SOURCE, test_source)); | ||||
| } | ||||
|  | ||||
| TYPED_TEST(meta_db_test, can_get_api_file_list) { | ||||
|   std::vector<std::string> directories{}; | ||||
|   for (auto idx = 0U; idx < 5U; ++idx) { | ||||
|     auto test_dir = create_test_file(); | ||||
|     directories.push_back(test_dir); | ||||
|     EXPECT_EQ( | ||||
|         api_error::success, | ||||
|         this->meta_db->set_item_meta( | ||||
|             test_dir, { | ||||
|                           {META_DIRECTORY, utils::string::from_bool(true)}, | ||||
|                       })); | ||||
|   } | ||||
|  | ||||
|   std::vector<std::string> files{}; | ||||
|   for (auto idx = 0U; idx < 5U; ++idx) { | ||||
|     auto test_file = create_test_file(); | ||||
|     files.push_back(test_file); | ||||
|     EXPECT_EQ( | ||||
|         api_error::success, | ||||
|         this->meta_db->set_item_meta( | ||||
|             test_file, { | ||||
|                            {META_DIRECTORY, utils::string::from_bool(false)}, | ||||
|                        })); | ||||
|   } | ||||
|  | ||||
|   auto file_list = this->meta_db->get_api_path_list(); | ||||
|   for (const auto &api_path : directories) { | ||||
|     EXPECT_TRUE(utils::collection::includes(file_list, api_path)); | ||||
|   } | ||||
|  | ||||
|   for (const auto &api_path : files) { | ||||
|     EXPECT_TRUE(utils::collection::includes(file_list, api_path)); | ||||
|   } | ||||
| } | ||||
|  | ||||
| TYPED_TEST(meta_db_test, can_get_full_item_meta_for_directory) { | ||||
|   auto api_path = create_test_file(); | ||||
|   auto source_path = create_test_file(); | ||||
|   EXPECT_EQ(api_error::success, | ||||
|             this->meta_db->set_item_meta( | ||||
|                 api_path, { | ||||
|                               {META_DIRECTORY, utils::string::from_bool(true)}, | ||||
|                               {META_PINNED, utils::string::from_bool(true)}, | ||||
|                               {META_SIZE, std::to_string(2ULL)}, | ||||
|                               {META_SOURCE, source_path}, | ||||
|                           })); | ||||
|   api_meta_map meta; | ||||
|   EXPECT_EQ(api_error::success, this->meta_db->get_item_meta(api_path, meta)); | ||||
|  | ||||
|   EXPECT_TRUE(utils::string::to_bool(meta[META_DIRECTORY])); | ||||
|   EXPECT_FALSE(utils::string::to_bool(meta[META_PINNED])); | ||||
|   EXPECT_EQ(0U, utils::string::to_uint64(meta[META_SIZE])); | ||||
|   EXPECT_TRUE(meta[META_SOURCE].empty()); | ||||
| } | ||||
|  | ||||
| TYPED_TEST(meta_db_test, can_get_full_item_meta_for_file) { | ||||
|   auto api_path = create_test_file(); | ||||
|   auto source_path = create_test_file(); | ||||
|   EXPECT_EQ(api_error::success, | ||||
|             this->meta_db->set_item_meta( | ||||
|                 api_path, { | ||||
|                               {META_DIRECTORY, utils::string::from_bool(false)}, | ||||
|                               {META_PINNED, utils::string::from_bool(true)}, | ||||
|                               {META_SIZE, std::to_string(2ULL)}, | ||||
|                               {META_SOURCE, source_path}, | ||||
|                           })); | ||||
|  | ||||
|   api_meta_map meta; | ||||
|   EXPECT_EQ(api_error::success, this->meta_db->get_item_meta(api_path, meta)); | ||||
|  | ||||
|   EXPECT_FALSE(utils::string::to_bool(meta[META_DIRECTORY])); | ||||
|   EXPECT_TRUE(utils::string::to_bool(meta[META_PINNED])); | ||||
|   EXPECT_EQ(2ULL, utils::string::to_uint64(meta[META_SIZE])); | ||||
|   EXPECT_STREQ(source_path.c_str(), meta[META_SOURCE].c_str()); | ||||
| } | ||||
| } // namespace repertory | ||||
|   | ||||
		Reference in New Issue
	
	Block a user