added test

This commit is contained in:
Scott E. Graves 2024-10-28 14:36:38 -05:00
parent ab0b1b645b
commit 79c72d1aef

View File

@ -1535,4 +1535,74 @@ TEST_F(file_manager_test, remove_file_fails_if_provider_remove_file_fails) {
EXPECT_EQ(api_error::item_not_found, fm.remove_file("/test_remove.txt"));
}
TEST_F(file_manager_test,
resize_greater_than_chunk_size_sets_new_chunks_to_read) {
cfg->set_enable_chunk_downloader_timeout(true);
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
polling::instance().start(cfg.get());
file_manager fm(*cfg, mp);
fm.start();
event_capture capture({
"item_timeout",
"filesystem_item_opened",
"filesystem_item_handle_opened",
"filesystem_item_handle_closed",
"filesystem_item_closed",
});
std::uint64_t handle{};
{
const auto source_path = utils::path::combine(
cfg->get_cache_directory(), {utils::create_uuid_string()});
std::shared_ptr<i_open_file> f;
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "key", 2, now + 3u,
3u, 4u, 0u, source_path, 10, now + 4u);
EXPECT_CALL(mp, create_file("/test_create.txt", meta))
.WillOnce(Return(api_error::success));
EXPECT_CALL(mp, get_filesystem_item)
.WillOnce([&meta](const std::string &api_path, bool directory,
filesystem_item &fsi) -> api_error {
EXPECT_STREQ("/test_create.txt", api_path.c_str());
EXPECT_FALSE(directory);
fsi.api_path = api_path;
fsi.api_parent = utils::path::get_parent_api_path(api_path);
fsi.directory = directory;
fsi.size = utils::string::to_uint64(meta[META_SIZE]);
fsi.source_path = meta[META_SOURCE];
return api_error::success;
});
#if defined(_WIN32)
EXPECT_EQ(api_error::success,
fm.create("/test_create.txt", meta, {}, handle, f));
#else
EXPECT_EQ(api_error::success,
fm.create("/test_create.txt", meta, O_RDWR, handle, f));
#endif
f->resize(utils::encryption::encrypting_reader::get_data_chunk_size() *
4UL);
auto read_state = f->get_read_state();
EXPECT_TRUE(read_state.all());
}
fm.close(handle);
capture.wait_for_empty();
fm.stop();
polling::instance().stop();
}
} // namespace repertory