[unit test] Complete all providers unit tests #12
This commit is contained in:
@@ -103,6 +103,7 @@ endforeach
|
||||
endfunction
|
||||
eventlib
|
||||
expect_streq
|
||||
expect_strne
|
||||
fallocate
|
||||
fallocate_impl
|
||||
fext
|
||||
|
221
repertory/repertory_test/include/fixtures/providers_fixture.hpp
Normal file
221
repertory/repertory_test/include/fixtures/providers_fixture.hpp
Normal file
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
Copyright <2018-2025> <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_TEST_INCLUDE_FIXTURES_PROVIDERS_FIXTURE_HPP
|
||||
#define REPERTORY_TEST_INCLUDE_FIXTURES_PROVIDERS_FIXTURE_HPP
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "comm/curl/curl_comm.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "file_manager/file_manager.hpp"
|
||||
#include "fixtures/providers_fixture.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "providers/encrypt/encrypt_provider.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "providers/s3/s3_provider.hpp"
|
||||
#include "providers/sia/sia_provider.hpp"
|
||||
#include "utils/collection.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/time.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
struct encrypt_provider_type final {
|
||||
static constexpr provider_type type{provider_type::encrypt};
|
||||
|
||||
static void setup(std::unique_ptr<i_http_com> &comm,
|
||||
std::unique_ptr<app_config> &config,
|
||||
std::unique_ptr<i_provider> &provider) {
|
||||
auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {
|
||||
"provider",
|
||||
"encrypt",
|
||||
});
|
||||
|
||||
config = std::make_unique<app_config>(type, config_path);
|
||||
|
||||
auto encrypt_path =
|
||||
utils::path::combine(test::get_test_input_dir(), {"encrypt"});
|
||||
|
||||
EXPECT_STREQ(
|
||||
encrypt_path.c_str(),
|
||||
config->set_value_by_name("EncryptConfig.Path", encrypt_path).c_str());
|
||||
EXPECT_STREQ(
|
||||
"test_token",
|
||||
config->set_value_by_name("EncryptConfig.EncryptionToken", "test_token")
|
||||
.c_str());
|
||||
|
||||
provider = std::make_unique<encrypt_provider>(*config);
|
||||
EXPECT_TRUE(provider->is_read_only());
|
||||
EXPECT_FALSE(provider->is_rename_supported());
|
||||
EXPECT_EQ(type, provider->get_provider_type());
|
||||
}
|
||||
};
|
||||
|
||||
struct s3_provider_encrypted_type final {
|
||||
static constexpr provider_type type{provider_type::s3};
|
||||
|
||||
static void setup(std::unique_ptr<i_http_com> &comm,
|
||||
std::unique_ptr<app_config> &config,
|
||||
std::unique_ptr<i_provider> &provider) {
|
||||
auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {
|
||||
"provider",
|
||||
"s3",
|
||||
});
|
||||
|
||||
config = std::make_unique<app_config>(type, config_path);
|
||||
{
|
||||
app_config src_cfg(
|
||||
type, utils::path::combine(test::get_test_config_dir(), {"s3"}));
|
||||
auto s3_cfg = src_cfg.get_s3_config();
|
||||
s3_cfg.encryption_token = "cow_moose_doge_chicken";
|
||||
config->set_s3_config(s3_cfg);
|
||||
}
|
||||
|
||||
comm = std::make_unique<curl_comm>(config->get_s3_config());
|
||||
|
||||
provider = std::make_unique<s3_provider>(*config, *comm);
|
||||
EXPECT_EQ(type, provider->get_provider_type());
|
||||
EXPECT_FALSE(provider->is_read_only());
|
||||
EXPECT_FALSE(provider->is_rename_supported());
|
||||
}
|
||||
};
|
||||
|
||||
struct s3_provider_unencrypted_type final {
|
||||
static constexpr provider_type type{provider_type::s3};
|
||||
|
||||
static void setup(std::unique_ptr<i_http_com> &comm,
|
||||
std::unique_ptr<app_config> &config,
|
||||
std::unique_ptr<i_provider> &provider) {
|
||||
auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {
|
||||
"provider",
|
||||
"s3",
|
||||
});
|
||||
|
||||
config = std::make_unique<app_config>(type, config_path);
|
||||
{
|
||||
app_config src_cfg(
|
||||
type, utils::path::combine(test::get_test_config_dir(), {"s3"}));
|
||||
auto s3_cfg = src_cfg.get_s3_config();
|
||||
s3_cfg.encryption_token = "";
|
||||
config->set_s3_config(s3_cfg);
|
||||
}
|
||||
|
||||
comm = std::make_unique<curl_comm>(config->get_s3_config());
|
||||
|
||||
provider = std::make_unique<s3_provider>(*config, *comm);
|
||||
EXPECT_EQ(type, provider->get_provider_type());
|
||||
EXPECT_FALSE(provider->is_read_only());
|
||||
EXPECT_FALSE(provider->is_rename_supported());
|
||||
}
|
||||
};
|
||||
|
||||
struct sia_provider_type final {
|
||||
static constexpr provider_type type{provider_type::sia};
|
||||
|
||||
static void setup(std::unique_ptr<i_http_com> &comm,
|
||||
std::unique_ptr<app_config> &config,
|
||||
std::unique_ptr<i_provider> &provider) {
|
||||
auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {
|
||||
"provider",
|
||||
"sia",
|
||||
});
|
||||
|
||||
config = std::make_unique<app_config>(type, config_path);
|
||||
{
|
||||
app_config src_cfg(
|
||||
provider_type::sia,
|
||||
utils::path::combine(test::get_test_config_dir(), {"sia"}));
|
||||
config->set_host_config(src_cfg.get_host_config());
|
||||
config->set_sia_config(src_cfg.get_sia_config());
|
||||
}
|
||||
|
||||
comm = std::make_unique<curl_comm>(config->get_host_config());
|
||||
|
||||
provider = std::make_unique<sia_provider>(*config, *comm);
|
||||
|
||||
EXPECT_EQ(type, provider->get_provider_type());
|
||||
EXPECT_FALSE(provider->is_read_only());
|
||||
EXPECT_TRUE(provider->is_rename_supported());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename provider_t> class providers_test : public ::testing::Test {
|
||||
public:
|
||||
static std::unique_ptr<i_http_com> comm;
|
||||
static std::unique_ptr<app_config> config;
|
||||
static std::unique_ptr<file_manager> mgr;
|
||||
static std::unique_ptr<i_provider> provider;
|
||||
static console_consumer consumer{};
|
||||
|
||||
protected:
|
||||
static void SetUpTestCase() {
|
||||
event_system::instance().start();
|
||||
|
||||
provider_t::setup(comm, config, provider);
|
||||
mgr = std::make_unique<file_manager>(*config, *provider);
|
||||
|
||||
EXPECT_TRUE(provider->start(
|
||||
[&provider](bool directory, api_file &file) -> api_error {
|
||||
return provider_meta_handler(*provider, directory, file);
|
||||
},
|
||||
mgr.get()));
|
||||
|
||||
mgr->start();
|
||||
EXPECT_TRUE(provider->is_online());
|
||||
}
|
||||
|
||||
static void TearDownTestCase() {
|
||||
provider->stop();
|
||||
mgr->stop();
|
||||
|
||||
mgr.reset();
|
||||
provider.reset();
|
||||
comm.reset();
|
||||
|
||||
event_system::instance().stop();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename provider_t>
|
||||
std::unique_ptr<i_http_com> providers_test<provider_t>::comm;
|
||||
|
||||
template <typename provider_t>
|
||||
std::unique_ptr<app_config> providers_test<provider_t>::config;
|
||||
|
||||
template <typename provider_t>
|
||||
std::unique_ptr<file_manager> providers_test<provider_t>::mgr;
|
||||
|
||||
template <typename provider_t>
|
||||
std::unique_ptr<i_provider> providers_test<provider_t>::provider;
|
||||
|
||||
using provider_types =
|
||||
::testing::Types<encrypt_provider_type, s3_provider_encrypted_type,
|
||||
s3_provider_unencrypted_type, sia_provider_type>;
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_TEST_INCLUDE_FIXTURES_PROVIDERS_FIXTURE_HPP
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user