This commit is contained in:
Scott E. Graves 2024-11-13 12:31:10 -06:00
parent 99785c0b41
commit 596b171c2c

View File

@ -1555,53 +1555,54 @@ TEST_F(file_manager_test,
std::uint64_t handle{};
EXPECT_CALL(mp, upload_file).Times(AnyNumber());
const auto source_path = utils::path::combine(cfg->get_cache_directory(),
{utils::create_uuid_string()});
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1U,
now + 2U, false, 1U, "key", 2, now + 3U,
3U, 4U, 0U, source_path, 10U, now + 4U);
EXPECT_CALL(mp, create_file("/test_create.txt", meta))
.WillOnce(Return(api_error::success));
EXPECT_CALL(mp, get_filesystem_item)
.WillRepeatedly([&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;
});
EXPECT_CALL(mp, set_item_meta("/test_create.txt", _))
.WillOnce([](const std::string &,
const api_meta_map &new_meta) -> api_error {
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size() *
4UL,
utils::string::to_uint64(new_meta.at(META_SIZE)));
return api_error::success;
});
{
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)
.WillRepeatedly([&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;
});
std::shared_ptr<i_open_file> open_file;
#if defined(_WIN32)
EXPECT_EQ(api_error::success,
fm.create("/test_create.txt", meta, {}, handle, f));
fm.create("/test_create.txt", meta, {}, handle, open_file));
#else // !defined(_WIN32)
EXPECT_EQ(api_error::success,
fm.create("/test_create.txt", meta, O_RDWR, handle, f));
fm.create("/test_create.txt", meta, O_RDWR, handle, open_file));
#endif // defined(_WIN32)
EXPECT_CALL(mp, set_item_meta("/test_create.txt", _))
.WillOnce([](const std::string &,
const api_meta_map &new_meta) -> api_error {
EXPECT_EQ(
utils::encryption::encrypting_reader::get_data_chunk_size() * 4UL,
utils::string::to_uint64(new_meta.at(META_SIZE)));
return api_error::success;
});
f->resize(utils::encryption::encrypting_reader::get_data_chunk_size() *
4UL);
EXPECT_EQ(
api_error::success,
open_file->resize(
utils::encryption::encrypting_reader::get_data_chunk_size() * 4UL));
auto read_state = f->get_read_state();
EXPECT_TRUE(read_state.all());
EXPECT_TRUE(open_file->get_read_state().all());
}
fm.close(handle);