refactor s3 provider
This commit is contained in:
@@ -1,321 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "fixtures/directory_db_fixture.hpp"
|
||||
|
||||
namespace repertory {
|
||||
static const auto dirs = {"/",
|
||||
"/root",
|
||||
"/root/sub1",
|
||||
"/root/sub2",
|
||||
"/root/sub2/sub2_sub1",
|
||||
"/root/sub2/sub2_sub2",
|
||||
"/root/sub2/sub2_sub2/sub2_sub2_sub1",
|
||||
"/root/sub3"};
|
||||
|
||||
TEST_F(directory_db_test, is_directory) {
|
||||
for (const auto &dir : dirs) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory(dir));
|
||||
}
|
||||
|
||||
for (const auto &dir : dirs) {
|
||||
EXPECT_TRUE(db_->is_directory(dir));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, remove_directory) {
|
||||
for (const auto &dir : dirs) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory(dir));
|
||||
}
|
||||
|
||||
EXPECT_EQ(api_error::success, db_->remove_directory("/root/sub2/sub2_sub1"));
|
||||
EXPECT_FALSE(db_->is_directory("/root/sub2/sub2_sub1"));
|
||||
EXPECT_EQ(1u, db_->get_sub_directory_count("/root/sub2"));
|
||||
EXPECT_TRUE(db_->is_directory("/root/sub2/sub2_sub2"));
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, get_sub_directory_count) {
|
||||
for (const auto &dir : dirs) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory(dir));
|
||||
}
|
||||
|
||||
EXPECT_EQ(1u, db_->get_sub_directory_count("/"));
|
||||
EXPECT_EQ(3u, db_->get_sub_directory_count("/root"));
|
||||
EXPECT_EQ(0u, db_->get_sub_directory_count("/root/sub1"));
|
||||
EXPECT_EQ(2u, db_->get_sub_directory_count("/root/sub2"));
|
||||
EXPECT_EQ(0u, db_->get_sub_directory_count("/root/sub2/sub2_sub1"));
|
||||
EXPECT_EQ(1u, db_->get_sub_directory_count("/root/sub2/sub2_sub2"));
|
||||
EXPECT_EQ(0u, db_->get_sub_directory_count("/root/sub3"));
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, populate_sub_directories) {
|
||||
for (const auto &dir : dirs) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory(dir));
|
||||
}
|
||||
|
||||
directory_item_list list{};
|
||||
const auto dump_directory_list = [&]() {
|
||||
for (const auto &di : list) {
|
||||
std::cout << di.to_json().dump(2) << std::endl;
|
||||
}
|
||||
list.clear();
|
||||
};
|
||||
|
||||
std::cout << "/" << std::endl;
|
||||
db_->populate_sub_directories(
|
||||
"/", [](directory_item &) {}, list);
|
||||
EXPECT_EQ(1u, list.size());
|
||||
dump_directory_list();
|
||||
|
||||
std::cout << std::endl << "/root" << std::endl;
|
||||
db_->populate_sub_directories(
|
||||
"/root", [](directory_item &) {}, list);
|
||||
EXPECT_EQ(3u, list.size());
|
||||
dump_directory_list();
|
||||
|
||||
std::cout << std::endl << "/root/sub1" << std::endl;
|
||||
db_->populate_sub_directories(
|
||||
"/root/sub1", [](directory_item &) {}, list);
|
||||
EXPECT_EQ(0u, list.size());
|
||||
dump_directory_list();
|
||||
|
||||
std::cout << std::endl << "/root/sub2" << std::endl;
|
||||
db_->populate_sub_directories(
|
||||
"/root/sub2", [](directory_item &) {}, list);
|
||||
EXPECT_EQ(2u, list.size());
|
||||
dump_directory_list();
|
||||
|
||||
std::cout << std::endl << "/root/sub2/sub2_sub1" << std::endl;
|
||||
db_->populate_sub_directories(
|
||||
"/root/sub2/sub2_sub1", [](directory_item &) {}, list);
|
||||
EXPECT_EQ(0u, list.size());
|
||||
dump_directory_list();
|
||||
|
||||
std::cout << std::endl << "/root/sub2/sub2_sub2" << std::endl;
|
||||
db_->populate_sub_directories(
|
||||
"/root/sub2/sub2_sub2", [](directory_item &) {}, list);
|
||||
EXPECT_EQ(1u, list.size());
|
||||
dump_directory_list();
|
||||
|
||||
std::cout << std::endl << "/root/sub3" << std::endl;
|
||||
db_->populate_sub_directories(
|
||||
"/root/sub3", [](directory_item &) {}, list);
|
||||
EXPECT_EQ(0u, list.size());
|
||||
dump_directory_list();
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, is_file) {
|
||||
for (const auto &dir : dirs) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory(dir));
|
||||
}
|
||||
|
||||
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
|
||||
EXPECT_TRUE(db_->is_file("/cow.txt"));
|
||||
EXPECT_FALSE(db_->is_directory("/cow.txt"));
|
||||
EXPECT_EQ(api_error::item_exists, db_->create_file("/cow.txt"));
|
||||
EXPECT_EQ(api_error::item_exists, db_->create_directory("/cow.txt"));
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, remove_file) {
|
||||
for (const auto &dir : dirs) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory(dir));
|
||||
}
|
||||
|
||||
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
|
||||
EXPECT_EQ(api_error::directory_not_found, db_->remove_directory("/cow.txt"));
|
||||
EXPECT_TRUE(db_->remove_file("/cow.txt"));
|
||||
EXPECT_FALSE(db_->is_file("/cow.txt"));
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, get_directory_item_count) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory("/"));
|
||||
|
||||
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
|
||||
EXPECT_EQ(api_error::success, db_->create_file("/cow2.txt"));
|
||||
EXPECT_EQ(api_error::success, db_->create_directory("/cow"));
|
||||
EXPECT_EQ(3u, db_->get_directory_item_count("/"));
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, get_file) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory("/"));
|
||||
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
|
||||
|
||||
api_file file{};
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->get_file("/cow.txt", file, [](api_file &cur_file) {
|
||||
EXPECT_STREQ("/cow.txt", cur_file.api_path.c_str());
|
||||
}));
|
||||
EXPECT_STREQ("/cow.txt", file.api_path.c_str());
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, get_file_list) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory("/"));
|
||||
|
||||
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
|
||||
EXPECT_EQ(api_error::success, db_->create_file("/cow2.txt"));
|
||||
|
||||
api_file_list list;
|
||||
int i = 0;
|
||||
EXPECT_EQ(api_error::success, db_->get_file_list(list, [&i](api_file &file) {
|
||||
if (i++ == 0) {
|
||||
EXPECT_STREQ("/cow.txt", file.api_path.c_str());
|
||||
} else {
|
||||
EXPECT_STREQ("/cow2.txt", file.api_path.c_str());
|
||||
}
|
||||
}));
|
||||
|
||||
EXPECT_EQ(std::size_t(2u), list.size());
|
||||
EXPECT_STREQ("/cow.txt", list[0u].api_path.c_str());
|
||||
EXPECT_STREQ("/cow2.txt", list[1u].api_path.c_str());
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, get_total_item_count) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory("/"));
|
||||
|
||||
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
|
||||
EXPECT_EQ(api_error::success, db_->create_file("/cow2.txt"));
|
||||
|
||||
EXPECT_EQ(api_error::success, db_->create_directory("/cow"));
|
||||
EXPECT_EQ(api_error::success, db_->create_directory("/cow/moose"));
|
||||
|
||||
EXPECT_EQ(std::uint64_t(5), db_->get_total_item_count());
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, populate_directory_files) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory("/"));
|
||||
|
||||
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
|
||||
EXPECT_EQ(api_error::success, db_->create_file("/cow2.txt"));
|
||||
|
||||
directory_item_list list;
|
||||
int i = 0;
|
||||
db_->populate_directory_files(
|
||||
"/",
|
||||
[&i](directory_item &di) {
|
||||
di.meta[META_SIZE] = std::to_string(i + 1);
|
||||
EXPECT_FALSE(di.directory);
|
||||
if (i++ == 0) {
|
||||
EXPECT_STREQ("/cow.txt", &di.api_path[0]);
|
||||
} else {
|
||||
EXPECT_STREQ("/cow2.txt", &di.api_path[0]);
|
||||
}
|
||||
},
|
||||
list);
|
||||
|
||||
EXPECT_EQ(std::size_t(2u), list.size());
|
||||
|
||||
EXPECT_EQ(1u, list[0].size);
|
||||
EXPECT_STREQ("/cow.txt", &list[0].api_path[0]);
|
||||
|
||||
EXPECT_EQ(2u, list[1].size);
|
||||
EXPECT_STREQ("/cow2.txt", &list[1].api_path[0]);
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, create_directory_fails_if_directory_exists) {
|
||||
for (const auto &dir : dirs) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory(dir));
|
||||
}
|
||||
|
||||
EXPECT_EQ(api_error::directory_exists, db_->create_file("/root/sub1"));
|
||||
EXPECT_TRUE(db_->is_directory("/root/sub1"));
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, create_file_fails_if_file_exists) {
|
||||
for (const auto &dir : dirs) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory(dir));
|
||||
}
|
||||
|
||||
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
|
||||
EXPECT_EQ(api_error::item_exists, db_->create_directory("/cow.txt"));
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, create_file_fails_if_parent_does_not_exist) {
|
||||
for (const auto &dir : dirs) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory(dir));
|
||||
}
|
||||
|
||||
EXPECT_EQ(api_error::directory_not_found, db_->create_file("/moose/cow.txt"));
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, create_directory_fails_if_parent_does_not_exist) {
|
||||
for (const auto &dir : dirs) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory(dir));
|
||||
}
|
||||
|
||||
EXPECT_EQ(api_error::directory_not_found, db_->create_file("/cow/moose"));
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, remove_file_fails_if_directory_exists) {
|
||||
for (const auto &dir : dirs) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory(dir));
|
||||
}
|
||||
|
||||
EXPECT_FALSE(db_->remove_file("/root/sub1"));
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, remove_directory_fails_if_file_exists) {
|
||||
for (const auto &dir : dirs) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory(dir));
|
||||
}
|
||||
|
||||
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
|
||||
EXPECT_EQ(api_error::directory_not_found, db_->remove_directory("/cow.txt"));
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, remove_directory_fails_if_sub_directories_exist) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory("/"));
|
||||
EXPECT_EQ(api_error::success, db_->create_directory("/sub"));
|
||||
EXPECT_EQ(api_error::success, db_->create_directory("/sub/sub2"));
|
||||
|
||||
EXPECT_EQ(api_error::directory_not_empty, db_->remove_directory("/sub"));
|
||||
EXPECT_TRUE(db_->is_directory("/sub"));
|
||||
EXPECT_TRUE(db_->is_directory("/sub/sub2"));
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test, remove_directory_fails_if_files_exist) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory("/"));
|
||||
EXPECT_EQ(api_error::success, db_->create_directory("/sub"));
|
||||
EXPECT_EQ(api_error::success, db_->create_file("/sub/test.txt"));
|
||||
|
||||
EXPECT_EQ(api_error::directory_not_empty, db_->remove_directory("/sub"));
|
||||
EXPECT_TRUE(db_->is_directory("/sub"));
|
||||
EXPECT_TRUE(db_->is_file("/sub/test.txt"));
|
||||
}
|
||||
|
||||
TEST_F(directory_db_test,
|
||||
remove_directory_fails_for_root_directory_by_default) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory("/"));
|
||||
|
||||
EXPECT_EQ(api_error::access_denied, db_->remove_directory("/"));
|
||||
EXPECT_TRUE(db_->is_directory("/"));
|
||||
}
|
||||
|
||||
TEST_F(
|
||||
directory_db_test,
|
||||
remove_directory_succeeds_for_root_directory_if_allow_remove_root_is_true) {
|
||||
EXPECT_EQ(api_error::success, db_->create_directory("/"));
|
||||
|
||||
EXPECT_EQ(api_error::success, db_->remove_directory("/", true));
|
||||
EXPECT_FALSE(db_->is_directory("/"));
|
||||
}
|
||||
} // namespace repertory
|
@@ -81,8 +81,6 @@ TEST(encrypt_provider, can_get_file_list) {
|
||||
list2.at(idx).api_parent.c_str());
|
||||
EXPECT_EQ(list.at(idx).accessed_date, list2.at(idx).accessed_date);
|
||||
EXPECT_EQ(list.at(idx).changed_date, list2.at(idx).changed_date);
|
||||
EXPECT_TRUE(list.at(idx).encryption_token.empty());
|
||||
EXPECT_TRUE(list2.at(idx).encryption_token.empty());
|
||||
EXPECT_EQ(list.at(idx).file_size, list2.at(idx).file_size);
|
||||
EXPECT_TRUE(list.at(idx).key.empty());
|
||||
EXPECT_TRUE(list2.at(idx).key.empty());
|
||||
|
@@ -114,8 +114,8 @@ TEST(file_manager, can_create_and_close_file) {
|
||||
const auto now = utils::get_file_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u,
|
||||
now + 2u, false, "token", 1, "key", 2, now + 3u, 3u, 4u, 0u,
|
||||
source_path, 10, now + 4u);
|
||||
now + 2u, false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
|
||||
now + 4u);
|
||||
|
||||
EXPECT_CALL(mp, create_file("/test_create.txt", meta))
|
||||
.WillOnce(Return(api_error::success));
|
||||
@@ -127,7 +127,6 @@ TEST(file_manager, can_create_and_close_file) {
|
||||
fsi.api_path = api_path;
|
||||
fsi.api_parent = utils::path::get_parent_api_path(api_path);
|
||||
fsi.directory = directory;
|
||||
fsi.encryption_token = meta[META_ENCRYPTION_TOKEN];
|
||||
fsi.size = utils::string::to_uint64(meta[META_SIZE]);
|
||||
fsi.source_path = meta[META_SOURCE];
|
||||
return api_error::success;
|
||||
@@ -223,8 +222,8 @@ TEST(file_manager, can_open_and_close_file) {
|
||||
const auto now = utils::get_file_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u,
|
||||
now + 2u, false, "token", 1, "key", 2, now + 3u, 3u, 4u, 0u,
|
||||
source_path, 10, now + 4u);
|
||||
now + 2u, false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
|
||||
now + 4u);
|
||||
|
||||
EXPECT_CALL(mp, create_file).Times(0u);
|
||||
|
||||
@@ -236,7 +235,6 @@ TEST(file_manager, can_open_and_close_file) {
|
||||
fsi.api_path = api_path;
|
||||
fsi.api_parent = utils::path::get_parent_api_path(api_path);
|
||||
fsi.directory = directory;
|
||||
fsi.encryption_token = meta[META_ENCRYPTION_TOKEN];
|
||||
fsi.size = utils::string::to_uint64(meta[META_SIZE]);
|
||||
fsi.source_path = meta[META_SOURCE];
|
||||
return api_error::success;
|
||||
@@ -325,8 +323,8 @@ TEST(file_manager, can_open_and_close_multiple_handles_for_same_file) {
|
||||
const auto now = utils::get_file_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u,
|
||||
now + 2u, false, "token", 1, "key", 2, now + 3u, 3u, 4u, 0u,
|
||||
source_path, 10, now + 4u);
|
||||
now + 2u, false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
|
||||
now + 4u);
|
||||
|
||||
EXPECT_CALL(mp, create_file).Times(0u);
|
||||
|
||||
@@ -338,7 +336,6 @@ TEST(file_manager, can_open_and_close_multiple_handles_for_same_file) {
|
||||
fsi.api_path = api_path;
|
||||
fsi.api_parent = utils::path::get_parent_api_path(api_path);
|
||||
fsi.directory = directory;
|
||||
fsi.encryption_token = meta[META_ENCRYPTION_TOKEN];
|
||||
fsi.size = utils::string::to_uint64(meta[META_SIZE]);
|
||||
fsi.source_path = meta[META_SOURCE];
|
||||
return api_error::success;
|
||||
@@ -404,7 +401,7 @@ TEST(file_manager, download_is_stored_after_write_if_partially_downloaded) {
|
||||
const auto now = utils::get_file_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
|
||||
false, "", 1, "key", 2, now + 3u, 3u, 4u,
|
||||
false, 1, "key", 2, now + 3u, 3u, 4u,
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size() * 4u,
|
||||
source_path, 10, now + 4u);
|
||||
auto nf = create_random_file(generate_test_file_name(".", "test_src"),
|
||||
@@ -418,7 +415,6 @@ TEST(file_manager, download_is_stored_after_write_if_partially_downloaded) {
|
||||
fsi.api_path = api_path;
|
||||
fsi.api_parent = utils::path::get_parent_api_path(api_path);
|
||||
fsi.directory = directory;
|
||||
fsi.encryption_token = meta[META_ENCRYPTION_TOKEN];
|
||||
fsi.size = utils::string::to_uint64(meta[META_SIZE]);
|
||||
fsi.source_path = meta[META_SOURCE];
|
||||
return api_error::success;
|
||||
@@ -566,7 +562,7 @@ TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
|
||||
const auto now = utils::get_file_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
|
||||
false, "", 1, "key", 2, now + 3u, 3u, 4u,
|
||||
false, 1, "key", 2, now + 3u, 3u, 4u,
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size() * 4u,
|
||||
source_path, 10, now + 4u);
|
||||
auto nf = create_random_file(generate_test_file_name(".", "test_src"),
|
||||
@@ -580,7 +576,6 @@ TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
|
||||
fsi.api_path = api_path;
|
||||
fsi.api_parent = utils::path::get_parent_api_path(api_path);
|
||||
fsi.directory = directory;
|
||||
fsi.encryption_token = meta[META_ENCRYPTION_TOKEN];
|
||||
fsi.size = utils::string::to_uint64(meta[META_SIZE]);
|
||||
fsi.source_path = meta[META_SOURCE];
|
||||
return api_error::success;
|
||||
@@ -625,8 +620,8 @@ TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
|
||||
|
||||
ec.wait_for_empty();
|
||||
|
||||
EXPECT_CALL(
|
||||
mp, upload_file("/test_write_full_download.txt", source_path, "", _))
|
||||
EXPECT_CALL(mp,
|
||||
upload_file("/test_write_full_download.txt", source_path, _))
|
||||
.WillOnce(Return(api_error::success));
|
||||
|
||||
event_capture ec2({"file_upload_queued", "file_upload_completed"});
|
||||
@@ -634,8 +629,8 @@ TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
|
||||
|
||||
ec2.wait_for_empty();
|
||||
|
||||
EXPECT_EQ(std::size_t(0u), fm.get_open_file_count());
|
||||
EXPECT_EQ(std::size_t(0u), fm.get_open_handle_count());
|
||||
EXPECT_EQ(std::size_t(0U), fm.get_open_file_count());
|
||||
EXPECT_EQ(std::size_t(0U), fm.get_open_handle_count());
|
||||
|
||||
fm.stop();
|
||||
|
||||
@@ -676,8 +671,7 @@ TEST(file_manager, can_evict_file) {
|
||||
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
|
||||
false, "token", 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
|
||||
now + 4u);
|
||||
false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10, now + 4u);
|
||||
std::uint64_t handle{};
|
||||
{
|
||||
std::shared_ptr<i_open_file> f;
|
||||
@@ -692,7 +686,6 @@ TEST(file_manager, can_evict_file) {
|
||||
fsi.api_path = api_path;
|
||||
fsi.api_parent = utils::path::get_parent_api_path(api_path);
|
||||
fsi.directory = directory;
|
||||
fsi.encryption_token = meta[META_ENCRYPTION_TOKEN];
|
||||
fsi.size = utils::string::to_uint64(meta[META_SIZE]);
|
||||
fsi.source_path = meta[META_SOURCE];
|
||||
return api_error::success;
|
||||
@@ -708,7 +701,7 @@ TEST(file_manager, can_evict_file) {
|
||||
EXPECT_CALL(mp, set_item_meta("/test_evict.txt", _))
|
||||
.Times(2)
|
||||
.WillRepeatedly(Return(api_error::success));
|
||||
EXPECT_CALL(mp, upload_file(_, _, _, _))
|
||||
EXPECT_CALL(mp, upload_file(_, _, _))
|
||||
.WillOnce(Return(api_error::success));
|
||||
|
||||
data_buffer data{{0, 1, 1}};
|
||||
@@ -944,7 +937,7 @@ TEST(file_manager, evict_file_fails_if_file_is_uploading) {
|
||||
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
|
||||
false, "", 1, "", 2, now + 3u, 3u, 4u, 0u, source_path, 10, now + 4u);
|
||||
false, 1, "", 2, now + 3u, 3u, 4u, 0u, source_path, 10, now + 4u);
|
||||
std::uint64_t handle{};
|
||||
{
|
||||
std::shared_ptr<i_open_file> f;
|
||||
@@ -959,7 +952,6 @@ TEST(file_manager, evict_file_fails_if_file_is_uploading) {
|
||||
fsi.api_path = api_path;
|
||||
fsi.api_parent = utils::path::get_parent_api_path(api_path);
|
||||
fsi.directory = directory;
|
||||
fsi.encryption_token = meta[META_ENCRYPTION_TOKEN];
|
||||
fsi.size = utils::string::to_uint64(meta[META_SIZE]);
|
||||
fsi.source_path = meta[META_SOURCE];
|
||||
return api_error::success;
|
||||
@@ -978,11 +970,9 @@ TEST(file_manager, evict_file_fails_if_file_is_uploading) {
|
||||
EXPECT_CALL(mp, upload_file)
|
||||
.WillOnce([](const std::string &api_path,
|
||||
const std::string &source_path2,
|
||||
const std::string &encryption_token,
|
||||
stop_type & /*stop_requested*/) -> api_error {
|
||||
EXPECT_STREQ("/test_evict.txt", api_path.c_str());
|
||||
EXPECT_FALSE(source_path2.empty());
|
||||
EXPECT_TRUE(encryption_token.empty());
|
||||
std::this_thread::sleep_for(3s);
|
||||
return api_error::success;
|
||||
});
|
||||
@@ -1178,7 +1168,7 @@ TEST(file_manager, file_is_not_opened_if_provider_create_file_fails) {
|
||||
const auto now = utils::get_file_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
|
||||
false, "", 1, "", 2, now + 3u, 3u, 4u, 0u, "/test_create.src", 10,
|
||||
false, 1, "", 2, now + 3u, 3u, 4u, 0u, "/test_create.src", 10,
|
||||
now + 4u);
|
||||
file_manager fm(cfg, mp);
|
||||
|
||||
@@ -1721,7 +1711,7 @@ TEST(file_manager, file_is_closed_after_download_timeout) {
|
||||
const auto now = utils::get_file_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
|
||||
false, "", 1, "key", 2, now + 3u, 3u, 4u,
|
||||
false, 1, "key", 2, now + 3u, 3u, 4u,
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size() * 4u,
|
||||
source_path, 10, now + 4u);
|
||||
|
||||
@@ -1733,7 +1723,6 @@ TEST(file_manager, file_is_closed_after_download_timeout) {
|
||||
fsi.api_path = api_path;
|
||||
fsi.api_parent = utils::path::get_parent_api_path(api_path);
|
||||
fsi.directory = directory;
|
||||
fsi.encryption_token = meta[META_ENCRYPTION_TOKEN];
|
||||
fsi.size = utils::string::to_uint64(meta[META_SIZE]);
|
||||
fsi.source_path = meta[META_SOURCE];
|
||||
return api_error::success;
|
||||
|
@@ -56,10 +56,8 @@ TEST(upload, can_upload_a_valid_file) {
|
||||
EXPECT_STREQ("0", ee.get_cancelled().get<std::string>().c_str());
|
||||
});
|
||||
|
||||
EXPECT_CALL(
|
||||
mp, upload_file(fsi.api_path, fsi.source_path, fsi.encryption_token, _))
|
||||
EXPECT_CALL(mp, upload_file(fsi.api_path, fsi.source_path, _))
|
||||
.WillOnce([&fsi](const std::string &, const std::string &,
|
||||
const std::string &,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
EXPECT_FALSE(stop_requested);
|
||||
return api_error::success;
|
||||
@@ -105,10 +103,8 @@ TEST(upload, can_cancel_upload) {
|
||||
std::mutex mtx;
|
||||
std::condition_variable cv;
|
||||
|
||||
EXPECT_CALL(
|
||||
mp, upload_file(fsi.api_path, fsi.source_path, fsi.encryption_token, _))
|
||||
EXPECT_CALL(mp, upload_file(fsi.api_path, fsi.source_path, _))
|
||||
.WillOnce([&cv, &fsi, &mtx](const std::string &, const std::string &,
|
||||
const std::string &,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
EXPECT_FALSE(stop_requested);
|
||||
|
||||
@@ -169,10 +165,8 @@ TEST(upload, can_stop_upload) {
|
||||
EXPECT_STREQ("0", ee.get_cancelled().get<std::string>().c_str());
|
||||
});
|
||||
|
||||
EXPECT_CALL(
|
||||
mp, upload_file(fsi.api_path, fsi.source_path, fsi.encryption_token, _))
|
||||
EXPECT_CALL(mp, upload_file(fsi.api_path, fsi.source_path, _))
|
||||
.WillOnce([&fsi](const std::string &, const std::string &,
|
||||
const std::string &,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
std::this_thread::sleep_for(3s);
|
||||
EXPECT_TRUE(stop_requested);
|
||||
|
57
tests/fixtures/directory_db_fixture.hpp
vendored
57
tests/fixtures/directory_db_fixture.hpp
vendored
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef REPERTORY_DIRECTORY_DB_FIXTURE_H
|
||||
#define REPERTORY_DIRECTORY_DB_FIXTURE_H
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "db/directory_db.hpp"
|
||||
#include "utils/path_utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class directory_db_test : public ::testing::Test {
|
||||
private:
|
||||
const std::string config_location_ = utils::path::absolute("./directorydb");
|
||||
|
||||
protected:
|
||||
std::unique_ptr<app_config> config_;
|
||||
std::unique_ptr<directory_db> db_;
|
||||
|
||||
public:
|
||||
void SetUp() override {
|
||||
ASSERT_TRUE(utils::file::delete_directory_recursively(config_location_));
|
||||
config_ =
|
||||
std::make_unique<app_config>(provider_type::encrypt, config_location_);
|
||||
db_ = std::make_unique<directory_db>(*config_.get());
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
db_.reset();
|
||||
config_.reset();
|
||||
|
||||
EXPECT_TRUE(utils::file::delete_directory_recursively(config_location_));
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_DIRECTORY_DB_FIXTURE_H
|
57
tests/fixtures/meta_db_fixture.hpp
vendored
57
tests/fixtures/meta_db_fixture.hpp
vendored
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef REPERTORY_META_DB_FIXTURE_H
|
||||
#define REPERTORY_META_DB_FIXTURE_H
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "db/meta_db.hpp"
|
||||
#include "utils/path_utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class meta_db_test : public ::testing::Test {
|
||||
private:
|
||||
const std::string config_location_ = utils::path::absolute("./metadb");
|
||||
|
||||
protected:
|
||||
std::unique_ptr<app_config> config_;
|
||||
std::unique_ptr<meta_db> db_;
|
||||
|
||||
public:
|
||||
void SetUp() override {
|
||||
ASSERT_TRUE(utils::file::delete_directory_recursively(config_location_));
|
||||
config_ =
|
||||
std::make_unique<app_config>(provider_type::sia, config_location_);
|
||||
db_ = std::make_unique<meta_db>(*config_.get());
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
db_.reset();
|
||||
config_.reset();
|
||||
|
||||
EXPECT_TRUE(utils::file::delete_directory_recursively(config_location_));
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_META_DB_FIXTURE_H
|
88
tests/fixtures/s3_comm_fixture.hpp
vendored
88
tests/fixtures/s3_comm_fixture.hpp
vendored
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef REPERTORY_S3_COMM_FIXTURE_H
|
||||
#define REPERTORY_S3_COMM_FIXTURE_H
|
||||
|
||||
#if defined(REPERTORY_ENABLE_S3) && defined(REPERTORY_ENABLE_S3_TESTING)
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "comm/s3/s3_comm.hpp"
|
||||
#include "utils/path_utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class s3_comm_test : public ::testing::Test {
|
||||
private:
|
||||
console_consumer c_;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<app_config> config_;
|
||||
std::unique_ptr<s3_comm> s3_comm_;
|
||||
|
||||
public:
|
||||
void SetUp() override {
|
||||
const auto path = utils::path::absolute("./test/");
|
||||
ASSERT_TRUE(utils::file::delete_directory_recursively(path));
|
||||
{
|
||||
app_config config(provider_type::s3,
|
||||
utils::path::combine(get_test_dir(), {"filebase"}));
|
||||
|
||||
config_ = std::make_unique<app_config>(provider_type::s3, "./test");
|
||||
config_->set_event_level(event_level::verbose);
|
||||
EXPECT_FALSE(config_
|
||||
->set_value_by_name("S3Config.AccessKey",
|
||||
config.get_s3_config().access_key)
|
||||
.empty());
|
||||
EXPECT_FALSE(config_
|
||||
->set_value_by_name("S3Config.SecretKey",
|
||||
config.get_s3_config().secret_key)
|
||||
.empty());
|
||||
EXPECT_FALSE(config_
|
||||
->set_value_by_name("S3Config.Region",
|
||||
config.get_s3_config().region)
|
||||
.empty());
|
||||
EXPECT_FALSE(
|
||||
config_->set_value_by_name("S3Config.URL", config.get_s3_config().url)
|
||||
.empty());
|
||||
EXPECT_FALSE(
|
||||
config_->set_value_by_name("S3Config.Bucket", "repertory").empty());
|
||||
}
|
||||
|
||||
s3_comm_ = std::make_unique<s3_comm>(*config_);
|
||||
|
||||
event_system::instance().start();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
event_system::instance().stop();
|
||||
s3_comm_.reset();
|
||||
config_.reset();
|
||||
|
||||
const auto path = utils::path::absolute("./test/");
|
||||
EXPECT_TRUE(utils::file::delete_directory_recursively(path));
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_ENABLE_S3_TESTING
|
||||
#endif // REPERTORY_S3_COMM_FIXTURE_H
|
@@ -23,7 +23,7 @@
|
||||
#define REPERTORY_S3_PROVIDER_FILE_LIST_FIXTURE_H
|
||||
|
||||
#if defined(REPERTORY_ENABLE_S3) && defined(REPERTORY_ENABLE_S3_TESTING)
|
||||
|
||||
#if 0
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "mocks/mock_s3_comm.hpp"
|
||||
@@ -76,7 +76,6 @@ public:
|
||||
file.api_parent = utils::path::get_parent_api_path(file.api_path);
|
||||
file.changed_date = times[idx] + 1u;
|
||||
file.creation_date = times[idx] + 2u;
|
||||
file.encryption_token = "";
|
||||
file.file_size = 100u + idx;
|
||||
file.modified_date = times[idx] + 3u;
|
||||
this->list.emplace_back(std::move(file));
|
||||
@@ -145,5 +144,6 @@ public:
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif
|
||||
#endif // REPERTORY_ENABLE_S3_TESTING
|
||||
#endif // REPERTORY_S3_PROVIDER_FILE_LIST_FIXTURE_H
|
||||
|
@@ -25,7 +25,6 @@
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "comm/curl/curl_comm.hpp"
|
||||
#include "comm/s3/s3_comm.hpp"
|
||||
#include "drives/fuse/fuse_drive.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "providers/s3/s3_provider.hpp"
|
||||
@@ -54,10 +53,8 @@ static void execute_unmount(i_provider &provider,
|
||||
EXPECT_STREQ("/", fsi.api_path.c_str());
|
||||
EXPECT_TRUE(fsi.api_parent.empty());
|
||||
EXPECT_TRUE(fsi.directory);
|
||||
EXPECT_TRUE(fsi.encryption_token.empty());
|
||||
EXPECT_EQ(std::uint64_t(0u), fsi.size);
|
||||
EXPECT_TRUE(fsi.source_path.empty());
|
||||
EXPECT_FALSE(fsi.is_encrypted());
|
||||
|
||||
api_meta_map meta{};
|
||||
EXPECT_EQ(api_error::success, provider.get_item_meta("/", meta));
|
||||
@@ -511,9 +508,6 @@ TEST(fuse_drive, all_tests) {
|
||||
EXPECT_TRUE(utils::file::create_full_directory_path(mount_location));
|
||||
{
|
||||
std::unique_ptr<app_config> config_ptr{};
|
||||
#ifdef REPERTORY_ENABLE_S3
|
||||
std::unique_ptr<s3_comm> s3_comm_ptr{};
|
||||
#endif
|
||||
std::unique_ptr<curl_comm> comm_ptr{};
|
||||
std::unique_ptr<i_provider> provider_ptr{};
|
||||
std::unique_ptr<lock_data> lock_data_ptr{};
|
||||
@@ -537,8 +531,8 @@ TEST(fuse_drive, all_tests) {
|
||||
config_ptr->set_s3_config(src_cfg.get_s3_config());
|
||||
}
|
||||
|
||||
s3_comm_ptr = std::make_unique<s3_comm>(*config_ptr);
|
||||
provider_ptr = std::make_unique<s3_provider>(*config_ptr, *s3_comm_ptr);
|
||||
comm_ptr = std::make_unique<curl_comm>(config_ptr->get_s3_config());
|
||||
provider_ptr = std::make_unique<s3_provider>(*config_ptr, *comm_ptr);
|
||||
lock_data_ptr = std::make_unique<lock_data>(
|
||||
provider_type::s3, "unittests_" + std::to_string(idx));
|
||||
#else
|
||||
|
@@ -1,292 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "fixtures/meta_db_fixture.hpp"
|
||||
|
||||
namespace repertory {
|
||||
TEST_F(meta_db_test, get_and_set_item_meta) {
|
||||
api_meta_map meta{
|
||||
{"test", "test_value"},
|
||||
{"test2", "test_value2"},
|
||||
{"test3", "test_value3"},
|
||||
};
|
||||
EXPECT_EQ(api_error::success, db_->set_item_meta("/test/item", meta));
|
||||
|
||||
api_meta_map meta2{};
|
||||
EXPECT_EQ(api_error::success, db_->get_item_meta("/test/item", meta2));
|
||||
|
||||
EXPECT_EQ(meta, meta2);
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, get_and_set_item_meta_single_key) {
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->set_item_meta("/test/item", "test", "moose"));
|
||||
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->get_item_meta("/test/item", "test", value));
|
||||
|
||||
EXPECT_STREQ("moose", value.c_str());
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test,
|
||||
get_item_meta_fails_with_not_found_for_items_that_dont_exist) {
|
||||
api_meta_map meta{};
|
||||
EXPECT_EQ(api_error::item_not_found, db_->get_item_meta("/test/item", meta));
|
||||
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::item_not_found,
|
||||
db_->get_item_meta("/test/item", "test", value));
|
||||
EXPECT_TRUE(value.empty());
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, get_item_meta_exists) {
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->set_item_meta("/test/item", "test", "value"));
|
||||
EXPECT_TRUE(db_->get_item_meta_exists("/test/item"));
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, get_item_meta_exists_is_false_if_not_found) {
|
||||
EXPECT_FALSE(db_->get_item_meta_exists("/test/item"));
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, remove_item_meta) {
|
||||
api_meta_map meta{
|
||||
{"test", "test_value"},
|
||||
{"test2", "test_value2"},
|
||||
{"test3", "test_value3"},
|
||||
};
|
||||
EXPECT_EQ(api_error::success, db_->set_item_meta("/test/item", meta));
|
||||
|
||||
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item"));
|
||||
|
||||
api_meta_map meta2{};
|
||||
EXPECT_EQ(api_error::item_not_found, db_->get_item_meta("/test/item", meta2));
|
||||
|
||||
EXPECT_TRUE(meta2.empty());
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, remove_item_meta_single_key) {
|
||||
api_meta_map meta{
|
||||
{"test", "test_value"},
|
||||
{"test2", "test_value2"},
|
||||
{"test3", "test_value3"},
|
||||
};
|
||||
EXPECT_EQ(api_error::success, db_->set_item_meta("/test/item", meta));
|
||||
|
||||
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item", "test"));
|
||||
|
||||
api_meta_map meta2{};
|
||||
EXPECT_EQ(api_error::success, db_->get_item_meta("/test/item", meta2));
|
||||
|
||||
meta.erase("test");
|
||||
EXPECT_EQ(meta, meta2);
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, get_and_set_source_path) {
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->set_source_path("/test/item", "/test/path"));
|
||||
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->get_item_meta("/test/item", META_SOURCE, value));
|
||||
EXPECT_STREQ("/test/path", value.c_str());
|
||||
}
|
||||
|
||||
// TEST_F(meta_db_test, set_source_path_fails_on_empty_path) {
|
||||
// EXPECT_EQ(api_error::invalid_operation, db_->set_source_path("/test/item",
|
||||
// ""));
|
||||
//
|
||||
// std::string value;
|
||||
// EXPECT_EQ(api_error::item_not_found, db_->get_item_meta("/test/item",
|
||||
// META_SOURCE, value)); EXPECT_TRUE(value.empty());
|
||||
// }
|
||||
|
||||
TEST_F(meta_db_test, get_api_path_from_source) {
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->set_source_path("/test/item", "/test/path"));
|
||||
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->get_api_path_from_source("/test/path", value));
|
||||
EXPECT_STREQ("/test/item", value.c_str());
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, get_api_path_from_source_succeeds_after_change) {
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->set_source_path("/test/item", "/test/path"));
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->set_source_path("/test/item", "/test/path2"));
|
||||
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->get_api_path_from_source("/test/path2", value));
|
||||
EXPECT_STREQ("/test/item", value.c_str());
|
||||
|
||||
value.clear();
|
||||
EXPECT_EQ(api_error::item_not_found,
|
||||
db_->get_api_path_from_source("/test/path", value));
|
||||
EXPECT_TRUE(value.empty());
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, get_api_path_from_source_fails_after_remove_all_meta) {
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->set_source_path("/test/item", "/test/path"));
|
||||
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item"));
|
||||
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::item_not_found,
|
||||
db_->get_api_path_from_source("/test/path", value));
|
||||
EXPECT_TRUE(value.empty());
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, get_api_path_from_source_fails_after_remove_source_key) {
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->set_source_path("/test/item", "/test/path"));
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->remove_item_meta("/test/item", META_SOURCE));
|
||||
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::item_not_found,
|
||||
db_->get_api_path_from_source("/test/path", value));
|
||||
EXPECT_TRUE(value.empty());
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, get_source_path_exists) {
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->set_source_path("/test/item", "/test/path"));
|
||||
EXPECT_TRUE(db_->get_source_path_exists("/test/path"));
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, get_source_path_exists_is_false_if_not_found) {
|
||||
EXPECT_FALSE(db_->get_source_path_exists("/test/item"));
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, get_api_path_from_key) {
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->set_item_meta("/test/item", META_KEY, "key"));
|
||||
|
||||
std::string value;
|
||||
EXPECT_EQ(api_error::success, db_->get_api_path_from_key("key", value));
|
||||
EXPECT_STREQ("/test/item", value.c_str());
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, remove_item_meta_succeeds_for_items_that_dont_exist) {
|
||||
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item"));
|
||||
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item", "test"));
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, remove_item_meta_removes_source_path) {
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->set_source_path("/test/item", "/source/path"));
|
||||
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item"));
|
||||
|
||||
std::string api_path;
|
||||
EXPECT_EQ(api_error::item_not_found,
|
||||
db_->get_api_path_from_source("/source/path", api_path));
|
||||
EXPECT_TRUE(api_path.empty());
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, remove_item_meta_by_key_removes_source_path) {
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->set_source_path("/test/item", "/source/path"));
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->remove_item_meta("/test/item", META_SOURCE));
|
||||
|
||||
std::string api_path;
|
||||
EXPECT_EQ(api_error::item_not_found,
|
||||
db_->get_api_path_from_source("/source/path", api_path));
|
||||
EXPECT_TRUE(api_path.empty());
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, remove_item_meta_removes_key) {
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->set_item_meta("/test/item", META_KEY, "key"));
|
||||
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item"));
|
||||
|
||||
std::string api_path;
|
||||
EXPECT_EQ(api_error::item_not_found,
|
||||
db_->get_api_path_from_key("key", api_path));
|
||||
EXPECT_TRUE(api_path.empty());
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, remove_item_meta_by_key_removes_key) {
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->set_item_meta("/test/item", META_KEY, "key"));
|
||||
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item", META_KEY));
|
||||
|
||||
std::string api_path;
|
||||
EXPECT_EQ(api_error::item_not_found,
|
||||
db_->get_api_path_from_key("/source/path", api_path));
|
||||
EXPECT_TRUE(api_path.empty());
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, rename_item_meta) {
|
||||
api_meta_map meta{
|
||||
{"test", "test_value"},
|
||||
{"test2", "test_value2"},
|
||||
{"test3", "test_value3"},
|
||||
};
|
||||
EXPECT_EQ(api_error::success, db_->set_item_meta("/test/item", meta));
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->rename_item_meta("", "/test/item", "/test/item2"));
|
||||
|
||||
api_meta_map meta2{};
|
||||
EXPECT_EQ(api_error::item_not_found, db_->get_item_meta("/test/item", meta2));
|
||||
|
||||
EXPECT_EQ(api_error::success, db_->get_item_meta("/test/item2", meta2));
|
||||
EXPECT_EQ(meta, meta2);
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, rename_item_meta_with_key) {
|
||||
api_meta_map meta{
|
||||
{META_KEY, "test_key"},
|
||||
{"test2", "test_value2"},
|
||||
{"test3", "test_value3"},
|
||||
};
|
||||
EXPECT_EQ(api_error::success, db_->set_item_meta("/test/item", meta));
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->rename_item_meta("", "/test/item", "/test/item2"));
|
||||
|
||||
std::string api_path;
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->get_api_path_from_key("test_key", api_path));
|
||||
EXPECT_STREQ("/test/item2", api_path.c_str());
|
||||
}
|
||||
|
||||
TEST_F(meta_db_test, rename_item_meta_with_source_path) {
|
||||
api_meta_map meta{
|
||||
{META_SOURCE, "/test/source"},
|
||||
{"test2", "test_value2"},
|
||||
{"test3", "test_value3"},
|
||||
};
|
||||
EXPECT_EQ(api_error::success, db_->set_item_meta("/test/item", meta));
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->rename_item_meta("/test/source", "/test/item", "/test/item2"));
|
||||
|
||||
std::string api_path;
|
||||
EXPECT_EQ(api_error::success,
|
||||
db_->get_api_path_from_source("/test/source", api_path));
|
||||
EXPECT_STREQ("/test/item2", api_path.c_str());
|
||||
}
|
||||
} // namespace repertory
|
@@ -154,7 +154,7 @@ public:
|
||||
|
||||
MOCK_METHOD(api_error, upload_file,
|
||||
(const std::string &api_path, const std::string &source_path,
|
||||
const std::string &encryption_token, stop_type &stop_requested),
|
||||
stop_type &stop_requested),
|
||||
(override));
|
||||
};
|
||||
} // namespace repertory
|
||||
|
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef TESTS_MOCKS_MOCK_S3_COMM_HPP_
|
||||
#define TESTS_MOCKS_MOCK_S3_COMM_HPP_
|
||||
#if defined(REPERTORY_ENABLE_S3) && defined(REPERTORY_ENABLE_S3_TESTING)
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "comm/i_s3_comm.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class mock_s3_comm final : public i_s3_comm {
|
||||
public:
|
||||
mock_s3_comm(s3_config cfg) : s3_config_(cfg) {}
|
||||
|
||||
private:
|
||||
s3_config s3_config_;
|
||||
|
||||
public:
|
||||
// [[nodiscard]] virtual api_error create_directory(const std::string
|
||||
// &api_path) = 0;
|
||||
//
|
||||
MOCK_METHOD(api_error, create_directory, (const std::string &api_path),
|
||||
(override));
|
||||
|
||||
// [[nodiscard]] virtual api_error directory_exists(const std::string
|
||||
// &api_path) const = 0;
|
||||
//
|
||||
MOCK_METHOD(api_error, directory_exists, (const std::string &api_path),
|
||||
(const, override));
|
||||
|
||||
// [[nodiscard]] virtual api_error file_exists(const std::string &api_path,
|
||||
// const get_key_callback
|
||||
// &get_key) const = 0;
|
||||
MOCK_METHOD(api_error, file_exists,
|
||||
(const std::string &api_path, const get_key_callback &get_key),
|
||||
(const, override));
|
||||
|
||||
// [[nodiscard]] virtual std::size_t
|
||||
// get_directory_item_count(const std::string &api_path,
|
||||
// meta_provider_callback meta_provider) const
|
||||
// = 0;
|
||||
//
|
||||
MOCK_METHOD(std::size_t, get_directory_item_count,
|
||||
(const std::string &api_path,
|
||||
meta_provider_callback meta_provider),
|
||||
(const, override));
|
||||
|
||||
// [[nodiscard]] virtual api_error get_directory_items(const std::string
|
||||
// &api_path,
|
||||
// const
|
||||
// meta_provider_callback
|
||||
// &meta_provider,
|
||||
// directory_item_list
|
||||
// &list) const = 0;
|
||||
//
|
||||
MOCK_METHOD(api_error, get_directory_items,
|
||||
(const std::string &api_path,
|
||||
meta_provider_callback meta_provider,
|
||||
directory_item_list &list),
|
||||
(const, override));
|
||||
|
||||
// [[nodiscard]] virtual api_error
|
||||
// get_directory_list(api_file_list &list) const = 0;
|
||||
//
|
||||
MOCK_METHOD(api_error, get_directory_list, (api_file_list & list),
|
||||
(const, override));
|
||||
|
||||
// [[nodiscard]] virtual api_error get_file(const std::string &api_path,
|
||||
// const get_key_callback &get_key,
|
||||
// const get_name_callback &get_name,
|
||||
// const get_token_callback
|
||||
// &get_token, api_file &file) const
|
||||
// = 0;
|
||||
//
|
||||
MOCK_METHOD(api_error, get_file,
|
||||
(const std::string &api_path, const get_key_callback &get_key,
|
||||
const get_name_callback &get_name,
|
||||
const get_token_callback &get_token, api_file &file),
|
||||
(const, override));
|
||||
|
||||
// [[nodiscard]] virtual api_error
|
||||
// get_file_list(const get_api_file_token_callback &get_api_file_token,
|
||||
// const get_name_callback &get_name, api_file_list &list) const
|
||||
// = 0;
|
||||
//
|
||||
MOCK_METHOD(api_error, get_file_list,
|
||||
(const get_api_file_token_callback &get_api_file_token,
|
||||
const get_name_callback &get_name, api_file_list &list),
|
||||
(const, override));
|
||||
|
||||
// [[nodiscard]] virtual api_error get_object_list(std::vector<directory_item>
|
||||
// &list) const = 0;
|
||||
//
|
||||
MOCK_METHOD(api_error, get_object_list, (std::vector<directory_item> & list),
|
||||
(const, override));
|
||||
|
||||
// virtual std::string get_object_name(const std::string &api_path,
|
||||
// const get_key_callback &get_key) const
|
||||
// = 0;
|
||||
//
|
||||
MOCK_METHOD(std::string, get_object_name,
|
||||
(const std::string &api_path, const get_key_callback &get_key),
|
||||
(const, override));
|
||||
|
||||
[[nodiscard]] s3_config get_s3_config() override { return s3_config_; }
|
||||
|
||||
[[nodiscard]] s3_config get_s3_config() const override { return s3_config_; }
|
||||
|
||||
// [[nodiscard]] virtual bool is_online() const = 0;
|
||||
//
|
||||
MOCK_METHOD(bool, is_online, (), (const, override));
|
||||
|
||||
// [[nodiscard]] virtual api_error
|
||||
// read_file_bytes(const std::string &api_path, std::size_t size, const
|
||||
// std::uint64_t &offset,
|
||||
// data_buffer &data, const get_key_callback &get_key,
|
||||
// const get_size_callback &get_size, const get_token_callback
|
||||
// &get_token, stop_type &stop_requested) const = 0;
|
||||
//
|
||||
MOCK_METHOD(api_error, read_file_bytes,
|
||||
(const std::string &api_path, std::size_t size,
|
||||
std::uint64_t offset, data_buffer &data,
|
||||
const get_key_callback &get_key,
|
||||
const get_size_callback &get_size,
|
||||
const get_token_callback &get_token, stop_type &stop_requested),
|
||||
(const, override));
|
||||
|
||||
// [[nodiscard]] virtual api_error remove_directory(const std::string
|
||||
// &api_path) = 0;
|
||||
//
|
||||
MOCK_METHOD(api_error, remove_directory, (const std::string &api_path),
|
||||
(override));
|
||||
|
||||
// [[nodiscard]] virtual api_error remove_file(const std::string &api_path,
|
||||
// const get_key_callback
|
||||
// &get_key) = 0;
|
||||
//
|
||||
MOCK_METHOD(api_error, remove_file,
|
||||
(const std::string &api_path, const get_key_callback &get_key),
|
||||
(override));
|
||||
|
||||
// [[nodiscard]] virtual api_error rename_file(const std::string &api_path,
|
||||
// const std::string
|
||||
// &new_api_path) = 0;
|
||||
//
|
||||
MOCK_METHOD(api_error, rename_file,
|
||||
(const std::string &api_path, const std::string &new_api_path),
|
||||
(override));
|
||||
|
||||
// [[nodiscard]] virtual api_error
|
||||
// upload_file(const std::string &api_path, const std::string &source_path,
|
||||
// const std::string &encryption_token, const get_key_callback
|
||||
// &get_key, const set_key_callback &set_key, stop_type
|
||||
// &stop_requested) = 0;
|
||||
MOCK_METHOD(api_error, upload_file,
|
||||
(const std::string &api_path, const std::string &source_path,
|
||||
const std::string &encryption_token,
|
||||
const get_key_callback &get_key, const set_key_callback &set_key,
|
||||
stop_type &stop_requested),
|
||||
(override));
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_ENABLE_S3_TESTING
|
||||
#endif // TESTS_MOCKS_MOCK_S3_COMM_HPP_
|
@@ -22,7 +22,6 @@
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "comm/curl/curl_comm.hpp"
|
||||
#include "comm/s3/s3_comm.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "file_manager/file_manager.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
@@ -57,8 +56,8 @@ const auto create_directory = [](repertory::i_provider &provider,
|
||||
const std::string &api_path) {
|
||||
auto date = repertory::utils::get_file_time_now();
|
||||
auto meta = repertory::create_meta_attributes(
|
||||
date, 0U, date + 1U, date + 2U, true, "", getgid(), "", 0700, date + 3U,
|
||||
1U, 2U, 0U, api_path + "_src", getuid(), date + 4U);
|
||||
date, 0U, date + 1U, date + 2U, true, getgid(), "", 0700, date + 3U, 1U,
|
||||
2U, 0U, api_path + "_src", getuid(), date + 4U);
|
||||
EXPECT_EQ(repertory::api_error::success,
|
||||
provider.create_directory(api_path, meta));
|
||||
|
||||
@@ -74,8 +73,8 @@ const auto create_file = [](repertory::i_provider &provider,
|
||||
|
||||
auto date = repertory::utils::get_file_time_now();
|
||||
auto meta = repertory::create_meta_attributes(
|
||||
date, 0U, date + 1U, date + 2U, false, "", getgid(), "", 0700, date + 3U,
|
||||
1U, 2U, 0U, source_path, getuid(), date + 4U);
|
||||
date, 0U, date + 1U, date + 2U, false, getgid(), "", 0700, date + 3U, 1U,
|
||||
2U, 0U, source_path, getuid(), date + 4U);
|
||||
EXPECT_EQ(repertory::api_error::success,
|
||||
provider.create_file(api_path, meta));
|
||||
|
||||
@@ -438,7 +437,6 @@ static void get_file(const app_config &cfg, i_provider &provider) {
|
||||
#else
|
||||
EXPECT_EQ(std::size_t(46U), file.file_size);
|
||||
#endif
|
||||
EXPECT_TRUE(file.encryption_token.empty());
|
||||
EXPECT_STREQ(source_path.c_str(), file.source_path.c_str());
|
||||
}
|
||||
}
|
||||
@@ -585,7 +583,7 @@ TEST(providers, s3_provider) {
|
||||
cfg.set_s3_config(src_cfg.get_s3_config());
|
||||
}
|
||||
|
||||
s3_comm comm{cfg};
|
||||
curl_comm comm{cfg.get_s3_config()};
|
||||
s3_provider provider{cfg, comm};
|
||||
file_manager fm(cfg, provider);
|
||||
fm.start();
|
||||
|
@@ -1,205 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#if defined(REPERTORY_ENABLE_S3) && defined(REPERTORY_ENABLE_S3_TESTING)
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "comm/s3/s3_comm.hpp"
|
||||
#include "fixtures/s3_comm_fixture.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
TEST_F(s3_comm_test, create_and_remove_directory) {
|
||||
auto ret = s3_comm_->create_directory("/dir");
|
||||
EXPECT_EQ(api_error::success, ret);
|
||||
EXPECT_EQ(api_error::directory_exists, s3_comm_->directory_exists("/dir"));
|
||||
|
||||
ret = s3_comm_->remove_directory("/dir");
|
||||
EXPECT_EQ(api_error::success, ret);
|
||||
EXPECT_EQ(api_error::directory_not_found, s3_comm_->directory_exists("/dir"));
|
||||
|
||||
ret = s3_comm_->remove_directory("/dir");
|
||||
EXPECT_TRUE(ret == api_error::success ||
|
||||
ret == api_error::directory_not_found);
|
||||
}
|
||||
|
||||
TEST_F(s3_comm_test, upload_file) {
|
||||
stop_type stop_requested = false;
|
||||
auto ret = s3_comm_->upload_file(
|
||||
"/test.txt", __FILE__, "", []() -> std::string { return ""; },
|
||||
[](const std::string &) -> api_error { return api_error::success; },
|
||||
stop_requested);
|
||||
EXPECT_EQ(api_error::success, ret);
|
||||
|
||||
ret = s3_comm_->upload_file(
|
||||
"/subdir/test2.txt", __FILE__, "", []() -> std::string { return ""; },
|
||||
[](const std::string &) -> api_error { return api_error::success; },
|
||||
stop_requested);
|
||||
EXPECT_EQ(api_error::success, ret);
|
||||
}
|
||||
|
||||
TEST_F(s3_comm_test, get_directory_items) {
|
||||
directory_item_list list{};
|
||||
auto ret = s3_comm_->get_directory_items(
|
||||
"/subdir", [](directory_item &) {}, list);
|
||||
EXPECT_EQ(api_error::success, ret);
|
||||
}
|
||||
|
||||
TEST_F(s3_comm_test, list_directories) {
|
||||
api_file_list list{};
|
||||
auto ret = s3_comm_->get_directory_list(list);
|
||||
EXPECT_EQ(api_error::success, ret);
|
||||
}
|
||||
|
||||
TEST_F(s3_comm_test, list_files) {
|
||||
api_file_list list{};
|
||||
auto ret = s3_comm_->get_file_list(
|
||||
[](const std::string &) -> std::string { return ""; },
|
||||
[](const std::string &, const std::string &object_name) -> std::string {
|
||||
return object_name;
|
||||
},
|
||||
list);
|
||||
EXPECT_EQ(api_error::success, ret);
|
||||
}
|
||||
|
||||
TEST_F(s3_comm_test, read_file_bytes) {
|
||||
stop_type stop_requested = false;
|
||||
data_buffer data;
|
||||
auto ret = s3_comm_->read_file_bytes(
|
||||
"/test.txt", 2, 0, data, []() -> std::string { return ""; },
|
||||
[]() -> std::uint64_t { return 0ull; },
|
||||
[]() -> std::string { return ""; }, stop_requested);
|
||||
EXPECT_EQ(api_error::success, ret);
|
||||
}
|
||||
|
||||
TEST_F(s3_comm_test, exists) {
|
||||
EXPECT_EQ(
|
||||
api_error::item_exists,
|
||||
s3_comm_->file_exists("/test.txt", []() -> std::string { return ""; }));
|
||||
EXPECT_EQ(api_error::item_not_found,
|
||||
s3_comm_->file_exists("/subdir/test.txt",
|
||||
[]() -> std::string { return ""; }));
|
||||
}
|
||||
|
||||
TEST_F(s3_comm_test, get_file) {
|
||||
api_file file{};
|
||||
auto ret = s3_comm_->get_file(
|
||||
"/test.txt", []() -> std::string { return ""; },
|
||||
[](const std::string &, const std::string &object_name) -> std::string {
|
||||
return object_name;
|
||||
},
|
||||
[]() -> std::string { return ""; }, file);
|
||||
EXPECT_EQ(api_error::success, ret);
|
||||
}
|
||||
|
||||
TEST_F(s3_comm_test, remove_file) {
|
||||
auto ret =
|
||||
s3_comm_->remove_file("/test.txt", []() -> std::string { return ""; });
|
||||
EXPECT_EQ(api_error::success, ret);
|
||||
ret = s3_comm_->remove_file("/subdir/test2.txt",
|
||||
[]() -> std::string { return ""; });
|
||||
EXPECT_EQ(api_error::success, ret);
|
||||
}
|
||||
|
||||
TEST_F(s3_comm_test, rename_file) {
|
||||
stop_type stop_requested = false;
|
||||
auto ret =
|
||||
s3_comm_->remove_file("/test_r2.txt", []() -> std::string { return ""; });
|
||||
|
||||
ret = s3_comm_->upload_file(
|
||||
"/test_r1.txt", __FILE__, "", []() -> std::string { return ""; },
|
||||
[](const std::string &) -> api_error { return api_error::success; },
|
||||
stop_requested);
|
||||
EXPECT_EQ(api_error::success, ret);
|
||||
|
||||
ret = s3_comm_->rename_file("/test_r1.txt", "/test_r2.txt");
|
||||
EXPECT_EQ(api_error::not_implemented, ret);
|
||||
EXPECT_EQ(api_error::item_exists,
|
||||
s3_comm_->file_exists("/test_r1.txt",
|
||||
[]() -> std::string { return ""; }));
|
||||
EXPECT_EQ(api_error::item_not_found,
|
||||
s3_comm_->file_exists("/test_r2.txt",
|
||||
[]() -> std::string { return ""; }));
|
||||
EXPECT_EQ(api_error::success,
|
||||
s3_comm_->remove_file("/test_r1.txt",
|
||||
[]() -> std::string { return ""; }));
|
||||
}
|
||||
|
||||
TEST_F(s3_comm_test, upload_file_encrypted) {
|
||||
const auto source_file_path = generate_test_file_name("./", "awscomm");
|
||||
auto file_size =
|
||||
2u * utils::encryption::encrypting_reader::get_data_chunk_size() + 3u;
|
||||
auto source_file = create_random_file(source_file_path, file_size);
|
||||
|
||||
stop_type stop_requested = false;
|
||||
std::string key;
|
||||
auto ret = s3_comm_->upload_file(
|
||||
"/test.txt", source_file_path, "test", []() -> std::string { return ""; },
|
||||
[&key](const std::string &k) -> api_error {
|
||||
key = k;
|
||||
std::cout << "key:" << key << std::endl;
|
||||
return api_error::success;
|
||||
},
|
||||
stop_requested);
|
||||
EXPECT_EQ(api_error::success, ret);
|
||||
|
||||
std::uint64_t offset = 0u;
|
||||
auto remain = file_size;
|
||||
while ((ret == api_error::success) && remain) {
|
||||
data_buffer data;
|
||||
ret = s3_comm_->read_file_bytes(
|
||||
"/test.txt",
|
||||
std::min(remain,
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size()),
|
||||
offset, data, [&key]() -> std::string { return key; },
|
||||
[&file_size]() -> std::uint64_t { return file_size; },
|
||||
[]() -> std::string { return "test"; }, stop_requested);
|
||||
EXPECT_EQ(api_error::success, ret);
|
||||
|
||||
data_buffer data2(data.size());
|
||||
std::size_t bytes_read{};
|
||||
EXPECT_TRUE(
|
||||
source_file->read_bytes(&data2[0u], data2.size(), offset, bytes_read));
|
||||
|
||||
EXPECT_EQ(0, std::memcmp(&data2[0u], &data[0u], data2.size()));
|
||||
remain -= data.size();
|
||||
offset += data.size();
|
||||
}
|
||||
|
||||
source_file->close();
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(source_file_path));
|
||||
|
||||
EXPECT_EQ(api_error::success,
|
||||
s3_comm_->remove_file("/test.txt",
|
||||
[&key]() -> std::string { return key; }));
|
||||
}
|
||||
|
||||
TEST_F(s3_comm_test, get_directory_item_count) {}
|
||||
|
||||
TEST_F(s3_comm_test, get_object_list) {}
|
||||
|
||||
TEST_F(s3_comm_test, get_object_name) {}
|
||||
|
||||
TEST_F(s3_comm_test, is_online) {}
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_ENABLE_S3_TESTING
|
@@ -24,11 +24,10 @@
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "comm/curl/curl_comm.hpp"
|
||||
#include "events/consumers/console_consumer.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "file_manager/file_manager.hpp"
|
||||
#include "fixtures/s3_provider_file_list_fixture.hpp"
|
||||
#include "mocks/mock_s3_comm.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "providers/s3/s3_provider.hpp"
|
||||
#include "types/s3.hpp"
|
||||
@@ -37,153 +36,44 @@
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
// TEST(s3_provider, can_construct_s3_provider) {
|
||||
// {
|
||||
// app_config cfg(provider_type::s3, "./s3_provider_test");
|
||||
// EXPECT_FALSE(cfg.set_value_by_name("S3Config.Bucket", "bucket").empty());
|
||||
// EXPECT_FALSE(
|
||||
// cfg.set_value_by_name("S3Config.URL", "https://url.com").empty());
|
||||
// mock_s3_comm comm(cfg.get_s3_config());
|
||||
// s3_provider s3(cfg, comm);
|
||||
// EXPECT_EQ(s3.get_total_item_count(), 0u);
|
||||
// }
|
||||
//
|
||||
// EXPECT_TRUE(utils::file::delete_directory_recursively("./s3_provider_test"));
|
||||
// }
|
||||
//
|
||||
TEST(s3_provider, start_fails_with_empty_bucket) {
|
||||
TEST(s3_provider, get_file_list) {
|
||||
{
|
||||
app_config cfg(provider_type::s3, "./s3_provider_test");
|
||||
EXPECT_TRUE(cfg.set_value_by_name("S3Config.Bucket", "").empty());
|
||||
EXPECT_FALSE(
|
||||
cfg.set_value_by_name("S3Config.URL", "https://url.com").empty());
|
||||
mock_s3_comm comm(cfg.get_s3_config());
|
||||
s3_provider s3(cfg, comm);
|
||||
file_manager fm(cfg, s3);
|
||||
const auto config_path = utils::path::absolute("./s3_provider_test");
|
||||
ASSERT_TRUE(utils::file::delete_directory_recursively(config_path));
|
||||
|
||||
try {
|
||||
auto res = s3.start(
|
||||
[](bool, api_file & /* file */) -> api_error {
|
||||
return api_error::success;
|
||||
console_consumer con{};
|
||||
event_system::instance().start();
|
||||
{
|
||||
app_config cfg(provider_type::s3, config_path);
|
||||
{
|
||||
app_config src_cfg(provider_type::s3,
|
||||
utils::path::combine(get_test_dir(), {"storj"}));
|
||||
cfg.set_s3_config(src_cfg.get_s3_config());
|
||||
}
|
||||
|
||||
curl_comm comm{cfg.get_s3_config()};
|
||||
s3_provider provider{cfg, comm};
|
||||
file_manager mgr(cfg, provider);
|
||||
mgr.start();
|
||||
|
||||
EXPECT_TRUE(provider.start(
|
||||
[&provider](bool directory, api_file &file) -> api_error {
|
||||
return provider_meta_handler(provider, directory, file);
|
||||
},
|
||||
&fm);
|
||||
std::cerr << "unexpected return-should throw|err|" << res << std::endl;
|
||||
} catch (const startup_exception &e) {
|
||||
EXPECT_STREQ("s3 bucket name cannot be empty", e.what());
|
||||
return;
|
||||
&mgr));
|
||||
|
||||
api_file_list list{};
|
||||
EXPECT_EQ(api_error::success, provider.get_file_list(list));
|
||||
provider.stop();
|
||||
mgr.stop();
|
||||
}
|
||||
event_system::instance().stop();
|
||||
|
||||
throw std::runtime_error("exception not thrown");
|
||||
ASSERT_TRUE(utils::file::delete_directory_recursively(config_path));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::delete_directory_recursively("./s3_provider_test"));
|
||||
}
|
||||
|
||||
TEST(s3_provider, start_fails_when_provider_is_offline) {
|
||||
{
|
||||
app_config cfg(provider_type::s3, "./s3_provider_test");
|
||||
EXPECT_FALSE(cfg.set_value_by_name("S3Config.Bucket", "bucket").empty());
|
||||
EXPECT_FALSE(
|
||||
cfg.set_value_by_name("S3Config.URL", "https://url.com").empty());
|
||||
cfg.set_online_check_retry_secs(2u);
|
||||
mock_s3_comm comm(cfg.get_s3_config());
|
||||
s3_provider s3(cfg, comm);
|
||||
file_manager fm(cfg, s3);
|
||||
|
||||
EXPECT_CALL(comm, is_online()).WillRepeatedly(Return(false));
|
||||
EXPECT_FALSE(s3.start([](bool, api_file & /* file */)
|
||||
-> api_error { return api_error::success; },
|
||||
&fm));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::delete_directory_recursively("./s3_provider_test"));
|
||||
}
|
||||
|
||||
// TEST(s3_provider, get_empty_file_list) {
|
||||
// {
|
||||
// app_config cfg(provider_type::s3, "./s3_provider_test");
|
||||
// EXPECT_FALSE(cfg.set_value_by_name("S3Config.Bucket", "bucket").empty());
|
||||
// EXPECT_FALSE(
|
||||
// cfg.set_value_by_name("S3Config.URL", "https://url.com").empty());
|
||||
// cfg.set_online_check_retry_secs(2u);
|
||||
// mock_s3_comm comm(cfg.get_s3_config());
|
||||
// s3_provider s3(cfg, comm);
|
||||
// file_manager fm(cfg, s3);
|
||||
//
|
||||
// api_file_list list{};
|
||||
// EXPECT_CALL(comm, get_file_list)
|
||||
// .WillOnce([](const get_api_file_token_callback &,
|
||||
// const get_name_callback &,
|
||||
// api_file_list &) { return api_error::success; });
|
||||
//
|
||||
// EXPECT_EQ(api_error::success, s3.get_file_list(list));
|
||||
// }
|
||||
//
|
||||
// EXPECT_TRUE(utils::file::delete_directory_recursively("./s3_provider_test"));
|
||||
// }
|
||||
//
|
||||
// TEST_F(s3_provider_file_list_test, can_add_new_files_and_directories) {
|
||||
// provider->set_callback([this](bool directory, api_file &file) -> api_error
|
||||
// {
|
||||
// std::cout << "added|api_path|" << file.api_path << "|api_parent|"
|
||||
// << file.api_parent << "|source|" << file.source_path
|
||||
// << "|directory|" << directory << "|create_date|"
|
||||
// << file.creation_date << "|access_date|" << file.accessed_date
|
||||
// << "|modified_date|" << file.modified_date << "|changed_date|"
|
||||
// << file.changed_date << std::endl;
|
||||
// return provider_meta_handler(*provider, directory, file);
|
||||
// });
|
||||
//
|
||||
// api_file_list l{};
|
||||
// auto res = provider->get_file_list(l);
|
||||
// EXPECT_EQ(api_error::success, res);
|
||||
// EXPECT_EQ(list.size(), l.size());
|
||||
// EXPECT_EQ(std::size_t(22u), provider->get_total_item_count());
|
||||
//
|
||||
// bool exists{};
|
||||
// EXPECT_EQ(api_error::success, provider->is_directory("/", exists));
|
||||
// EXPECT_TRUE(exists);
|
||||
//
|
||||
// EXPECT_EQ(api_error::success, provider->is_directory("/dir", exists));
|
||||
// EXPECT_TRUE(exists);
|
||||
//
|
||||
// const auto check_file = [this, &l](std::size_t idx,
|
||||
// bool check_sub_directory) {
|
||||
// const auto &file = l.at(idx);
|
||||
// const auto base_idx = idx - (check_sub_directory ? l.size() / 2 : 0u);
|
||||
// EXPECT_EQ(this->times[base_idx], file.accessed_date);
|
||||
// if (check_sub_directory) {
|
||||
// EXPECT_EQ(utils::path::create_api_path("/dir/file_" +
|
||||
// std::to_string(base_idx) +
|
||||
// ".txt"),
|
||||
// file.api_path);
|
||||
// EXPECT_EQ(utils::path::get_parent_api_path(utils::path::create_api_path(
|
||||
// "/dir/file_" + std::to_string(base_idx) + ".txt")),
|
||||
// file.api_parent);
|
||||
// } else {
|
||||
// EXPECT_EQ(utils::path::create_api_path("/file_" +
|
||||
// std::to_string(base_idx) +
|
||||
// ".txt"),
|
||||
// file.api_path);
|
||||
// EXPECT_EQ(utils::path::get_parent_api_path(utils::path::create_api_path(
|
||||
// "/file_" + std::to_string(base_idx) + ".txt")),
|
||||
// file.api_parent);
|
||||
// }
|
||||
// EXPECT_EQ(this->times[base_idx] + 1u, file.changed_date);
|
||||
// EXPECT_EQ(this->times[base_idx] + 2u, file.creation_date);
|
||||
// EXPECT_TRUE(file.encryption_token.empty());
|
||||
// EXPECT_EQ(100u + base_idx, file.file_size);
|
||||
// EXPECT_EQ(this->times[base_idx] + 3u, file.modified_date);
|
||||
// };
|
||||
//
|
||||
// for (std::size_t idx = 0u; idx < l.size() / 2u; idx++) {
|
||||
// check_file(idx, false);
|
||||
// }
|
||||
//
|
||||
// for (std::size_t idx = l.size() / 2u; idx < l.size(); idx++) {
|
||||
// check_file(idx, true);
|
||||
// }
|
||||
// }
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_ENABLE_S3_TESTING
|
||||
|
Reference in New Issue
Block a user