[unit test] Complete all providers unit tests #12
This commit is contained in:
@@ -1450,6 +1450,99 @@ static void remove_item_meta_restricted_names_fail(i_provider &provider) {
|
|||||||
EXPECT_EQ(api_error::success, provider.remove_file(api_path));
|
EXPECT_EQ(api_error::success, provider.remove_file(api_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void rename_file(i_provider &provider) {
|
||||||
|
fmt::println("testing|{}|{}",
|
||||||
|
app_config::get_provider_name(provider.get_provider_type()),
|
||||||
|
__FUNCTION__);
|
||||||
|
|
||||||
|
if (not provider.is_rename_supported()) {
|
||||||
|
auto res = provider.rename_file("/rn_src.txt", "/rn_dst.txt");
|
||||||
|
EXPECT_EQ(api_error::not_implemented, res);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string src{"/rn_src.txt"};
|
||||||
|
std::string dst{"/rn_dst.txt"};
|
||||||
|
create_file(provider, src);
|
||||||
|
|
||||||
|
std::string src_meta_size{};
|
||||||
|
std::string src_meta_source{};
|
||||||
|
EXPECT_EQ(api_error::success,
|
||||||
|
provider.get_item_meta(src, META_SIZE, src_meta_size));
|
||||||
|
EXPECT_EQ(api_error::success,
|
||||||
|
provider.get_item_meta(src, META_SOURCE, src_meta_source));
|
||||||
|
|
||||||
|
EXPECT_EQ(api_error::success, provider.rename_file(src, dst));
|
||||||
|
|
||||||
|
bool exists{};
|
||||||
|
EXPECT_EQ(api_error::success, provider.is_file(src, exists));
|
||||||
|
EXPECT_FALSE(exists);
|
||||||
|
EXPECT_EQ(api_error::success, provider.is_file(dst, exists));
|
||||||
|
EXPECT_TRUE(exists);
|
||||||
|
|
||||||
|
std::string dst_meta_size{};
|
||||||
|
std::string dst_meta_source{};
|
||||||
|
EXPECT_EQ(api_error::success,
|
||||||
|
provider.get_item_meta(dst, META_SIZE, dst_meta_size));
|
||||||
|
EXPECT_EQ(api_error::success,
|
||||||
|
provider.get_item_meta(dst, META_SOURCE, dst_meta_source));
|
||||||
|
|
||||||
|
EXPECT_STREQ(src_meta_size.c_str(), dst_meta_size.c_str());
|
||||||
|
EXPECT_STREQ(src_meta_source.c_str(), dst_meta_source.c_str());
|
||||||
|
|
||||||
|
EXPECT_EQ(api_error::success, provider.remove_file(dst));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rename_file_fails_if_source_not_found(i_provider &provider) {
|
||||||
|
fmt::println("testing|{}|{}",
|
||||||
|
app_config::get_provider_name(provider.get_provider_type()),
|
||||||
|
__FUNCTION__);
|
||||||
|
|
||||||
|
if (not provider.is_rename_supported()) {
|
||||||
|
auto res = provider.rename_file("/rn_missing.txt", "/rn_any.txt");
|
||||||
|
EXPECT_EQ(api_error::not_implemented, res);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto res = provider.rename_file("/rn_missing.txt", "/rn_any.txt");
|
||||||
|
EXPECT_EQ(api_error::item_not_found, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rename_file_fails_if_destination_exists(i_provider &provider) {
|
||||||
|
fmt::println("testing|{}|{}",
|
||||||
|
app_config::get_provider_name(provider.get_provider_type()),
|
||||||
|
__FUNCTION__);
|
||||||
|
|
||||||
|
if (not provider.is_rename_supported()) {
|
||||||
|
create_file(provider, "/rn_src_conflict.txt");
|
||||||
|
create_file(provider, "/rn_dst_conflict.txt");
|
||||||
|
auto res =
|
||||||
|
provider.rename_file("/rn_src_conflict.txt", "/rn_dst_conflict.txt");
|
||||||
|
EXPECT_EQ(api_error::not_implemented, res);
|
||||||
|
|
||||||
|
EXPECT_EQ(api_error::success, provider.remove_file("/rn_src_conflict.txt"));
|
||||||
|
EXPECT_EQ(api_error::success, provider.remove_file("/rn_dst_conflict.txt"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string src{"/rn_src_conflict.txt"};
|
||||||
|
std::string dst{"/rn_dst_conflict.txt"};
|
||||||
|
create_file(provider, src);
|
||||||
|
create_file(provider, dst);
|
||||||
|
|
||||||
|
auto res = provider.rename_file(src, dst);
|
||||||
|
EXPECT_EQ(api_error::item_exists, res);
|
||||||
|
|
||||||
|
bool exists{};
|
||||||
|
EXPECT_EQ(api_error::success, provider.is_file(src, exists));
|
||||||
|
EXPECT_TRUE(exists);
|
||||||
|
EXPECT_EQ(api_error::success, provider.is_file(dst, exists));
|
||||||
|
EXPECT_TRUE(exists);
|
||||||
|
|
||||||
|
EXPECT_EQ(api_error::success, provider.remove_file(src));
|
||||||
|
EXPECT_EQ(api_error::success, provider.remove_file(dst));
|
||||||
|
}
|
||||||
|
|
||||||
static void run_tests(const app_config &cfg, i_provider &provider) {
|
static void run_tests(const app_config &cfg, i_provider &provider) {
|
||||||
// MOVED
|
// MOVED
|
||||||
get_file_list(cfg, provider);
|
get_file_list(cfg, provider);
|
||||||
@@ -1519,10 +1612,14 @@ static void run_tests(const app_config &cfg, i_provider &provider) {
|
|||||||
remove_item_meta(provider);
|
remove_item_meta(provider);
|
||||||
remove_item_meta_path_not_found(provider);
|
remove_item_meta_path_not_found(provider);
|
||||||
remove_item_meta_restricted_names_fail(provider);
|
remove_item_meta_restricted_names_fail(provider);
|
||||||
|
|
||||||
|
rename_file(provider);
|
||||||
|
rename_file_fails_if_source_not_found(provider);
|
||||||
|
rename_file_fails_if_destination_exists(provider);
|
||||||
|
|
||||||
// TODO need to test read when file size changes for encrypt provider
|
// TODO need to test read when file size changes for encrypt provider
|
||||||
/*
|
/*
|
||||||
read_file_bytes(provider);
|
read_file_bytes(provider);
|
||||||
rename_file(provider);
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user