unit tests and fixes
This commit is contained in:
@ -158,6 +158,10 @@ auto file_manager::evict_file(const std::string &api_path) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fsi.source_path.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string pinned;
|
||||
res = provider_.get_item_meta(api_path, META_PINNED, pinned);
|
||||
if (res != api_error::success && res != api_error::item_not_found) {
|
||||
@ -170,17 +174,6 @@ auto file_manager::evict_file(const std::string &api_path) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string source_path{};
|
||||
res = provider_.get_item_meta(api_path, META_SOURCE, source_path);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(std::string{function_name}, api_path,
|
||||
res, "failed to get source path");
|
||||
return false;
|
||||
}
|
||||
if (source_path.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<i_closeable_open_file> closeable_file;
|
||||
if (open_file_lookup_.contains(api_path)) {
|
||||
closeable_file = open_file_lookup_.at(api_path);
|
||||
@ -192,11 +185,11 @@ auto file_manager::evict_file(const std::string &api_path) -> bool {
|
||||
auto allocated = closeable_file ? closeable_file->get_allocated() : true;
|
||||
closeable_file.reset();
|
||||
|
||||
auto removed = remove_source_and_shrink_cache(api_path, source_path, fsi.size,
|
||||
allocated);
|
||||
auto removed = remove_source_and_shrink_cache(api_path, fsi.source_path,
|
||||
fsi.size, allocated);
|
||||
if (removed) {
|
||||
event_system::instance().raise<filesystem_item_evicted>(api_path,
|
||||
source_path);
|
||||
fsi.source_path);
|
||||
}
|
||||
|
||||
return removed;
|
||||
|
@ -728,15 +728,6 @@ TEST_F(file_manager_test, can_evict_file) {
|
||||
EXPECT_TRUE(utils::retry_action(
|
||||
[&mgr]() -> bool { return not mgr.is_processing("/test_evict.txt"); }));
|
||||
|
||||
EXPECT_CALL(mp, get_item_meta(_, META_SOURCE, _))
|
||||
.WillOnce([&source_path](const std::string &api_path,
|
||||
const std::string &key,
|
||||
std::string &value) -> api_error {
|
||||
EXPECT_STREQ("/test_evict.txt", api_path.c_str());
|
||||
EXPECT_STREQ(META_SOURCE.c_str(), key.c_str());
|
||||
value = source_path;
|
||||
return api_error::success;
|
||||
});
|
||||
EXPECT_CALL(mp, get_item_meta(_, META_PINNED, _))
|
||||
.WillOnce([](const std::string &api_path, const std::string &key,
|
||||
std::string &value) -> api_error {
|
||||
@ -813,28 +804,16 @@ TEST_F(file_manager_test, evict_file_fails_if_file_is_open) {
|
||||
mgr.close(handle);
|
||||
}
|
||||
|
||||
TEST_F(file_manager_test,
|
||||
evict_file_fails_if_unable_to_get_source_path_from_item_meta) {
|
||||
TEST_F(file_manager_test, evict_file_fails_if_unable_to_get_filesystem_item) {
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
file_manager mgr(*cfg, mp);
|
||||
|
||||
EXPECT_CALL(mp, get_item_meta(_, META_SOURCE, _))
|
||||
.WillOnce([](const std::string &api_path, const std::string &key,
|
||||
std::string & /*value*/) -> api_error {
|
||||
EXPECT_STREQ("/test_open.txt", api_path.c_str());
|
||||
EXPECT_STREQ(META_SOURCE.c_str(), key.c_str());
|
||||
EXPECT_CALL(mp, get_filesystem_item)
|
||||
.WillRepeatedly([&meta](const std::string &api_path, bool directory,
|
||||
filesystem_item &fsi) -> api_error {
|
||||
return api_error::error;
|
||||
});
|
||||
|
||||
EXPECT_CALL(mp, get_item_meta(_, META_PINNED, _))
|
||||
.WillOnce([](const std::string &api_path, const std::string &key,
|
||||
std::string &value) -> api_error {
|
||||
EXPECT_STREQ("/test_open.txt", api_path.c_str());
|
||||
EXPECT_STREQ(META_PINNED.c_str(), key.c_str());
|
||||
value = "0";
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
EXPECT_FALSE(mgr.evict_file("/test_open.txt"));
|
||||
}
|
||||
|
||||
@ -842,20 +821,13 @@ TEST_F(file_manager_test, evict_file_fails_if_source_path_is_empty) {
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
file_manager mgr(*cfg, mp);
|
||||
|
||||
EXPECT_CALL(mp, get_item_meta(_, META_SOURCE, _))
|
||||
.WillOnce([](const std::string &api_path, const std::string &key,
|
||||
std::string &value) -> api_error {
|
||||
EXPECT_STREQ("/test_open.txt", api_path.c_str());
|
||||
EXPECT_STREQ(META_SOURCE.c_str(), key.c_str());
|
||||
value = "";
|
||||
return api_error::success;
|
||||
});
|
||||
EXPECT_CALL(mp, get_item_meta(_, META_PINNED, _))
|
||||
.WillOnce([](const std::string &api_path, const std::string &key,
|
||||
std::string &value) -> api_error {
|
||||
EXPECT_STREQ("/test_open.txt", api_path.c_str());
|
||||
EXPECT_STREQ(META_PINNED.c_str(), key.c_str());
|
||||
value = "0";
|
||||
EXPECT_CALL(mp, get_filesystem_item)
|
||||
.WillRepeatedly([&meta](const std::string &api_path, bool directory,
|
||||
filesystem_item &fsi) -> api_error {
|
||||
fsi.api_path = api_path;
|
||||
fsi.api_parent = utils::path::get_parent_api_path(api_path);
|
||||
fsi.directory = directory;
|
||||
fsi.size = 20U;
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user