[unit test] Complete all providers unit tests #12
This commit is contained in:
@@ -794,10 +794,10 @@ static void get_filesystem_item(i_provider &provider) {
|
|||||||
auto api_path = list.front().api_path;
|
auto api_path = list.front().api_path;
|
||||||
|
|
||||||
filesystem_item fsi{};
|
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_error::success, res);
|
||||||
|
|
||||||
EXPECT_FALSE(fsi.is_directory);
|
EXPECT_FALSE(fsi.directory);
|
||||||
EXPECT_EQ(api_path, fsi.api_path);
|
EXPECT_EQ(api_path, fsi.api_path);
|
||||||
|
|
||||||
std::uint64_t size{};
|
std::uint64_t size{};
|
||||||
@@ -817,10 +817,10 @@ static void get_filesystem_item(i_provider &provider) {
|
|||||||
ASSERT_EQ(api_error::success, res);
|
ASSERT_EQ(api_error::success, res);
|
||||||
|
|
||||||
filesystem_item fsi{};
|
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_error::success, res);
|
||||||
EXPECT_EQ(api_path, fsi.api_path);
|
EXPECT_EQ(api_path, fsi.api_path);
|
||||||
EXPECT_FALSE(fsi.is_directory);
|
EXPECT_FALSE(fsi.directory);
|
||||||
EXPECT_EQ(*src.size(), fsi.file_size);
|
EXPECT_EQ(*src.size(), fsi.file_size);
|
||||||
|
|
||||||
res = provider.remove_file(api_path);
|
res = provider.remove_file(api_path);
|
||||||
@@ -833,23 +833,35 @@ static void get_filesystem_item_root_is_directory(i_provider &provider) {
|
|||||||
__FUNCTION__);
|
__FUNCTION__);
|
||||||
|
|
||||||
filesystem_item fsi{};
|
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_EQ(api_error::success, res);
|
||||||
EXPECT_TRUE(fsi.is_directory);
|
EXPECT_TRUE(fsi.directory);
|
||||||
EXPECT_EQ("/", fsi.api_path);
|
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|{}|{}",
|
fmt::println("testing|{}|{}",
|
||||||
app_config::get_provider_name(provider.get_provider_type()),
|
app_config::get_provider_name(provider.get_provider_type()),
|
||||||
__FUNCTION__);
|
__FUNCTION__);
|
||||||
|
|
||||||
filesystem_item fsi{};
|
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);
|
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) {
|
static void run_tests(const app_config &cfg, i_provider &provider) {
|
||||||
get_file_list(cfg, provider);
|
get_file_list(cfg, provider);
|
||||||
ASSERT_FALSE(::testing::Test::HasFailure());
|
ASSERT_FALSE(::testing::Test::HasFailure());
|
||||||
|
@@ -174,6 +174,10 @@ public:
|
|||||||
calculate_encrypted_size(std::string_view source_path, bool uses_kdf)
|
calculate_encrypted_size(std::string_view source_path, bool uses_kdf)
|
||||||
-> std::uint64_t;
|
-> 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]] auto create_iostream() const -> std::shared_ptr<iostream>;
|
||||||
|
|
||||||
[[nodiscard]] static constexpr auto get_encrypted_chunk_size()
|
[[nodiscard]] static constexpr auto get_encrypted_chunk_size()
|
||||||
|
@@ -430,11 +430,16 @@ auto encrypting_reader::calculate_encrypted_size(std::string_view source_path,
|
|||||||
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(
|
auto total_chunks = utils::divide_with_ceiling(
|
||||||
file_size, static_cast<std::uint64_t>(data_chunk_size_));
|
size, static_cast<std::uint64_t>(data_chunk_size_));
|
||||||
return file_size + (total_chunks * encryption_header_size) +
|
return size + (total_chunks * encryption_header_size) +
|
||||||
(uses_kdf ? kdf_config::size() : 0U);
|
(uses_kdf ? kdf_config::size() : 0U);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user