[Unit Test] Complete all providers unit tests #12
This commit is contained in:
parent
67fe189765
commit
ad820dcc27
@ -40,6 +40,7 @@
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/polling.hpp"
|
||||
#include <spdlog/fmt/bundled/base.h>
|
||||
|
||||
namespace repertory {
|
||||
encrypt_provider::encrypt_provider(app_config &config)
|
||||
@ -342,13 +343,23 @@ auto encrypt_provider::get_file_list(api_file_list &list,
|
||||
const auto &cfg{get_encrypt_config()};
|
||||
|
||||
try {
|
||||
for (const auto &dir_entry : utils::file::directory{cfg.path}.get_items()) {
|
||||
std::string api_path{};
|
||||
if (process_directory_entry(*dir_entry.get(), cfg, api_path)) {
|
||||
list.emplace_back(create_api_file(
|
||||
api_path, dir_entry->is_directory_item(), dir_entry->get_path()));
|
||||
using func = std::function<void(std::string path)>;
|
||||
const func process_directory = [&](std::string path) {
|
||||
for (const auto &dir_entry : utils::file::directory{path}.get_items()) {
|
||||
std::string api_path{};
|
||||
if (dir_entry->is_directory_item()) {
|
||||
process_directory_entry(*dir_entry.get(), cfg, api_path);
|
||||
process_directory(dir_entry->get_path());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (process_directory_entry(*dir_entry.get(), cfg, api_path)) {
|
||||
list.emplace_back(create_api_file(
|
||||
api_path, dir_entry->is_directory_item(), dir_entry->get_path()));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
process_directory(cfg.path);
|
||||
|
||||
return api_error::success;
|
||||
} catch (const std::exception &ex) {
|
||||
|
@ -19,8 +19,6 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#if 0
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "comm/curl/curl_comm.hpp"
|
||||
@ -346,8 +344,8 @@ create_file_fails_if_directory_already_exists(i_provider &provider) {
|
||||
static void get_api_path_from_source(const app_config &cfg,
|
||||
i_provider &provider) {
|
||||
if (provider.get_provider_type() == provider_type::encrypt) {
|
||||
const auto source_path =
|
||||
utils::path::combine("./test_date/encrypt", {"test.txt"});
|
||||
auto source_path =
|
||||
utils::path::combine("./test_input/encrypt", {"test.txt"});
|
||||
|
||||
std::string api_path{};
|
||||
EXPECT_EQ(api_error::success,
|
||||
@ -391,13 +389,13 @@ get_api_path_from_source_fails_if_file_not_found(const app_config &cfg,
|
||||
EXPECT_TRUE(api_path.empty());
|
||||
}
|
||||
|
||||
static void get_directory_item_count(const app_config &cfg,
|
||||
static void get_directory_item_count(const app_config & /* cfg */,
|
||||
i_provider &provider) {
|
||||
if (provider.get_provider_type() == provider_type::encrypt) {
|
||||
EXPECT_EQ(std::size_t(2U), provider.get_directory_item_count("/"));
|
||||
EXPECT_EQ(std::size_t(0U), provider.get_directory_item_count("/not_found"));
|
||||
|
||||
const auto source_path =
|
||||
auto source_path =
|
||||
utils::path::combine(test::get_test_input_dir(), {"encrypt", "sub10"});
|
||||
|
||||
std::string api_path{};
|
||||
@ -443,7 +441,7 @@ static void get_directory_items(const app_config &cfg, i_provider &provider) {
|
||||
EXPECT_EQ(std::size_t(46U), file->size);
|
||||
#endif
|
||||
|
||||
const auto source_path =
|
||||
auto source_path =
|
||||
utils::path::combine(cfg.get_encrypt_config().path, {"sub10"});
|
||||
std::string api_path{};
|
||||
EXPECT_EQ(api_error::success,
|
||||
@ -486,7 +484,7 @@ get_directory_items_fails_if_directory_not_found(i_provider &provider) {
|
||||
static void get_directory_items_fails_if_item_is_file(const app_config &cfg,
|
||||
i_provider &provider) {
|
||||
if (provider.get_provider_type() == provider_type::encrypt) {
|
||||
const auto source_path =
|
||||
auto source_path =
|
||||
utils::path::combine(cfg.get_encrypt_config().path, {"test.txt"});
|
||||
|
||||
std::string api_path{};
|
||||
@ -502,7 +500,7 @@ static void get_directory_items_fails_if_item_is_file(const app_config &cfg,
|
||||
|
||||
static void get_file(const app_config &cfg, i_provider &provider) {
|
||||
if (provider.get_provider_type() == provider_type::encrypt) {
|
||||
const auto source_path =
|
||||
auto source_path =
|
||||
utils::path::combine(cfg.get_encrypt_config().path, {"test.txt"});
|
||||
|
||||
std::string api_path{};
|
||||
@ -533,7 +531,7 @@ static void get_file_fails_if_file_not_found(i_provider &provider) {
|
||||
static void get_file_fails_if_item_is_directory(const app_config &cfg,
|
||||
i_provider &provider) {
|
||||
if (provider.get_provider_type() == provider_type::encrypt) {
|
||||
const auto source_path =
|
||||
auto source_path =
|
||||
utils::path::combine(cfg.get_encrypt_config().path, {"sub10"});
|
||||
|
||||
std::string api_path{};
|
||||
@ -630,8 +628,9 @@ static void run_tests(const app_config &cfg, i_provider &provider) {
|
||||
}
|
||||
|
||||
TEST(providers_test, encrypt_provider) {
|
||||
const auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {"encrypt_provider"});
|
||||
auto config_path = utils::path::combine(test::get_test_output_dir(),
|
||||
{"provider", "encrypt"});
|
||||
fmt::println("config|{}", config_path);
|
||||
|
||||
console_consumer consumer{};
|
||||
event_system::instance().start();
|
||||
@ -639,8 +638,9 @@ TEST(providers_test, encrypt_provider) {
|
||||
{
|
||||
app_config cfg(provider_type::encrypt, config_path);
|
||||
|
||||
const auto encrypt_path =
|
||||
auto encrypt_path =
|
||||
utils::path::combine(test::get_test_input_dir(), {"encrypt"});
|
||||
fmt::println("encrypt|{}", encrypt_path);
|
||||
|
||||
EXPECT_STREQ(
|
||||
encrypt_path.c_str(),
|
||||
@ -674,8 +674,8 @@ TEST(providers_test, encrypt_provider) {
|
||||
}
|
||||
|
||||
TEST(providers_test, s3_provider) {
|
||||
const auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {"s3_provider"});
|
||||
auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {"provider", "s3"});
|
||||
|
||||
console_consumer consumer{};
|
||||
event_system::instance().start();
|
||||
@ -685,7 +685,7 @@ TEST(providers_test, s3_provider) {
|
||||
{
|
||||
app_config src_cfg(
|
||||
provider_type::s3,
|
||||
utils::path::combine(test::get_test_config_dir(), {"storj"}));
|
||||
utils::path::combine(test::get_test_config_dir(), {"s3"}));
|
||||
cfg.set_s3_config(src_cfg.get_s3_config());
|
||||
}
|
||||
|
||||
@ -714,8 +714,8 @@ TEST(providers_test, s3_provider) {
|
||||
}
|
||||
|
||||
TEST(providers_test, sia_provider) {
|
||||
const auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {"sia_provider"});
|
||||
auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {"sia", "provider"});
|
||||
|
||||
console_consumer consumer{};
|
||||
event_system::instance().start();
|
||||
@ -753,5 +753,3 @@ TEST(providers_test, sia_provider) {
|
||||
event_system::instance().stop();
|
||||
}
|
||||
} // namespace repertory
|
||||
|
||||
#endif // 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user