[unit test] Complete all providers unit tests #12
This commit is contained in:
@@ -173,6 +173,35 @@ const auto decrypt_parts = [](const repertory::app_config &cfg,
|
|||||||
path = repertory::utils::string::join(parts, '/');
|
path = repertory::utils::string::join(parts, '/');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] auto read_all_plain(const std::string &path) -> std::string {
|
||||||
|
repertory::utils::file::file file{path};
|
||||||
|
auto data = file.read_all();
|
||||||
|
EXPECT_TRUE(data.has_value());
|
||||||
|
return data.value_or(std::string{});
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto chunked_read_bytes(repertory::i_provider &provider,
|
||||||
|
const std::string &api_path,
|
||||||
|
std::uint64_t total) -> std::string {
|
||||||
|
std::string out{};
|
||||||
|
std::uint64_t off = 0U;
|
||||||
|
static constexpr std::uint64_t chunks[] = {1U, 7U, 64U, 3U, 1024U, 5U};
|
||||||
|
std::size_t idx = 0U;
|
||||||
|
|
||||||
|
while (off < total) {
|
||||||
|
const auto want =
|
||||||
|
std::min<std::uint64_t>(chunks[idx % std::size(chunks)], total - off);
|
||||||
|
std::string part{};
|
||||||
|
EXPECT_EQ(api_error::success,
|
||||||
|
provider.read_file_bytes(api_path, off, want, part));
|
||||||
|
EXPECT_EQ(want, static_cast<std::uint64_t>(part.size()));
|
||||||
|
out.append(part);
|
||||||
|
off += want;
|
||||||
|
++idx;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
@@ -1139,7 +1168,7 @@ static void get_pinned_files(i_provider &provider) {
|
|||||||
app_config::get_provider_name(provider.get_provider_type()),
|
app_config::get_provider_name(provider.get_provider_type()),
|
||||||
__FUNCTION__);
|
__FUNCTION__);
|
||||||
if (provider.is_read_only()) {
|
if (provider.is_read_only()) {
|
||||||
auto pinned= provider.get_pinned_files());
|
auto pinned = provider.get_pinned_files();
|
||||||
EXPECT_TRUE(pinned.empty());
|
EXPECT_TRUE(pinned.empty());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1306,14 +1335,12 @@ static void get_used_drive_space(i_provider &provider) {
|
|||||||
sum_sizes += size;
|
sum_sizes += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint64_t used{};
|
std::uint64_t used{provider.get_used_drive_space()};
|
||||||
EXPECT_EQ(api_error::success, provider.get_used_drive_space(used));
|
|
||||||
EXPECT_EQ(sum_sizes, used);
|
EXPECT_EQ(sum_sizes, used);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint64_t before{};
|
std::uint64_t before{provider.get_used_drive_space()};
|
||||||
EXPECT_EQ(api_error::success, provider.get_used_drive_space(before));
|
|
||||||
|
|
||||||
auto &file1 = test::create_random_file(96U);
|
auto &file1 = test::create_random_file(96U);
|
||||||
auto &file2 = test::create_random_file(128U);
|
auto &file2 = test::create_random_file(128U);
|
||||||
@@ -1339,15 +1366,13 @@ static void get_used_drive_space(i_provider &provider) {
|
|||||||
provider.set_item_meta(api_path2, META_SIZE,
|
provider.set_item_meta(api_path2, META_SIZE,
|
||||||
std::to_string(*file2.size())));
|
std::to_string(*file2.size())));
|
||||||
|
|
||||||
std::uint64_t mid{};
|
std::uint64_t mid{provider.get_used_drive_space()};
|
||||||
EXPECT_EQ(api_error::success, provider.get_used_drive_space(mid));
|
|
||||||
EXPECT_EQ(before + *file1.size() + *file2.size(), mid);
|
EXPECT_EQ(before + *file1.size() + *file2.size(), mid);
|
||||||
|
|
||||||
EXPECT_EQ(api_error::success, provider.remove_file(api_path1));
|
EXPECT_EQ(api_error::success, provider.remove_file(api_path1));
|
||||||
EXPECT_EQ(api_error::success, provider.remove_file(api_path2));
|
EXPECT_EQ(api_error::success, provider.remove_file(api_path2));
|
||||||
|
|
||||||
std::uint64_t after{};
|
std::uint64_t after{provider.get_used_drive_space()};
|
||||||
EXPECT_EQ(api_error::success, provider.get_used_drive_space(after));
|
|
||||||
EXPECT_EQ(before, after);
|
EXPECT_EQ(before, after);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1360,8 +1385,7 @@ static void get_total_drive_space(i_provider &provider) {
|
|||||||
auto res_total = provider.get_total_drive_space(total);
|
auto res_total = provider.get_total_drive_space(total);
|
||||||
EXPECT_EQ(api_error::success, res_total);
|
EXPECT_EQ(api_error::success, res_total);
|
||||||
|
|
||||||
std::uint64_t used{};
|
std::uint64_t used{provider.get_used_drive_space(used)};
|
||||||
EXPECT_EQ(api_error::success, provider.get_used_drive_space(used));
|
|
||||||
|
|
||||||
if (total != 0U) {
|
if (total != 0U) {
|
||||||
EXPECT_GE(total, used);
|
EXPECT_GE(total, used);
|
||||||
|
Reference in New Issue
Block a user