meta db unit tests and fixes

This commit is contained in:
Scott E. Graves 2024-12-04 12:16:42 -06:00
parent 5f51a9384e
commit c6b895ced2

View File

@ -119,6 +119,8 @@ auto rdb_meta_db::get_item_meta_json(const std::string &api_path,
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
auto found{false};
{ {
std::string value; std::string value;
auto res = perform_action(__FUNCTION__, [&]() -> rocksdb::Status { auto res = perform_action(__FUNCTION__, [&]() -> rocksdb::Status {
@ -129,12 +131,11 @@ auto rdb_meta_db::get_item_meta_json(const std::string &api_path,
return res; return res;
} }
if (value.empty()) { found = not value.empty();
return api_error::item_not_found; if (found) {
}
json_data = json::parse(value); json_data = json::parse(value);
} }
}
{ {
std::string value; std::string value;
@ -146,6 +147,7 @@ auto rdb_meta_db::get_item_meta_json(const std::string &api_path,
return res; return res;
} }
json_data[META_DIRECTORY] = value; json_data[META_DIRECTORY] = value;
found = found || not value.empty();
} }
{ {
@ -157,6 +159,7 @@ auto rdb_meta_db::get_item_meta_json(const std::string &api_path,
return res; return res;
} }
json_data[META_KEY] = value; json_data[META_KEY] = value;
found = found || not value.empty();
} }
{ {
@ -169,6 +172,7 @@ auto rdb_meta_db::get_item_meta_json(const std::string &api_path,
return res; return res;
} }
json_data[META_PINNED] = value; json_data[META_PINNED] = value;
found = found || not value.empty();
} }
{ {
@ -180,6 +184,7 @@ auto rdb_meta_db::get_item_meta_json(const std::string &api_path,
return res; return res;
} }
json_data[META_SIZE] = value; json_data[META_SIZE] = value;
found = found || not value.empty();
} }
{ {
@ -192,9 +197,10 @@ auto rdb_meta_db::get_item_meta_json(const std::string &api_path,
return res; return res;
} }
json_data[META_SOURCE] = value; json_data[META_SOURCE] = value;
found = found || not value.empty();
} }
return api_error::success; return found ? api_error::success : api_error::item_not_found;
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::raise_api_path_error(function_name, api_path, e, utils::error::raise_api_path_error(function_name, api_path, e,
"failed to get item meta"); "failed to get item meta");