[unit test] Complete all providers unit tests #12
This commit is contained in:
@@ -164,11 +164,6 @@ public:
|
|||||||
filesystem_item &fsi) const
|
filesystem_item &fsi) const
|
||||||
-> api_error override;
|
-> api_error override;
|
||||||
|
|
||||||
[[nodiscard]] auto get_filesystem_item_and_file(const std::string &api_path,
|
|
||||||
api_file &f,
|
|
||||||
filesystem_item &fsi) const
|
|
||||||
-> api_error override;
|
|
||||||
|
|
||||||
[[nodiscard]] auto
|
[[nodiscard]] auto
|
||||||
get_filesystem_item_from_source_path(const std::string &source_path,
|
get_filesystem_item_from_source_path(const std::string &source_path,
|
||||||
filesystem_item &fsi) const
|
filesystem_item &fsi) const
|
||||||
|
@@ -145,11 +145,6 @@ public:
|
|||||||
filesystem_item &fsi) const
|
filesystem_item &fsi) const
|
||||||
-> api_error override;
|
-> api_error override;
|
||||||
|
|
||||||
[[nodiscard]] auto get_filesystem_item_and_file(const std::string &api_path,
|
|
||||||
api_file &file,
|
|
||||||
filesystem_item &fsi) const
|
|
||||||
-> api_error override;
|
|
||||||
|
|
||||||
[[nodiscard]] auto
|
[[nodiscard]] auto
|
||||||
get_filesystem_item_from_source_path(const std::string &source_path,
|
get_filesystem_item_from_source_path(const std::string &source_path,
|
||||||
filesystem_item &fsi) const
|
filesystem_item &fsi) const
|
||||||
|
@@ -79,10 +79,6 @@ public:
|
|||||||
filesystem_item &fsi) const
|
filesystem_item &fsi) const
|
||||||
-> api_error = 0;
|
-> api_error = 0;
|
||||||
|
|
||||||
[[nodiscard]] virtual auto
|
|
||||||
get_filesystem_item_and_file(const std::string &api_path, api_file &file,
|
|
||||||
filesystem_item &fsi) const -> api_error = 0;
|
|
||||||
|
|
||||||
[[nodiscard]] virtual auto
|
[[nodiscard]] virtual auto
|
||||||
get_filesystem_item_from_source_path(const std::string &source_path,
|
get_filesystem_item_from_source_path(const std::string &source_path,
|
||||||
filesystem_item &fsi) const
|
filesystem_item &fsi) const
|
||||||
|
@@ -435,30 +435,6 @@ auto base_provider::get_filesystem_item(const std::string &api_path,
|
|||||||
return api_error::success;
|
return api_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto base_provider::get_filesystem_item_and_file(const std::string &api_path,
|
|
||||||
api_file &file,
|
|
||||||
filesystem_item &fsi) const
|
|
||||||
-> api_error {
|
|
||||||
auto res = get_file(api_path, file);
|
|
||||||
if (res != api_error::success) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
api_meta_map meta{};
|
|
||||||
res = get_item_meta(api_path, meta);
|
|
||||||
if (res != api_error::success) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
fsi.api_parent = utils::path::get_parent_api_path(api_path);
|
|
||||||
fsi.api_path = api_path;
|
|
||||||
fsi.directory = false;
|
|
||||||
fsi.size = utils::string::to_uint64(meta[META_SIZE]);
|
|
||||||
fsi.source_path = meta[META_SOURCE];
|
|
||||||
|
|
||||||
return api_error::success;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto base_provider::get_filesystem_item_from_source_path(
|
auto base_provider::get_filesystem_item_from_source_path(
|
||||||
const std::string &source_path, filesystem_item &fsi) const -> api_error {
|
const std::string &source_path, filesystem_item &fsi) const -> api_error {
|
||||||
std::string api_path{};
|
std::string api_path{};
|
||||||
@@ -467,15 +443,6 @@ auto base_provider::get_filesystem_item_from_source_path(
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool exists{};
|
|
||||||
res = is_directory(api_path, exists);
|
|
||||||
if (res != api_error::success) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
if (exists) {
|
|
||||||
return api_error::directory_exists;
|
|
||||||
}
|
|
||||||
|
|
||||||
return get_filesystem_item(api_path, false, fsi);
|
return get_filesystem_item(api_path, false, fsi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -474,49 +474,9 @@ auto encrypt_provider::get_filesystem_item_from_source_path(
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool exists{};
|
|
||||||
res = is_directory(api_path, exists);
|
|
||||||
if (res != api_error::success) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
if (exists) {
|
|
||||||
return api_error::directory_exists;
|
|
||||||
}
|
|
||||||
|
|
||||||
return get_filesystem_item(api_path, false, fsi);
|
return get_filesystem_item(api_path, false, fsi);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto encrypt_provider::get_filesystem_item_and_file(const std::string &api_path,
|
|
||||||
api_file &file,
|
|
||||||
filesystem_item &fsi) const
|
|
||||||
-> api_error {
|
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
|
||||||
|
|
||||||
try {
|
|
||||||
bool exists{};
|
|
||||||
auto res{is_directory(api_path, exists)};
|
|
||||||
if (res != api_error::success) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
if (exists) {
|
|
||||||
return api_error::directory_exists;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto ret{get_filesystem_item(api_path, exists, fsi)};
|
|
||||||
if (ret != api_error::success) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
file = create_api_file(api_path, false, fsi.source_path);
|
|
||||||
return api_error::success;
|
|
||||||
} catch (const std::exception &ex) {
|
|
||||||
utils::error::raise_error(function_name, ex, api_path,
|
|
||||||
"failed to get filesystem_item and file");
|
|
||||||
}
|
|
||||||
|
|
||||||
return api_error::error;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto encrypt_provider::get_pinned_files() const -> std::vector<std::string> {
|
auto encrypt_provider::get_pinned_files() const -> std::vector<std::string> {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@@ -80,11 +80,6 @@ public:
|
|||||||
filesystem_item &fsi),
|
filesystem_item &fsi),
|
||||||
(const, override));
|
(const, override));
|
||||||
|
|
||||||
MOCK_METHOD(api_error, get_filesystem_item_and_file,
|
|
||||||
(const std::string &api_path, api_file &file,
|
|
||||||
filesystem_item &fsi),
|
|
||||||
(const, override));
|
|
||||||
|
|
||||||
MOCK_METHOD(api_error, get_filesystem_item_from_source_path,
|
MOCK_METHOD(api_error, get_filesystem_item_from_source_path,
|
||||||
(const std::string &source_path, filesystem_item &fsi),
|
(const std::string &source_path, filesystem_item &fsi),
|
||||||
(const, override));
|
(const, override));
|
||||||
|
@@ -745,7 +745,7 @@ static void get_file_size(i_provider &provider) {
|
|||||||
res = provider.get_file_size(list.front().api_path, size);
|
res = provider.get_file_size(list.front().api_path, size);
|
||||||
EXPECT_EQ(api_error::success, res);
|
EXPECT_EQ(api_error::success, res);
|
||||||
EXPECT_EQ(utils::encryption::encrypting_reader::calculate_encrypted_size(
|
EXPECT_EQ(utils::encryption::encrypting_reader::calculate_encrypted_size(
|
||||||
7U, true),
|
8U, true),
|
||||||
size);
|
size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -753,6 +753,7 @@ static void get_file_size(i_provider &provider) {
|
|||||||
auto &file = test::create_random_file(128U);
|
auto &file = test::create_random_file(128U);
|
||||||
auto api_path =
|
auto api_path =
|
||||||
fmt::format("/{}", utils::path::strip_to_file_name(file.get_path()));
|
fmt::format("/{}", utils::path::strip_to_file_name(file.get_path()));
|
||||||
|
create_file(provider, api_path);
|
||||||
|
|
||||||
stop_type stop_requested{false};
|
stop_type stop_requested{false};
|
||||||
auto res = provider.upload_file(api_path, file.get_path(), stop_requested);
|
auto res = provider.upload_file(api_path, file.get_path(), stop_requested);
|
||||||
@@ -811,6 +812,7 @@ static void get_filesystem_item(i_provider &provider) {
|
|||||||
auto &src = test::create_random_file(128U);
|
auto &src = test::create_random_file(128U);
|
||||||
auto api_path =
|
auto api_path =
|
||||||
fmt::format("/{}", utils::path::strip_to_file_name(src.get_path()));
|
fmt::format("/{}", utils::path::strip_to_file_name(src.get_path()));
|
||||||
|
create_file(provider, api_path);
|
||||||
|
|
||||||
stop_type stop_requested{false};
|
stop_type stop_requested{false};
|
||||||
auto res = provider.upload_file(api_path, src.get_path(), stop_requested);
|
auto res = provider.upload_file(api_path, src.get_path(), stop_requested);
|
||||||
@@ -862,6 +864,56 @@ get_filesystem_item_fails_if_directory_is_not_found(i_provider &provider) {
|
|||||||
EXPECT_EQ(api_error::directory_not_found, res);
|
EXPECT_EQ(api_error::directory_not_found, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void get_filesystem_item_from_source_path(const app_config &cfg,
|
||||||
|
i_provider &provider) {
|
||||||
|
fmt::println("testing|{}|{}",
|
||||||
|
app_config::get_provider_name(provider.get_provider_type()),
|
||||||
|
__FUNCTION__);
|
||||||
|
|
||||||
|
std::string api_path;
|
||||||
|
std::string source_path;
|
||||||
|
std::uint64_t size{};
|
||||||
|
if (provider.get_provider_type() == provider_type::encrypt) {
|
||||||
|
source_path =
|
||||||
|
utils::path::combine(cfg.get_encrypt_config().path, "/test.txt");
|
||||||
|
size = utils::encryption::encrypting_reader::calculate_encrypted_size(8U,
|
||||||
|
true);
|
||||||
|
} else {
|
||||||
|
size = 128U;
|
||||||
|
auto &file = test::create_random_file(size);
|
||||||
|
api_path =
|
||||||
|
fmt::format("/{}", utils::path::strip_to_file_name(file.get_path()));
|
||||||
|
create_file(provider, api_path);
|
||||||
|
|
||||||
|
source_path = file.get_path();
|
||||||
|
stop_type stop_requested{false};
|
||||||
|
auto res = provider.upload_file(api_path, source_path, stop_requested);
|
||||||
|
ASSERT_EQ(api_error::success, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
filesystem_item fsi{};
|
||||||
|
auto res = provider.get_filesystem_item_from_source_path(source_path, fsi);
|
||||||
|
EXPECT_EQ(api_error::success, res);
|
||||||
|
EXPECT_FALSE(fsi.directory);
|
||||||
|
EXPECT_EQ(size, fsi.size);
|
||||||
|
|
||||||
|
if (provider.get_provider_type() != provider_type::encrypt) {
|
||||||
|
EXPECT_EQ(api_error::success, provider.remove_file(api_path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void get_filesystem_item_from_source_path_fails_if_file_is_not_found(
|
||||||
|
const app_config &cfg, 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_from_source_path(
|
||||||
|
"/cow/moose/doge/chicken", fsi);
|
||||||
|
EXPECT_EQ(api_error::item_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());
|
||||||
@@ -901,10 +953,11 @@ static void run_tests(const app_config &cfg, i_provider &provider) {
|
|||||||
get_filesystem_item_fails_if_file_is_not_found(provider);
|
get_filesystem_item_fails_if_file_is_not_found(provider);
|
||||||
get_filesystem_item_fails_if_directory_is_not_found(provider);
|
get_filesystem_item_fails_if_directory_is_not_found(provider);
|
||||||
|
|
||||||
|
get_filesystem_item_from_source_path(cfg, provider);
|
||||||
|
get_filesystem_item_from_source_path_fails_if_file_is_not_found(cfg,
|
||||||
|
provider);
|
||||||
// TODO need to test read when file size changes for encrypt provider
|
// TODO need to test read when file size changes for encrypt provider
|
||||||
/*
|
/*
|
||||||
get_filesystem_item_and_file(provider);
|
|
||||||
get_filesystem_item_from_source_path(provider);
|
|
||||||
get_item_meta(provider);
|
get_item_meta(provider);
|
||||||
get_item_meta2(provider);
|
get_item_meta2(provider);
|
||||||
get_pinned_files(provider);
|
get_pinned_files(provider);
|
||||||
|
Reference in New Issue
Block a user