[Unit Test] Complete all providers unit tests #12
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
This commit is contained in:
parent
d795e97412
commit
987fca8f79
@ -495,7 +495,19 @@ auto s3_provider::get_file(const std::string &api_path, api_file &file) const
|
||||
get_object_info(false, api_path, is_encrypted, object_name, result),
|
||||
};
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
if (res != api_error::item_not_found) {
|
||||
return res;
|
||||
}
|
||||
|
||||
bool exists{};
|
||||
res = is_directory(api_path, exists);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, api_path, res,
|
||||
"failed to determine if directory exists");
|
||||
}
|
||||
|
||||
return exists ? api_error::directory_exists : api_error::item_not_found;
|
||||
}
|
||||
|
||||
file.api_path = api_path;
|
||||
|
@ -206,16 +206,30 @@ auto sia_provider::get_file(const std::string &api_path, api_file &file) const
|
||||
json file_data{};
|
||||
auto res{get_object_info(api_path, file_data)};
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
if (res != api_error::item_not_found) {
|
||||
return res;
|
||||
}
|
||||
|
||||
bool exists{};
|
||||
res = is_directory(api_path, exists);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, api_path, res,
|
||||
"failed to determine if directory exists");
|
||||
}
|
||||
|
||||
return exists ? api_error::directory_exists : api_error::item_not_found;
|
||||
}
|
||||
|
||||
auto slabs{file_data["object"]["Slabs"]};
|
||||
auto size{
|
||||
std::accumulate(
|
||||
slabs.begin(), slabs.end(), std::uint64_t(0U),
|
||||
[](auto &&total_size, const json &slab) -> std::uint64_t {
|
||||
return total_size + slab["Length"].get<std::uint64_t>();
|
||||
}),
|
||||
file_data["object"].contains("Slabs")
|
||||
? std::accumulate(
|
||||
file_data["object"]["Slabs"].begin(),
|
||||
file_data["object"]["Slabs"].end(), std::uint64_t(0U),
|
||||
[](auto &&total_size, const json &slab) -> std::uint64_t {
|
||||
return total_size + slab["Length"].get<std::uint64_t>();
|
||||
})
|
||||
: file_data["object"]["size"].get<std::uint64_t>(),
|
||||
};
|
||||
|
||||
api_meta_map meta{};
|
||||
|
@ -640,6 +640,24 @@ static void get_file(const app_config &cfg, i_provider &provider) {
|
||||
EXPECT_STREQ(source_path.c_str(), file.source_path.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
create_file(provider, "/pt01.txt");
|
||||
|
||||
api_file file{};
|
||||
EXPECT_EQ(api_error::success, provider.get_file("/pt01.txt", file));
|
||||
|
||||
EXPECT_STREQ("/pt01.txt", file.api_path.c_str());
|
||||
EXPECT_STREQ("/", file.api_parent.c_str());
|
||||
EXPECT_LT(utils::time::get_time_now() - (utils::time::NANOS_PER_SECOND * 5U),
|
||||
file.accessed_date);
|
||||
EXPECT_LT(utils::time::get_time_now() - (utils::time::NANOS_PER_SECOND * 5U),
|
||||
file.changed_date);
|
||||
EXPECT_LT(utils::time::get_time_now() - (utils::time::NANOS_PER_SECOND * 5U),
|
||||
file.creation_date);
|
||||
EXPECT_LT(utils::time::get_time_now() - (utils::time::NANOS_PER_SECOND * 5U),
|
||||
file.modified_date);
|
||||
|
||||
EXPECT_EQ(api_error::success, provider.remove_file("/pt01.txt"));
|
||||
}
|
||||
|
||||
static void get_file_fails_if_file_not_found(i_provider &provider) {
|
||||
@ -667,6 +685,13 @@ static void get_file_fails_if_item_is_directory(const app_config &cfg,
|
||||
EXPECT_EQ(api_error::directory_exists, provider.get_file(api_path, file));
|
||||
return;
|
||||
}
|
||||
|
||||
create_directory(provider, "/dir01");
|
||||
|
||||
api_file file{};
|
||||
EXPECT_EQ(api_error::directory_exists, provider.get_file("/dir01", file));
|
||||
|
||||
EXPECT_EQ(api_error::success, provider.remove_directory("/dir01"));
|
||||
}
|
||||
|
||||
static void get_file_list(const app_config &cfg, i_provider &provider) {
|
||||
@ -723,7 +748,6 @@ static void run_tests(const app_config &cfg, i_provider &provider) {
|
||||
|
||||
get_directory_item_count(cfg, provider);
|
||||
|
||||
// TODO continue here
|
||||
get_file(cfg, provider);
|
||||
get_file_fails_if_file_not_found(provider);
|
||||
get_file_fails_if_item_is_directory(cfg, provider);
|
||||
|
Loading…
x
Reference in New Issue
Block a user