[unit test] Complete all providers unit tests #12
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
Blockstorage/repertory/pipeline/head There was a failure building this commit

This commit is contained in:
2025-09-16 10:36:23 -05:00
parent 66b3a0595d
commit 816d242234
3 changed files with 32 additions and 11 deletions

View File

@@ -794,10 +794,10 @@ static void get_filesystem_item(i_provider &provider) {
auto api_path = list.front().api_path;
filesystem_item fsi{};
res = provider.get_filesystem_item(api_path, fsi);
res = provider.get_filesystem_item(api_path, false, fsi);
EXPECT_EQ(api_error::success, res);
EXPECT_FALSE(fsi.is_directory);
EXPECT_FALSE(fsi.directory);
EXPECT_EQ(api_path, fsi.api_path);
std::uint64_t size{};
@@ -817,10 +817,10 @@ static void get_filesystem_item(i_provider &provider) {
ASSERT_EQ(api_error::success, res);
filesystem_item fsi{};
res = provider.get_filesystem_item(api_path, fsi);
res = provider.get_filesystem_item(api_path, false, fsi);
EXPECT_EQ(api_error::success, res);
EXPECT_EQ(api_path, fsi.api_path);
EXPECT_FALSE(fsi.is_directory);
EXPECT_FALSE(fsi.directory);
EXPECT_EQ(*src.size(), fsi.file_size);
res = provider.remove_file(api_path);
@@ -833,23 +833,35 @@ static void get_filesystem_item_root_is_directory(i_provider &provider) {
__FUNCTION__);
filesystem_item fsi{};
auto res = provider.get_filesystem_item("/", fsi);
auto res = provider.get_filesystem_item("/", true, fsi);
EXPECT_EQ(api_error::success, res);
EXPECT_TRUE(fsi.is_directory);
EXPECT_TRUE(fsi.directory);
EXPECT_EQ("/", fsi.api_path);
}
static void get_filesystem_item_fails_if_path_not_found(i_provider &provider) {
static void
get_filesystem_item_fails_if_file_is_not_found(i_provider &provider) {
fmt::println("testing|{}|{}",
app_config::get_provider_name(provider.get_provider_type()),
__FUNCTION__);
filesystem_item fsi{};
auto res = provider.get_filesystem_item("/cow/moose/dog/chicken", fsi);
auto res = provider.get_filesystem_item("/cow/moose/dog/chicken", false, fsi);
EXPECT_EQ(api_error::item_not_found, res);
}
static void
get_filesystem_item_fails_if_directory_is_not_found(i_provider &provider) {
fmt::println("testing|{}|{}",
app_config::get_provider_name(provider.get_provider_type()),
__FUNCTION__);
filesystem_item fsi{};
auto res = provider.get_filesystem_item("/cow/moose/dog/chicken", true, fsi);
EXPECT_EQ(api_error::directory_not_found, res);
}
static void run_tests(const app_config &cfg, i_provider &provider) {
get_file_list(cfg, provider);
ASSERT_FALSE(::testing::Test::HasFailure());

View File

@@ -174,6 +174,10 @@ public:
calculate_encrypted_size(std::string_view source_path, bool uses_kdf)
-> std::uint64_t;
[[nodiscard]] static auto calculate_encrypted_size(std::uint64_t size,
bool uses_kdf)
-> std::uint64_t;
[[nodiscard]] auto create_iostream() const -> std::shared_ptr<iostream>;
[[nodiscard]] static constexpr auto get_encrypted_chunk_size()

View File

@@ -430,11 +430,16 @@ auto encrypting_reader::calculate_encrypted_size(std::string_view source_path,
source_path,
});
}
auto file_size{opt_size.value()};
return calculate_encrypted_size(opt_size.value(), uses_kdf);
}
auto encrypting_reader::calculate_encrypted_size(std::uint64_t size,
bool uses_kdf)
-> std::uint64_t {
auto total_chunks = utils::divide_with_ceiling(
file_size, static_cast<std::uint64_t>(data_chunk_size_));
return file_size + (total_chunks * encryption_header_size) +
size, static_cast<std::uint64_t>(data_chunk_size_));
return size + (total_chunks * encryption_header_size) +
(uses_kdf ? kdf_config::size() : 0U);
}