isolate test directory

This commit is contained in:
Scott E. Graves 2024-07-16 08:54:41 -05:00
parent 2c0935a771
commit 7d5c5e18c6
9 changed files with 191 additions and 659 deletions

View File

@ -29,14 +29,20 @@
namespace repertory {
class config_test : public ::testing::Test {
public:
std::string s3_directory{
utils::path::combine(get_test_dir(), {"config_test", "s3"})};
std::string sia_directory{
utils::path::combine(get_test_dir(), {"config_test", "sia"})};
void SetUp() override {
ASSERT_TRUE(utils::file::delete_directory_recursively(
utils::path::absolute("./data")));
utils::path::combine(get_test_dir(), {"config_test"})));
}
void TearDown() override {
EXPECT_TRUE(utils::file::delete_directory_recursively(
utils::path::absolute("./data")));
ASSERT_TRUE(utils::file::delete_directory_recursively(
utils::path::combine(get_test_dir(), {"config_test"})));
}
};
@ -142,42 +148,42 @@ const auto DEFAULT_S3_CONFIG = "{\n"
"}";
TEST_F(config_test, sia_default_settings) {
const auto config_file = utils::path::absolute(
utils::path::combine("./data/sia", {"config.json"}));
const auto config_file = utils::path::combine(sia_directory, {"config.json"});
for (int i = 0; i < 2; i++) {
app_config config(provider_type::sia, "./data/sia");
app_config config(provider_type::sia, sia_directory);
config.set_remote_token("");
config.set_api_auth("");
EXPECT_TRUE(config.set_value_by_name("HostConfig.ApiPassword", "").empty());
json data;
EXPECT_TRUE(utils::file::read_json_file(config_file, data));
EXPECT_STREQ(DEFAULT_SIA_CONFIG.c_str(), data.dump(2).c_str());
EXPECT_TRUE(utils::file::is_directory("./data/sia/cache"));
EXPECT_TRUE(utils::file::is_directory("./data/sia/logs"));
EXPECT_TRUE(utils::file::is_directory(utils::path::combine(sia_directory, {"cache"}));
EXPECT_TRUE(utils::file::is_directory(utils::path::combine(sia_directory,{"logs"}));
}
}
TEST_F(config_test, s3_default_settings) {
const auto config_file =
utils::path::absolute(utils::path::combine("./data/s3", {"config.json"}));
const auto config_file = utils::path::combine(s3_directory, {"config.json"});
for (int i = 0; i < 2; i++) {
app_config config(provider_type::s3, "./data/s3");
app_config config(provider_type::s3, s3_directory);
config.set_remote_token("");
config.set_api_auth("");
json data;
EXPECT_TRUE(utils::file::read_json_file(config_file, data));
EXPECT_STREQ(DEFAULT_S3_CONFIG.c_str(), data.dump(2).c_str());
EXPECT_TRUE(utils::file::is_directory("./data/s3/cache"));
EXPECT_TRUE(utils::file::is_directory("./data/s3/logs"));
EXPECT_TRUE(utils::file::is_directory(
utils::path::combine(s3_directory, {"cache"})));
EXPECT_TRUE(utils::file::is_directory(
utils::path::combine(s3_directory, {"logs"})));
}
}
TEST_F(config_test, api_path) {
std::string original_value;
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_api_auth();
EXPECT_EQ(48U, original_value.size());
}
@ -186,13 +192,13 @@ TEST_F(config_test, api_path) {
TEST_F(config_test, api_auth) {
std::string original_value;
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_api_auth();
config.set_api_auth(original_value.substr(0, 20));
EXPECT_EQ(original_value.substr(0, 20), config.get_api_auth());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value.substr(0, 20), config.get_api_auth());
}
}
@ -200,13 +206,13 @@ TEST_F(config_test, api_auth) {
TEST_F(config_test, api_port) {
std::uint16_t original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_api_port();
config.set_api_port(original_value + 5);
EXPECT_EQ(original_value + 5, config.get_api_port());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value + 5, config.get_api_port());
}
}
@ -214,13 +220,13 @@ TEST_F(config_test, api_port) {
TEST_F(config_test, api_user) {
std::string original_value;
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_api_user();
config.set_api_user(original_value.substr(0, 2));
EXPECT_EQ(original_value.substr(0, 2), config.get_api_user());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value.substr(0, 2), config.get_api_user());
}
}
@ -228,13 +234,13 @@ TEST_F(config_test, api_user) {
TEST_F(config_test, chunk_downloader_timeout_secs) {
std::uint8_t original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_chunk_downloader_timeout_secs();
config.set_chunk_downloader_timeout_secs(original_value + 5);
EXPECT_EQ(original_value + 5, config.get_chunk_downloader_timeout_secs());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value + 5, config.get_chunk_downloader_timeout_secs());
}
}
@ -242,13 +248,13 @@ TEST_F(config_test, chunk_downloader_timeout_secs) {
TEST_F(config_test, enable_chunk_download_timeout) {
bool original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_enable_chunk_download_timeout();
config.set_enable_chunk_downloader_timeout(not original_value);
EXPECT_EQ(not original_value, config.get_enable_chunk_download_timeout());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(not original_value, config.get_enable_chunk_download_timeout());
}
}
@ -256,13 +262,13 @@ TEST_F(config_test, enable_chunk_download_timeout) {
TEST_F(config_test, enable_comm_duration_events) {
bool original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_enable_comm_duration_events();
config.set_enable_comm_duration_events(not original_value);
EXPECT_EQ(not original_value, config.get_enable_comm_duration_events());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(not original_value, config.get_enable_comm_duration_events());
}
}
@ -270,13 +276,13 @@ TEST_F(config_test, enable_comm_duration_events) {
TEST_F(config_test, enable_drive_events) {
bool original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_enable_drive_events();
config.set_enable_drive_events(not original_value);
EXPECT_EQ(not original_value, config.get_enable_drive_events());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(not original_value, config.get_enable_drive_events());
}
}
@ -284,13 +290,13 @@ TEST_F(config_test, enable_drive_events) {
TEST_F(config_test, enable_max_cache_size) {
bool original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_enable_max_cache_size();
config.set_enable_max_cache_size(not original_value);
EXPECT_EQ(not original_value, config.get_enable_max_cache_size());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(not original_value, config.get_enable_max_cache_size());
}
}
@ -298,27 +304,27 @@ TEST_F(config_test, enable_max_cache_size) {
TEST_F(config_test, enable_mount_manager) {
bool original_value;
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_enable_mount_manager();
config.set_enable_mount_manager(not original_value);
EXPECT_EQ(not original_value, config.get_enable_mount_manager());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(not original_value, config.get_enable_mount_manager());
}
}
#endif
TEST_F(config_test, event_level) {
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_event_level(event_level::debug);
EXPECT_EQ(event_level::debug, config.get_event_level());
config.set_event_level(event_level::warn);
EXPECT_EQ(event_level::warn, config.get_event_level());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(event_level::warn, config.get_event_level());
}
}
@ -326,13 +332,13 @@ TEST_F(config_test, event_level) {
TEST_F(config_test, eviction_delay_mins) {
std::uint32_t original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_eviction_delay_mins();
config.set_eviction_delay_mins(original_value + 5);
EXPECT_EQ(original_value + 5, config.get_eviction_delay_mins());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value + 5, config.get_eviction_delay_mins());
}
}
@ -340,14 +346,14 @@ TEST_F(config_test, eviction_delay_mins) {
TEST_F(config_test, eviction_uses_accessed_time) {
bool original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_eviction_uses_accessed_time();
config.set_eviction_uses_accessed_time(not original_value);
EXPECT_EQ(not original_value, config.get_eviction_uses_accessed_time());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(not original_value, config.get_eviction_uses_accessed_time());
}
}
@ -355,13 +361,13 @@ TEST_F(config_test, eviction_uses_accessed_time) {
TEST_F(config_test, high_frequency_interval_secs) {
std::uint8_t original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_high_frequency_interval_secs();
config.set_high_frequency_interval_secs(original_value + 5);
EXPECT_EQ(original_value + 5, config.get_high_frequency_interval_secs());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value + 5, config.get_high_frequency_interval_secs());
}
}
@ -369,41 +375,41 @@ TEST_F(config_test, high_frequency_interval_secs) {
TEST_F(config_test, low_frequency_interval_secs) {
std::uint32_t original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_low_frequency_interval_secs();
config.set_low_frequency_interval_secs(original_value + 5);
EXPECT_EQ(original_value + 5, config.get_low_frequency_interval_secs());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value + 5, config.get_low_frequency_interval_secs());
}
}
TEST_F(config_test, max_cache_size_bytes) {
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_max_cache_size_bytes(100 * 1024 * 1024);
EXPECT_EQ(100U * 1024 * 1024, config.get_max_cache_size_bytes());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(100U * 1024 * 1024, config.get_max_cache_size_bytes());
}
}
TEST_F(config_test, max_upload_count) {
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_max_upload_count(8U);
EXPECT_EQ(std::uint8_t(8U), config.get_max_upload_count());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(std::uint8_t(8U), config.get_max_upload_count());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_max_upload_count(0U);
EXPECT_EQ(std::uint8_t(1U), config.get_max_upload_count());
}
@ -412,20 +418,20 @@ TEST_F(config_test, max_upload_count) {
TEST_F(config_test, online_check_retry_secs) {
std::uint16_t original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_online_check_retry_secs();
config.set_online_check_retry_secs(original_value + 1);
EXPECT_EQ(original_value + 1, config.get_online_check_retry_secs());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value + 1, config.get_online_check_retry_secs());
}
}
TEST_F(config_test, online_check_retry_secs_minimum_value) {
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_online_check_retry_secs(14);
EXPECT_EQ(15, config.get_online_check_retry_secs());
}
@ -434,20 +440,20 @@ TEST_F(config_test, online_check_retry_secs_minimum_value) {
TEST_F(config_test, orphaned_file_retention_days) {
std::uint16_t original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_orphaned_file_retention_days();
config.set_orphaned_file_retention_days(original_value + 1);
EXPECT_EQ(original_value + 1, config.get_orphaned_file_retention_days());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value + 1, config.get_orphaned_file_retention_days());
}
}
TEST_F(config_test, orphaned_file_retention_days_minimum_value) {
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_orphaned_file_retention_days(0);
EXPECT_EQ(1, config.get_orphaned_file_retention_days());
}
@ -455,7 +461,7 @@ TEST_F(config_test, orphaned_file_retention_days_minimum_value) {
TEST_F(config_test, orphaned_file_retention_days_maximum_value) {
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_orphaned_file_retention_days(32);
EXPECT_EQ(31, config.get_orphaned_file_retention_days());
}
@ -464,21 +470,21 @@ TEST_F(config_test, orphaned_file_retention_days_maximum_value) {
TEST_F(config_test, read_ahead_count) {
std::uint8_t original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_read_ahead_count();
config.set_read_ahead_count(original_value + 5);
EXPECT_EQ(original_value + 5, config.get_read_ahead_count());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value + 5, config.get_read_ahead_count());
}
}
TEST_F(config_test, get_cache_directory) {
{
app_config config(provider_type::sia, "./data/sia");
EXPECT_STREQ(utils::path::absolute("./data/sia/cache").c_str(),
app_config config(provider_type::sia, sia_directory);
EXPECT_STREQ(utils::path::combine(sia_directory, {"cache"}).c_str(),
config.get_cache_directory().c_str());
}
}
@ -486,25 +492,24 @@ TEST_F(config_test, get_cache_directory) {
TEST_F(config_test, get_config_file_path) {
{
const auto config_file = utils::path::absolute(
utils::path::combine("./data/sia", {"config.json"}));
utils::path::combine(sia_directory, {"config.json"}));
app_config config(provider_type::sia, "./data/sia");
app_config config(provider_type::sia, sia_directory);
EXPECT_STREQ(config_file.c_str(), config.get_config_file_path().c_str());
}
}
TEST_F(config_test, get_data_directory) {
{
app_config config(provider_type::sia, "./data/sia");
EXPECT_STREQ(utils::path::absolute("./data/sia").c_str(),
config.get_data_directory().c_str());
app_config config(provider_type::sia, sia_directory);
EXPECT_STREQ(sia_directory.c_str(), config.get_data_directory().c_str());
}
}
TEST_F(config_test, get_log_directory) {
{
app_config config(provider_type::sia, "./data/sia");
EXPECT_STREQ(utils::path::absolute("./data/sia/logs").c_str(),
app_config config(provider_type::sia, sia_directory);
EXPECT_STREQ(utils::path::combine(sia_directory, {"logs"}).c_str(),
config.get_log_directory().c_str());
}
}
@ -512,37 +517,37 @@ TEST_F(config_test, get_log_directory) {
TEST_F(config_test, ring_buffer_file_size) {
std::uint16_t original_value;
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_ring_buffer_file_size();
config.set_ring_buffer_file_size(original_value + 5u);
EXPECT_EQ(original_value + 5u, config.get_ring_buffer_file_size());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value + 5u, config.get_ring_buffer_file_size());
}
}
TEST_F(config_test, ring_buffer_file_size_minimum_size) {
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_ring_buffer_file_size(63u);
EXPECT_EQ(64u, config.get_ring_buffer_file_size());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(64u, config.get_ring_buffer_file_size());
}
}
TEST_F(config_test, ring_buffer_file_size_maximum_size) {
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_ring_buffer_file_size(1025u);
EXPECT_EQ(1024u, config.get_ring_buffer_file_size());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(1024u, config.get_ring_buffer_file_size());
}
}
@ -550,13 +555,13 @@ TEST_F(config_test, ring_buffer_file_size_maximum_size) {
TEST_F(config_test, preferred_download_type) {
download_type original_value;
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_preferred_download_type();
config.set_preferred_download_type(download_type::ring_buffer);
EXPECT_NE(original_value, config.get_preferred_download_type());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_NE(original_value, config.get_preferred_download_type());
}
}
@ -607,7 +612,7 @@ TEST_F(config_test, get_provider_name) {
TEST_F(config_test, get_version) {
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(REPERTORY_CONFIG_VERSION, config.get_version());
}
}
@ -615,13 +620,13 @@ TEST_F(config_test, get_version) {
TEST_F(config_test, enable_remote_mount) {
bool original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_enable_remote_mount();
config.set_enable_remote_mount(not original_value);
EXPECT_EQ(not original_value, config.get_enable_remote_mount());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(not original_value, config.get_enable_remote_mount());
}
}
@ -629,19 +634,19 @@ TEST_F(config_test, enable_remote_mount) {
TEST_F(config_test, is_remote_mount) {
bool original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_is_remote_mount();
config.set_is_remote_mount(not original_value);
EXPECT_EQ(not original_value, config.get_is_remote_mount());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(not original_value, config.get_is_remote_mount());
}
}
TEST_F(config_test, enable_remote_mount_fails_if_remote_mount_is_true) {
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_is_remote_mount(true);
config.set_enable_remote_mount(true);
EXPECT_FALSE(config.get_enable_remote_mount());
@ -649,7 +654,7 @@ TEST_F(config_test, enable_remote_mount_fails_if_remote_mount_is_true) {
}
TEST_F(config_test, set_is_remote_mount_fails_if_enable_remote_mount_is_true) {
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_enable_remote_mount(true);
config.set_is_remote_mount(true);
EXPECT_FALSE(config.get_is_remote_mount());
@ -658,12 +663,12 @@ TEST_F(config_test, set_is_remote_mount_fails_if_enable_remote_mount_is_true) {
TEST_F(config_test, remote_host_name_or_ip) {
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_remote_host_name_or_ip("my.host.name");
EXPECT_STREQ("my.host.name", config.get_remote_host_name_or_ip().c_str());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_STREQ("my.host.name", config.get_remote_host_name_or_ip().c_str());
}
}
@ -671,13 +676,13 @@ TEST_F(config_test, remote_host_name_or_ip) {
TEST_F(config_test, remote_port) {
std::uint16_t original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_remote_port();
config.set_remote_port(original_value + 5);
EXPECT_EQ(original_value + 5, config.get_remote_port());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value + 5, config.get_remote_port());
}
}
@ -685,13 +690,13 @@ TEST_F(config_test, remote_port) {
TEST_F(config_test, remote_receive_timeout_secs) {
std::uint16_t original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_remote_receive_timeout_secs();
config.set_remote_receive_timeout_secs(original_value + 5);
EXPECT_EQ(original_value + 5, config.get_remote_receive_timeout_secs());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value + 5, config.get_remote_receive_timeout_secs());
}
}
@ -699,25 +704,25 @@ TEST_F(config_test, remote_receive_timeout_secs) {
TEST_F(config_test, remote_send_timeout_secs) {
std::uint16_t original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_remote_send_timeout_secs();
config.set_remote_send_timeout_secs(original_value + 5);
EXPECT_EQ(original_value + 5, config.get_remote_send_timeout_secs());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value + 5, config.get_remote_send_timeout_secs());
}
}
TEST_F(config_test, remote_token) {
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_remote_token("myToken");
EXPECT_STREQ("myToken", config.get_remote_token().c_str());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_STREQ("myToken", config.get_remote_token().c_str());
}
}
@ -725,25 +730,25 @@ TEST_F(config_test, remote_token) {
TEST_F(config_test, remote_client_pool_size) {
std::uint8_t original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_remote_client_pool_size();
config.set_remote_client_pool_size(original_value + 5);
EXPECT_EQ(original_value + 5, config.get_remote_client_pool_size());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value + 5, config.get_remote_client_pool_size());
}
}
TEST_F(config_test, remote_client_pool_size_minimum_value) {
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_remote_client_pool_size(0);
EXPECT_EQ(5, config.get_remote_client_pool_size());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(5, config.get_remote_client_pool_size());
}
}
@ -751,25 +756,25 @@ TEST_F(config_test, remote_client_pool_size_minimum_value) {
TEST_F(config_test, remote_max_connections) {
std::uint8_t original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_remote_max_connections();
config.set_remote_max_connections(original_value + 5);
EXPECT_EQ(original_value + 5, config.get_remote_max_connections());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value + 5, config.get_remote_max_connections());
}
}
TEST_F(config_test, remote_max_connections_minimum_value) {
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_remote_max_connections(0);
EXPECT_EQ(1, config.get_remote_max_connections());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(1, config.get_remote_max_connections());
}
}
@ -777,20 +782,20 @@ TEST_F(config_test, remote_max_connections_minimum_value) {
TEST_F(config_test, retry_read_count) {
std::uint16_t original_value{};
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
original_value = config.get_retry_read_count();
config.set_retry_read_count(original_value + 1);
EXPECT_EQ(original_value + 1, config.get_retry_read_count());
}
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
EXPECT_EQ(original_value + 1, config.get_retry_read_count());
}
}
TEST_F(config_test, retry_read_count_minimum_value) {
{
app_config config(provider_type::sia, "./data");
app_config config(provider_type::sia, sia_directory);
config.set_retry_read_count(1);
EXPECT_EQ(2, config.get_retry_read_count());
}
@ -798,7 +803,7 @@ TEST_F(config_test, retry_read_count_minimum_value) {
TEST_F(config_test, cache_timeout_seconds_minimum_value) {
{
app_config config(provider_type::s3, "./data");
app_config config(provider_type::s3, s3_directory);
EXPECT_FALSE(
config.set_value_by_name("S3Config.CacheTimeoutSeconds", "1").empty());
EXPECT_EQ(std::uint16_t(5U), config.get_s3_config().cache_timeout_secs);

View File

@ -1,187 +0,0 @@
/*
Copyright <2018-2024> <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 "app_config.hpp"
#include "file_manager/file_manager.hpp"
#include "events/consumers/console_consumer.hpp"
#include "providers/encrypt/encrypt_provider.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
/*
TEST(encrypt_provider, can_construct_encrypt_provider) {
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
// console_consumer consumer{};
// event_system::instance().start();
{
app_config cfg(provider_type::encrypt, "./encrypt_provider_test");
EXPECT_FALSE(
cfg.set_value_by_name("EncryptConfig.Path", "c:\\src").empty());
encrypt_provider provider(cfg);
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);
},
&mgr));
directory_item_list list{};
EXPECT_EQ(api_error::success, provider.get_directory_items("/", list));
provider.stop();
mgr.stop();
}
// event_system::instance().stop();
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
}
TEST(encrypt_provider, can_get_file_list) {
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
{
console_consumer cc{};
event_system::instance().start();
const auto path = std::filesystem::path(utils::path::absolute(__FILE__))
.parent_path()
.string();
app_config cfg(provider_type::encrypt, "./encrypt_provider_test");
EXPECT_STREQ(
path.c_str(),
cfg.set_value_by_name("EncryptConfig.Path", path.c_str()).c_str());
EXPECT_STREQ(
"test_token",
cfg.set_value_by_name("EncryptConfig.EncryptionToken", "test_token")
.c_str());
encrypt_provider provider(cfg);
api_file_list list{};
EXPECT_EQ(api_error::success, provider.get_file_list(list));
api_file_list list2{};
EXPECT_EQ(api_error::success, provider.get_file_list(list2));
EXPECT_EQ(list.size(), list2.size());
for (std::size_t idx = 0U; idx < list.size(); idx++) {
EXPECT_STREQ(list.at(idx).api_path.c_str(),
list2.at(idx).api_path.c_str());
EXPECT_STREQ(list.at(idx).api_parent.c_str(),
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_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());
EXPECT_EQ(list.at(idx).modified_date, list2.at(idx).modified_date);
EXPECT_STREQ(list.at(idx).source_path.c_str(),
list2.at(idx).source_path.c_str());
}
event_system::instance().stop();
}
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
}
TEST(encrypt_provider, can_encrypt_and_decrypt_file) {
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
{
console_consumer cc{};
event_system::instance().start();
const auto path = std::filesystem::path(utils::path::absolute(__FILE__))
.parent_path()
.string();
app_config cfg(provider_type::encrypt, "./encrypt_provider_test");
EXPECT_STREQ(
path.c_str(),
cfg.set_value_by_name("EncryptConfig.Path", path.c_str()).c_str());
EXPECT_STREQ(
"test_token",
cfg.set_value_by_name("EncryptConfig.EncryptionToken", "test_token")
.c_str());
encrypt_provider provider(cfg);
api_file_list list{};
EXPECT_EQ(api_error::success, provider.get_file_list(list));
for (const auto &file : list) {
std::string file_path{file.api_path};
EXPECT_EQ(api_error::success,
utils::encryption::decrypt_file_path(
cfg.get_encrypt_config().encryption_token, file_path));
file_path =
utils::path::combine(cfg.get_encrypt_config().path, {file_path});
EXPECT_TRUE(std::filesystem::equivalent(file.source_path, file_path));
std::vector<char> encrypted_data{};
stop_type stop_requested = false;
EXPECT_EQ(api_error::success,
provider.read_file_bytes(file.api_path, file.file_size, 0U,
encrypted_data, stop_requested));
EXPECT_EQ(file.file_size, encrypted_data.size());
std::vector<char> decrypted_data{};
EXPECT_TRUE(utils::encryption::decrypt_data(
cfg.get_encrypt_config().encryption_token, encrypted_data,
decrypted_data));
native_file::native_file_ptr nf{};
EXPECT_EQ(api_error::success, native_file::open(file.source_path, nf));
std::uint64_t file_size{};
EXPECT_TRUE(nf->get_file_size(file_size));
EXPECT_EQ(file_size, decrypted_data.size());
std::size_t bytes_read{};
std::vector<char> file_data{};
file_data.resize(file_size);
EXPECT_TRUE(nf->read_bytes(file_data.data(), file_size, 0U, bytes_read));
nf->close();
EXPECT_EQ(file_size, bytes_read);
for (std::uint64_t i = 0U; i < bytes_read; i++) {
ASSERT_EQ(file_data[i], decrypted_data[i]);
}
}
event_system::instance().stop();
}
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
} */
} // namespace repertory

View File

@ -28,7 +28,7 @@
namespace repertory {
static auto get_source_file_name() -> std::string {
return generate_test_file_name("./", "encrypting_reader");
return generate_test_file_name(get_test_dir(), "encrypting_reader");
}
TEST(encrypting_reader, get_encrypted_file_name) {

View File

@ -54,7 +54,8 @@ static void validate_write(file_manager::open_file &o, std::size_t offset,
}
TEST(open_file, properly_initializes_state_for_0_byte_file) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;
@ -74,7 +75,8 @@ TEST(open_file, properly_initializes_state_for_0_byte_file) {
}
TEST(open_file, properly_initializes_state_based_on_chunk_size) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;
@ -106,7 +108,8 @@ TEST(open_file, properly_initializes_state_based_on_chunk_size) {
}
TEST(open_file, will_not_change_source_path_for_0_byte_file) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;
@ -129,7 +132,8 @@ TEST(open_file, will_not_change_source_path_for_0_byte_file) {
}
TEST(open_file, will_change_source_path_if_file_size_is_greater_than_0) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;
@ -167,7 +171,8 @@ TEST(open_file, will_change_source_path_if_file_size_is_greater_than_0) {
TEST(open_file,
will_not_change_source_path_if_file_size_matches_existing_source) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "file_manager_open_file_test");
create_random_file(source_path, test_chunk_size)->close();
mock_provider mp;
@ -191,8 +196,10 @@ TEST(open_file,
}
TEST(open_file, write_with_incomplete_download) {
const auto source_path = generate_test_file_name(".", "test");
auto nf = create_random_file(generate_test_file_name(".", "test_src"),
const auto source_path =
generate_test_file_name(get_test_dir(), "file_manager_open_file_test");
auto nf = create_random_file(
generate_test_file_name(get_test_dir(), "file_manager_open_file_test"),
test_chunk_size * 2u);
mock_provider mp;
@ -281,7 +288,8 @@ TEST(open_file, write_with_incomplete_download) {
}
TEST(open_file, write_new_file) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;
@ -353,7 +361,8 @@ TEST(open_file, write_new_file) {
}
TEST(open_file, write_new_file_multiple_chunks) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;
@ -444,7 +453,8 @@ TEST(open_file, write_new_file_multiple_chunks) {
}
TEST(open_file, resize_file_to_0_bytes) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "file_manager_open_file_test");
create_random_file(source_path, test_chunk_size * 4u)->close();
mock_provider mp;
@ -493,7 +503,8 @@ TEST(open_file, resize_file_to_0_bytes) {
}
TEST(open_file, resize_file_by_full_chunk) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "file_manager_open_file_test");
create_random_file(source_path, test_chunk_size * 4u)->close();
mock_provider mp;
@ -544,7 +555,8 @@ TEST(open_file, resize_file_by_full_chunk) {
TEST(open_file, can_add_handle) {
event_system::instance().start();
console_consumer c;
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;
@ -605,7 +617,8 @@ TEST(open_file, can_remove_handle) {
event_system::instance().start();
console_consumer c;
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;

View File

@ -31,7 +31,8 @@ namespace repertory {
static constexpr const std::size_t test_chunk_size = 1024u;
TEST(ring_buffer_open_file, can_forward_to_last_chunk) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
mock_provider mp;
@ -63,7 +64,8 @@ TEST(ring_buffer_open_file, can_forward_to_last_chunk) {
TEST(ring_buffer_open_file,
can_forward_to_last_chunk_if_count_is_greater_than_remaining) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
mock_provider mp;
@ -94,7 +96,8 @@ TEST(ring_buffer_open_file,
}
TEST(ring_buffer_open_file, can_forward_after_last_chunk) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
mock_provider mp;
@ -126,7 +129,8 @@ TEST(ring_buffer_open_file, can_forward_after_last_chunk) {
}
TEST(ring_buffer_open_file, can_forward_and_rollover_after_last_chunk) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
mock_provider mp;
@ -154,7 +158,8 @@ TEST(ring_buffer_open_file, can_forward_and_rollover_after_last_chunk) {
}
TEST(ring_buffer_open_file, can_reverse_to_first_chunk) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
mock_provider mp;
@ -186,7 +191,8 @@ TEST(ring_buffer_open_file, can_reverse_to_first_chunk) {
TEST(ring_buffer_open_file,
can_reverse_to_first_chunk_if_count_is_greater_than_remaining) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
mock_provider mp;
@ -217,7 +223,8 @@ TEST(ring_buffer_open_file,
}
TEST(ring_buffer_open_file, can_reverse_before_first_chunk) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
mock_provider mp;
@ -249,7 +256,8 @@ TEST(ring_buffer_open_file, can_reverse_before_first_chunk) {
}
TEST(ring_buffer_open_file, can_reverse_and_rollover_before_first_chunk) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
mock_provider mp;
@ -285,7 +293,8 @@ TEST(ring_buffer_open_file, can_reverse_and_rollover_before_first_chunk) {
}
TEST(ring_buffer_open_file, can_reverse_full_ring) {
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
mock_provider mp;
@ -317,10 +326,12 @@ TEST(ring_buffer_open_file, can_reverse_full_ring) {
}
TEST(ring_buffer_open_file, read_full_file) {
const auto download_source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
auto nf = create_random_file(download_source_path, test_chunk_size * 32u);
const auto dest_path = generate_test_file_name(".", "test");
const auto dest_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
mock_provider mp;
@ -330,7 +341,8 @@ TEST(ring_buffer_open_file, read_full_file) {
fsi.directory = false;
fsi.api_path = "/test.txt";
fsi.size = test_chunk_size * 32u;
fsi.source_path = generate_test_file_name(".", "test");
fsi.source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
EXPECT_CALL(mp, read_file_bytes)
.WillRepeatedly([&nf](const std::string & /* api_path */,
@ -378,10 +390,12 @@ TEST(ring_buffer_open_file, read_full_file) {
}
TEST(ring_buffer_open_file, read_full_file_in_reverse) {
const auto download_source_path = generate_test_file_name(".", "test");
const auto download_source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
auto nf = create_random_file(download_source_path, test_chunk_size * 32u);
const auto dest_path = generate_test_file_name(".", "test");
const auto dest_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
mock_provider mp;
@ -391,7 +405,8 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) {
fsi.directory = false;
fsi.api_path = "/test.txt";
fsi.size = test_chunk_size * 32u;
fsi.source_path = generate_test_file_name(".", "test");
fsi.source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
EXPECT_CALL(mp, read_file_bytes)
.WillRepeatedly([&nf](const std::string & /* api_path */,
@ -439,10 +454,12 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) {
}
TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
const auto download_source_path = generate_test_file_name(".", "test");
const auto download_source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
auto nf = create_random_file(download_source_path, test_chunk_size * 32u);
const auto dest_path = generate_test_file_name(".", "test");
const auto dest_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
mock_provider mp;
@ -452,7 +469,8 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
fsi.directory = false;
fsi.api_path = "/test.txt";
fsi.size = test_chunk_size * 32u;
fsi.source_path = generate_test_file_name(".", "test");
fsi.source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
EXPECT_CALL(mp, read_file_bytes)
.WillRepeatedly([&nf](const std::string & /* api_path */,
@ -498,10 +516,12 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
}
TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
const auto download_source_path = generate_test_file_name(".", "test");
const auto download_source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
auto nf = create_random_file(download_source_path, test_chunk_size * 32u);
const auto dest_path = generate_test_file_name(".", "test");
const auto dest_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
mock_provider mp;
@ -511,7 +531,8 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
fsi.directory = false;
fsi.api_path = "/test.txt";
fsi.size = test_chunk_size * 32u;
fsi.source_path = generate_test_file_name(".", "test");
fsi.source_path =
generate_test_file_name(get_test_dir(), "ring_buffer_open_file");
EXPECT_CALL(mp, read_file_bytes)
.WillRepeatedly([&nf](const std::string & /* api_path */,

View File

@ -422,7 +422,8 @@ TEST(file_manager, download_is_stored_after_write_if_partially_downloaded) {
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"),
auto nf = create_random_file(
generate_test_file_name(get_test_dir(), "file_manage_test"),
utils::string::to_uint64(meta[META_SIZE]));
EXPECT_CALL(mp, get_filesystem_item)
@ -584,7 +585,8 @@ TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
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"),
auto nf = create_random_file(
generate_test_file_name(get_test_dir(), "file_manage_test"),
utils::string::to_uint64(meta[META_SIZE]));
EXPECT_CALL(mp, get_filesystem_item)

View File

@ -35,7 +35,8 @@ TEST(upload, can_upload_a_valid_file) {
event_system::instance().start();
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "upload_test");
mock_provider mp;
@ -78,7 +79,8 @@ TEST(upload, can_cancel_upload) {
event_system::instance().start();
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "upload_test");
// create_random_file(source_path, test_chunk_size * 4u)->close();
mock_provider mp;
@ -144,7 +146,8 @@ TEST(upload, can_stop_upload) {
event_system::instance().start();
const auto source_path = generate_test_file_name(".", "test");
const auto source_path =
generate_test_file_name(get_test_dir(), "upload_test");
mock_provider mp;

View File

@ -106,7 +106,8 @@ const auto create_directory = [](repertory::i_provider &provider,
const auto create_file = [](repertory::i_provider &provider,
const std::string &api_path) {
auto source_path = repertory::generate_test_file_name(".", "test");
auto source_path = repertory::generate_test_file_name(
repertory::get_test_dir(), "providers_test");
auto date = repertory::utils::get_file_time_now();
auto meta = repertory::create_meta_attributes(

View File

@ -1,326 +0,0 @@
/*
Copyright <2018-2024> <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 "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 "platform/platform.hpp"
#include "providers/sia/sia_provider.hpp"
#include "types/startup_exception.hpp"
#include "utils/path_utils.hpp"
#include "utils/utils.hpp"
namespace repertory {
/* TEST(sia_provider, can_construct_sia_provider) {
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider provider(cfg, comm);
EXPECT_EQ(provider_type::sia, provider.get_provider_type());
EXPECT_FALSE(provider.is_direct_only());
EXPECT_FALSE(provider.is_rename_supported());
}
TEST(sia_provider, can_create_and_remove_directory) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
api_meta_map meta{};
meta[META_ACCESSED] = std::to_string(utils::get_file_time_now());
meta[META_CHANGED] = std::to_string(utils::get_file_time_now());
meta[META_CREATION] = std::to_string(utils::get_file_time_now());
meta[META_MODIFIED] = std::to_string(utils::get_file_time_now());
EXPECT_EQ(api_error::success, provider.create_directory("/moose2", meta));
bool exists{};
EXPECT_EQ(api_error::success, provider.is_directory("/moose2", exists));
EXPECT_TRUE(exists);
EXPECT_EQ(api_error::success, provider.is_file("/moose2", exists));
EXPECT_FALSE(exists);
EXPECT_FALSE(provider.is_file_writeable("/moose2"));
EXPECT_EQ(api_error::directory_exists, provider.remove_file("/moose2"));
EXPECT_EQ(api_error::success, provider.remove_directory("/moose2"));
api_meta_map m{};
EXPECT_EQ(api_error::item_not_found, provider.get_item_meta("/moose2", m));
EXPECT_TRUE(m.empty());
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_create_and_remove_file) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
api_meta_map meta{};
meta[META_ACCESSED] = std::to_string(utils::get_file_time_now());
meta[META_CHANGED] = std::to_string(utils::get_file_time_now());
meta[META_CREATION] = std::to_string(utils::get_file_time_now());
meta[META_MODIFIED] = std::to_string(utils::get_file_time_now());
meta[META_SIZE] = "0";
EXPECT_EQ(api_error::success, provider.create_file("/moose.txt", meta));
bool exists{};
EXPECT_EQ(api_error::success, provider.is_file("/moose.txt", exists));
EXPECT_TRUE(exists);
EXPECT_EQ(api_error::success, provider.is_directory("/moose.txt", exists));
EXPECT_FALSE(exists);
EXPECT_TRUE(provider.is_file_writeable("/moose.txt"));
EXPECT_EQ(api_error::item_not_found, provider.remove_directory("/moose.txt"));
EXPECT_EQ(api_error::success, provider.remove_file("/moose.txt"));
api_meta_map m{};
EXPECT_EQ(api_error::item_not_found, provider.get_item_meta("/moose.txt", m));
EXPECT_TRUE(m.empty());
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_get_file_list) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
api_file_list list{};
EXPECT_EQ(api_error::success, provider.get_file_list(list));
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_get_and_set_item_meta) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
api_meta_map meta{};
meta[META_ACCESSED] = std::to_string(utils::get_file_time_now());
meta[META_CHANGED] = std::to_string(utils::get_file_time_now());
meta[META_CREATION] = std::to_string(utils::get_file_time_now());
meta[META_MODIFIED] = std::to_string(utils::get_file_time_now());
EXPECT_EQ(api_error::success, provider.create_directory("/moose2", meta));
EXPECT_EQ(api_error::success, provider.create_file("/moose2.txt", meta));
{
api_meta_map m{
{"test_one", "one"},
{"test_two", "two"},
};
EXPECT_EQ(api_error::success, provider.set_item_meta("/moose2", m));
api_meta_map m2{};
EXPECT_EQ(api_error::success, provider.get_item_meta("/moose2", m2));
EXPECT_EQ(meta.size() + m.size(), m2.size());
EXPECT_STREQ("one", m2["test_one"].c_str());
EXPECT_STREQ("two", m2["test_two"].c_str());
}
{
api_meta_map m{
{"test_one", "one1"},
{"test_two", "two2"},
};
EXPECT_EQ(api_error::success, provider.set_item_meta("/moose2.txt", m));
api_meta_map m2{};
EXPECT_EQ(api_error::success, provider.get_item_meta("/moose2.txt", m2));
EXPECT_EQ(meta.size() + m.size(), m2.size());
EXPECT_STREQ("one1", m2["test_one"].c_str());
EXPECT_STREQ("two2", m2["test_two"].c_str());
}
EXPECT_EQ(api_error::success, provider.remove_directory("/moose2"));
EXPECT_EQ(api_error::success, provider.remove_file("/moose2.txt"));
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_get_and_set_individual_item_meta) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
api_meta_map meta{};
meta[META_ACCESSED] = std::to_string(utils::get_file_time_now());
meta[META_CHANGED] = std::to_string(utils::get_file_time_now());
meta[META_CREATION] = std::to_string(utils::get_file_time_now());
meta[META_MODIFIED] = std::to_string(utils::get_file_time_now());
EXPECT_EQ(api_error::success, provider.create_directory("/moose2", meta));
EXPECT_EQ(api_error::success, provider.create_file("/moose2.txt", meta));
{
EXPECT_EQ(api_error::success,
provider.set_item_meta("/moose2", "test_meta", "cow2"));
std::string value{};
EXPECT_EQ(api_error::success,
provider.get_item_meta("/moose2", "test_meta", value));
EXPECT_STREQ("cow2", value.c_str());
}
{
EXPECT_EQ(api_error::success,
provider.set_item_meta("/moose2.txt", "test_meta", "cow"));
std::string value{};
EXPECT_EQ(api_error::success,
provider.get_item_meta("/moose2.txt", "test_meta", value));
EXPECT_STREQ("cow", value.c_str());
}
EXPECT_EQ(api_error::success, provider.remove_directory("/moose2"));
EXPECT_EQ(api_error::success, provider.remove_file("/moose2.txt"));
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_read_file_bytes) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
data_buffer data{};
stop_type stop_requested = false;
EXPECT_EQ(api_error::success,
provider.read_file_bytes("/renterd_linux_amd64.zip", 10U, 0U, data,
stop_requested));
EXPECT_EQ(10U, data.size());
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_upload_file) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
stop_type stop_requested = false;
EXPECT_EQ(api_error::success,
provider.upload_file("/sia_provider_test.cpp", __FILE__, "",
stop_requested));
api_meta_map meta = {{"test", "test"}};
EXPECT_EQ(api_error::success,
provider.set_item_meta("/sia_provider_test.cpp", meta));
EXPECT_EQ(api_error::success, provider.remove_file("/sia_provider_test.cpp"));
provider.stop();
event_system::instance().stop();
} */
} // namespace repertory