meta db unit tests and fixes

This commit is contained in:
Scott E. Graves 2024-12-05 07:00:16 -06:00
parent 3959067f22
commit 161208a1fd

View File

@ -169,4 +169,84 @@ TYPED_TEST(meta_db_test, can_get_full_item_meta_for_file) {
EXPECT_EQ(2ULL, utils::string::to_uint64(meta[META_SIZE])); EXPECT_EQ(2ULL, utils::string::to_uint64(meta[META_SIZE]));
EXPECT_STREQ(source_path.c_str(), meta[META_SOURCE].c_str()); EXPECT_STREQ(source_path.c_str(), meta[META_SOURCE].c_str());
} }
TYPED_TEST(meta_db_test, can_get_individual_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},
}));
{
std::string value;
EXPECT_EQ(api_error::success,
this->meta_db->get_item_meta(api_path, META_DIRECTORY, value));
EXPECT_TRUE(utils::string::to_bool(value));
}
{
std::string value;
EXPECT_EQ(api_error::success,
this->meta_db->get_item_meta(api_path, META_PINNED, value));
EXPECT_FALSE(utils::string::to_bool(value));
}
{
std::string value;
EXPECT_EQ(api_error::success,
this->meta_db->get_item_meta(api_path, META_SIZE, value));
EXPECT_EQ(0ULL, utils::string::to_uint64(value));
}
{
std::string value;
EXPECT_EQ(api_error::success,
this->meta_db->get_item_meta(api_path, META_SOURCE, value));
EXPECT_TRUE(value.empty());
}
}
TYPED_TEST(meta_db_test, can_get_individual_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},
}));
{
std::string value;
EXPECT_EQ(api_error::success,
this->meta_db->get_item_meta(api_path, META_DIRECTORY, value));
EXPECT_FALSE(utils::string::to_bool(value));
}
{
std::string value;
EXPECT_EQ(api_error::success,
this->meta_db->get_item_meta(api_path, META_PINNED, value));
EXPECT_TRUE(utils::string::to_bool(value));
}
{
std::string value;
EXPECT_EQ(api_error::success,
this->meta_db->get_item_meta(api_path, META_SIZE, value));
EXPECT_EQ(2ULL, utils::string::to_uint64(value));
}
{
std::string value;
EXPECT_EQ(api_error::success,
this->meta_db->get_item_meta(api_path, META_SOURCE, value));
EXPECT_STREQ(source_path.c_str(), value.c_str());
}
}
} // namespace repertory } // namespace repertory