2.0.0-rc (#9)
Some checks failed
BlockStorage/repertory_osx/pipeline/head This commit looks good
BlockStorage/repertory_windows/pipeline/head This commit looks good
BlockStorage/repertory/pipeline/head There was a failure building this commit
BlockStorage/repertory_linux_builds/pipeline/head This commit looks good
BlockStorage/repertory_osx_builds/pipeline/head There was a failure building this commit
Some checks failed
BlockStorage/repertory_osx/pipeline/head This commit looks good
BlockStorage/repertory_windows/pipeline/head This commit looks good
BlockStorage/repertory/pipeline/head There was a failure building this commit
BlockStorage/repertory_linux_builds/pipeline/head This commit looks good
BlockStorage/repertory_osx_builds/pipeline/head There was a failure building this commit
### Issues * \#1 \[bug\] Unable to mount S3 due to 'item_not_found' exception * \#2 Require bucket name for S3 mounts * \#3 \[bug\] File size is not being updated in S3 mount * \#4 Upgrade to libfuse-3.x.x * \#5 Switch to renterd for Sia support * \#6 Switch to cpp-httplib to further reduce dependencies * \#7 Remove global_data and calculate used disk space per provider * \#8 Switch to libcurl for S3 mount support ### Changes from v1.x.x * Added read-only encrypt provider * Pass-through mount point that transparently encrypts source data using `XChaCha20-Poly1305` * Added S3 encryption support via `XChaCha20-Poly1305` * Added replay protection to remote mounts * Added support base64 writes in remote FUSE * Created static linked Linux binaries for `amd64` and `aarch64` using `musl-libc` * Removed legacy Sia renter support * Removed Skynet support * Fixed multiple remote mount WinFSP API issues on \*NIX servers * Implemented chunked read and write * Writes for non-cached files are performed in chunks of 8Mib * Removed `repertory-ui` support * Removed `FreeBSD` support * Switched to `libsodium` over `CryptoPP` * Switched to `XChaCha20-Poly1305` for remote mounts * Updated `GoogleTest` to v1.14.0 * Updated `JSON for Modern C++` to v3.11.2 * Updated `OpenSSL` to v1.1.1w * Updated `RocksDB` to v8.5.3 * Updated `WinFSP` to 2023 * Updated `boost` to v1.78.0 * Updated `cURL` to v8.3.0 * Updated `zlib` to v1.3 * Use `upload_manager` for all providers * Adds a delay to uploads to prevent excessive API calls * Supports re-upload after mount restart for incomplete uploads * NOTE: Uploads for all providers are full file (no resume support) * Multipart upload support is planned for S3 Reviewed-on: #9
This commit is contained in:
@ -1,176 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <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_COMM_HPP_
|
||||
#define TESTS_MOCKS_MOCK_COMM_HPP_
|
||||
|
||||
#include "test_common.hpp"
|
||||
#include "comm/i_comm.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class mock_comm : public virtual i_comm {
|
||||
private:
|
||||
struct mock_data {
|
||||
api_error error;
|
||||
json result;
|
||||
json json_error;
|
||||
bool persist = false;
|
||||
};
|
||||
std::unordered_map<std::string, std::deque<mock_data>> return_lookup_;
|
||||
|
||||
public:
|
||||
void push_return(const std::string &op, const std::string &path, const json &result,
|
||||
const json &error, const api_error &apiError, bool persist = false) {
|
||||
const auto lookup_path = op + path;
|
||||
if (return_lookup_.find(lookup_path) == return_lookup_.end()) {
|
||||
return_lookup_[lookup_path] = std::deque<mock_data>();
|
||||
};
|
||||
mock_data data = {apiError, result, error, persist};
|
||||
return_lookup_[lookup_path].emplace_back(data);
|
||||
}
|
||||
|
||||
void remove_return(const std::string &op, const std::string &path) {
|
||||
const auto lookup_path = op + path;
|
||||
return_lookup_.erase(lookup_path);
|
||||
}
|
||||
|
||||
private:
|
||||
api_error process(const std::string &op, const std::string &path, json &data, json &error) {
|
||||
const auto lookup_path = op + path;
|
||||
if ((return_lookup_.find(lookup_path) == return_lookup_.end()) ||
|
||||
return_lookup_[lookup_path].empty()) {
|
||||
EXPECT_STREQ("", ("unexpected path: " + lookup_path).c_str());
|
||||
return api_error::comm_error;
|
||||
}
|
||||
error = return_lookup_[lookup_path].front().json_error;
|
||||
data = return_lookup_[lookup_path].front().result;
|
||||
const auto ret = return_lookup_[lookup_path].front().error;
|
||||
if (not return_lookup_[lookup_path].front().persist) {
|
||||
return_lookup_[lookup_path].pop_front();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public:
|
||||
api_error get(const std::string &path, json &data, json &error) override {
|
||||
return process("get", path, data, error);
|
||||
}
|
||||
|
||||
api_error get(const host_config &, const std::string &path, json &data, json &error) override {
|
||||
return process("get", path, data, error);
|
||||
}
|
||||
|
||||
api_error get(const std::string &path, const http_parameters &, json &data,
|
||||
json &error) override {
|
||||
return process("get_params", path, data, error);
|
||||
}
|
||||
|
||||
api_error get(const host_config &, const std::string &path, const http_parameters &, json &data,
|
||||
json &error) override {
|
||||
return process("get_params", path, data, error);
|
||||
}
|
||||
|
||||
api_error get_range(const std::string & /*path*/, const std::uint64_t & /*data_size*/,
|
||||
const http_parameters & /*parameters*/,
|
||||
const std::string & /*encryption_token*/, std::vector<char> & /*data*/,
|
||||
const http_ranges & /*ranges*/, json & /*error*/,
|
||||
const bool & /*stop_requested*/) override {
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
api_error get_range(const host_config & /*hc*/, const std::string & /*path*/,
|
||||
const std::uint64_t & /*data_size*/, const http_parameters & /*parameters*/,
|
||||
const std::string & /*encryption_token*/, std::vector<char> & /*data*/,
|
||||
const http_ranges & /*ranges*/, json & /*error*/,
|
||||
const bool & /*stop_requested*/) override {
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
api_error get_range_and_headers(const std::string & /*path*/, const std::uint64_t & /*data_size*/,
|
||||
const http_parameters & /*parameters*/,
|
||||
const std::string & /*encryption_token*/,
|
||||
std::vector<char> & /*data*/, const http_ranges & /*ranges*/,
|
||||
json & /*error*/, http_headers & /*headers*/,
|
||||
const bool & /*stop_requested*/) override {
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
api_error get_range_and_headers(const host_config & /*hc*/, const std::string & /*path*/,
|
||||
const std::uint64_t & /*data_size*/,
|
||||
const http_parameters & /*parameters*/,
|
||||
const std::string & /*encryption_token*/,
|
||||
std::vector<char> & /*data*/, const http_ranges & /*ranges*/,
|
||||
json & /*error*/, http_headers & /*headers*/,
|
||||
const bool & /*stop_requested*/) override {
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
api_error get_raw(const std::string &, const http_parameters &, std::vector<char> &, json &,
|
||||
const bool &) override {
|
||||
throw std::runtime_error("not implemented: get_raw");
|
||||
return api_error::comm_error;
|
||||
}
|
||||
|
||||
api_error get_raw(const host_config &, const std::string &, const http_parameters &,
|
||||
std::vector<char> &, json &, const bool &) override {
|
||||
throw std::runtime_error("not implemented: get_raw");
|
||||
return api_error::comm_error;
|
||||
}
|
||||
|
||||
api_error post(const std::string &path, json &data, json &error) override {
|
||||
return process("post", path, data, error);
|
||||
}
|
||||
|
||||
api_error post(const host_config &, const std::string &path, json &data, json &error) override {
|
||||
return process("post", path, data, error);
|
||||
}
|
||||
|
||||
api_error post(const std::string &path, const http_parameters &, json &data,
|
||||
json &error) override {
|
||||
return process("post_params", path, data, error);
|
||||
}
|
||||
|
||||
api_error post(const host_config &, const std::string &path, const http_parameters &, json &data,
|
||||
json &error) override {
|
||||
return process("post_params", path, data, error);
|
||||
}
|
||||
|
||||
api_error post_file(const std::string &, const std::string &, const http_parameters &, json &,
|
||||
json &, const bool &) override {
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
api_error post_file(const host_config &, const std::string &, const std::string &,
|
||||
const http_parameters &, json &, json &, const bool &) override {
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
api_error post_multipart_file(const std::string &, const std::string &, const std::string &,
|
||||
const std::string &, json &, json &, const bool &) override {
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
api_error post_multipart_file(const host_config &, const std::string &, const std::string &,
|
||||
const std::string &, const std::string &, json &, json &,
|
||||
const bool &) override {
|
||||
return api_error::error;
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // TESTS_MOCKS_MOCK_COMM_HPP_
|
@ -1,26 +1,30 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
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
|
||||
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 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.
|
||||
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_FUSE_DRIVE_HPP_
|
||||
#define TESTS_MOCKS_MOCK_FUSE_DRIVE_HPP_
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "drives/fuse/i_fuse_drive.hpp"
|
||||
#include "types/remote.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
@ -39,11 +43,17 @@ private:
|
||||
std::unordered_map<std::string, api_meta_map> meta_;
|
||||
|
||||
public:
|
||||
api_error check_owner(const std::string &) const override {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
api_error check_parent_access(const std::string &, int) const override {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
std::uint64_t get_directory_item_count(const std::string &) const override { return 1; }
|
||||
std::uint64_t get_directory_item_count(const std::string &) const override {
|
||||
return 1;
|
||||
}
|
||||
|
||||
directory_item_list get_directory_items(const std::string &) const override {
|
||||
directory_item_list list{};
|
||||
@ -67,7 +77,8 @@ public:
|
||||
|
||||
std::uint64_t get_file_size(const std::string &) const override { return 0u; }
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, api_meta_map &meta) const override {
|
||||
api_error get_item_meta(const std::string &api_path,
|
||||
api_meta_map &meta) const override {
|
||||
meta = const_cast<mock_fuse_drive *>(this)->meta_[api_path];
|
||||
return api_error::success;
|
||||
}
|
||||
@ -81,7 +92,9 @@ public:
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
std::uint64_t get_total_drive_space() const override { return 100 * 1024 * 1024; }
|
||||
std::uint64_t get_total_drive_space() const override {
|
||||
return 100 * 1024 * 1024;
|
||||
}
|
||||
|
||||
std::uint64_t get_total_item_count() const override { return 0u; }
|
||||
|
||||
@ -96,22 +109,28 @@ public:
|
||||
|
||||
void populate_stat(const directory_item &, struct stat &) const override {}
|
||||
|
||||
int rename_directory(const std::string &from_api_path, const std::string &to_api_path) override {
|
||||
const auto from_file_path = utils::path::combine(mount_location_, {from_api_path});
|
||||
const auto to_file_path = utils::path::combine(mount_location_, {to_api_path});
|
||||
int rename_directory(const std::string &from_api_path,
|
||||
const std::string &to_api_path) override {
|
||||
const auto from_file_path =
|
||||
utils::path::combine(mount_location_, {from_api_path});
|
||||
const auto to_file_path =
|
||||
utils::path::combine(mount_location_, {to_api_path});
|
||||
return rename(from_file_path.c_str(), to_file_path.c_str());
|
||||
}
|
||||
|
||||
int rename_file(const std::string &from_api_path, const std::string &to_api_path,
|
||||
const bool &overwrite) override {
|
||||
const auto from_file_path = utils::path::combine(mount_location_, {from_api_path});
|
||||
const auto to_file_path = utils::path::combine(mount_location_, {to_api_path});
|
||||
int rename_file(const std::string &from_api_path,
|
||||
const std::string &to_api_path, bool overwrite) override {
|
||||
const auto from_file_path =
|
||||
utils::path::combine(mount_location_, {from_api_path});
|
||||
const auto to_file_path =
|
||||
utils::path::combine(mount_location_, {to_api_path});
|
||||
|
||||
if (overwrite) {
|
||||
if (not utils::file::delete_file(to_file_path)) {
|
||||
if (not utils::file::retry_delete_file(to_file_path)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (utils::file::is_directory(to_file_path) || utils::file::is_file(to_file_path)) {
|
||||
} else if (utils::file::is_directory(to_file_path) ||
|
||||
utils::file::is_file(to_file_path)) {
|
||||
errno = EEXIST;
|
||||
return -1;
|
||||
}
|
||||
@ -125,8 +144,6 @@ public:
|
||||
const std::string &value) override {
|
||||
meta_[api_path][key] = value;
|
||||
}
|
||||
|
||||
void update_directory_item(directory_item &) const override {}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
97
tests/mocks/mock_open_file.hpp
Normal file
97
tests/mocks/mock_open_file.hpp
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
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_OPEN_FILE_HPP_
|
||||
#define TESTS_MOCKS_MOCK_OPEN_FILE_HPP_
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "file_manager/i_open_file.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class mock_open_file : public virtual i_closeable_open_file {
|
||||
public:
|
||||
MOCK_METHOD(std::string, get_api_path, (), (const, override));
|
||||
|
||||
MOCK_METHOD(std::size_t, get_chunk_size, (), (const, override));
|
||||
|
||||
MOCK_METHOD(std::uint64_t, get_file_size, (), (const, override));
|
||||
|
||||
MOCK_METHOD(filesystem_item, get_filesystem_item, (), (const, override));
|
||||
|
||||
MOCK_METHOD(open_file_data, get_open_data, (std::uint64_t handle),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD(std::size_t, get_open_file_count, (), (const, override));
|
||||
|
||||
MOCK_METHOD(boost::dynamic_bitset<>, get_read_state, (), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, get_read_state, (std::size_t chunk), (const, override));
|
||||
|
||||
MOCK_METHOD(std::string, get_source_path, (), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, is_directory, (), (const, override));
|
||||
|
||||
MOCK_METHOD(api_error, native_operation,
|
||||
(const native_operation_callback &cb), (override));
|
||||
|
||||
MOCK_METHOD(api_error, native_operation,
|
||||
(std::uint64_t new_file_size,
|
||||
const native_operation_callback &cb),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(api_error, read,
|
||||
(std::size_t read_size, std::uint64_t read_offset,
|
||||
data_buffer &data),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(api_error, resize, (std::uint64_t new_file_size), (override));
|
||||
|
||||
MOCK_METHOD(void, set_api_path, (const std::string &api_path), (override));
|
||||
|
||||
MOCK_METHOD(api_error, write,
|
||||
(std::uint64_t write_offset, const data_buffer &data,
|
||||
std::size_t &bytes_written),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(void, add, (std::uint64_t handle, open_file_data ofd),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(bool, can_close, (), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, close, (), (override));
|
||||
|
||||
MOCK_METHOD(std::vector<std::uint64_t>, get_handles, (), (const, override));
|
||||
|
||||
MOCK_METHOD((std::map<std::uint64_t, open_file_data>), get_open_data, (),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD(bool, is_complete, (), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, is_modified, (), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, is_write_supported, (), (const, override));
|
||||
|
||||
MOCK_METHOD(void, remove, (std::uint64_t handle), (override));
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // TESTS_MOCKS_MOCK_OPEN_FILE_HPP_
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <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_OPEN_FILE_TABLE_HPP_
|
||||
#define TESTS_MOCKS_MOCK_OPEN_FILE_TABLE_HPP_
|
||||
|
||||
#include "download/download_manager.hpp"
|
||||
#include "drives/i_open_file_table.hpp"
|
||||
#include "test_common.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class mock_open_file_table : public virtual i_open_file_table {
|
||||
public:
|
||||
explicit mock_open_file_table(download_manager *dm = nullptr, filesystem_item *fsi = nullptr)
|
||||
: dm_(dm), fsi_(fsi) {}
|
||||
|
||||
private:
|
||||
download_manager *dm_;
|
||||
filesystem_item *fsi_;
|
||||
|
||||
public:
|
||||
MOCK_CONST_METHOD1(get_open_count, std::uint64_t(const std::string &api_path));
|
||||
|
||||
MOCK_CONST_METHOD0(has_no_open_file_handles, bool());
|
||||
|
||||
MOCK_METHOD1(close, void(const std::uint64_t &handle));
|
||||
|
||||
MOCK_CONST_METHOD1(contains_restore, bool(const std::string &api_path));
|
||||
|
||||
MOCK_METHOD1(evict_file, bool(const std::string &api_path));
|
||||
|
||||
MOCK_CONST_METHOD1(get_directory_items, directory_item_list(const std::string &api_path));
|
||||
|
||||
MOCK_METHOD2(get_open_file, bool(const std::string &api_path, struct filesystem_item *&fsi));
|
||||
|
||||
MOCK_CONST_METHOD0(get_open_files, std::unordered_map<std::string, std::size_t>());
|
||||
|
||||
MOCK_METHOD1(force_schedule_upload, void(const struct filesystem_item &fsi));
|
||||
|
||||
MOCK_METHOD2(open, api_error(const struct filesystem_item &fsi, std::uint64_t &handle));
|
||||
|
||||
MOCK_METHOD3(set_item_meta, api_error(const std::string &api_path, const std::string &key,
|
||||
const std::string &value));
|
||||
bool perform_locked_operation(locked_operation_callback /*locked_operation*/) override {
|
||||
if (fsi_ && dm_) {
|
||||
fsi_->source_path = dm_->get_source_path(fsi_->api_path);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void update_directory_item(directory_item &) const override {}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // TESTS_MOCKS_MOCK_OPEN_FILE_TABLE_HPP_
|
@ -1,84 +1,162 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
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
|
||||
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 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.
|
||||
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_MOCKPROVIDER_HPP_
|
||||
#define TESTS_MOCKS_MOCKPROVIDER_HPP_
|
||||
#ifndef TESTS_MOCKS_MOCK_PROVIDER_HPP_
|
||||
#define TESTS_MOCKS_MOCK_PROVIDER_HPP_
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "test_common.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class mock_provider : public virtual i_provider {
|
||||
public:
|
||||
mock_provider(const bool &allow_rename = true) : allow_rename_(allow_rename) {}
|
||||
mock_provider(bool allow_rename = true) : allow_rename_(allow_rename) {}
|
||||
|
||||
private:
|
||||
const bool allow_rename_;
|
||||
|
||||
public:
|
||||
MOCK_METHOD2(create_directory, api_error(const std::string &api_path, const api_meta_map &meta));
|
||||
MOCK_METHOD2(create_directory_clone_source_meta,
|
||||
api_error(const std::string &source_api_path, const std::string &api_path));
|
||||
MOCK_METHOD2(create_file, api_error(const std::string &api_path, const api_meta_map &meta));
|
||||
MOCK_CONST_METHOD2(get_api_path_from_source,
|
||||
api_error(const std::string &source_path, std::string &api_path));
|
||||
MOCK_CONST_METHOD1(get_directory_item_count, std::uint64_t(const std::string &api_path));
|
||||
MOCK_CONST_METHOD2(get_directory_items,
|
||||
api_error(const std::string &api_path, directory_item_list &list));
|
||||
MOCK_CONST_METHOD2(get_file, api_error(const std::string &api_path, ApiFile &apiFile));
|
||||
MOCK_CONST_METHOD1(get_file_list, api_error(api_file_list &list));
|
||||
MOCK_CONST_METHOD2(get_file_size,
|
||||
api_error(const std::string &api_path, std::uint64_t &file_size));
|
||||
MOCK_CONST_METHOD3(get_filesystem_item, api_error(const std::string &api_path,
|
||||
const bool &directory, filesystem_item &fsi));
|
||||
MOCK_CONST_METHOD2(get_filesystem_item_from_source_path,
|
||||
api_error(const std::string &source_path, filesystem_item &fsi));
|
||||
MOCK_CONST_METHOD2(get_item_meta, api_error(const std::string &api_path, api_meta_map &meta));
|
||||
MOCK_CONST_METHOD3(get_item_meta, api_error(const std::string &api_path, const std::string &key,
|
||||
std::string &value));
|
||||
MOCK_CONST_METHOD0(get_pinned_files, std::vector<std::string>());
|
||||
MOCK_CONST_METHOD0(get_provider_type, provider_type());
|
||||
MOCK_CONST_METHOD0(get_total_drive_space, std::uint64_t());
|
||||
MOCK_CONST_METHOD0(get_total_item_count, std::uint64_t());
|
||||
MOCK_CONST_METHOD0(get_used_drive_space, std::uint64_t());
|
||||
MOCK_CONST_METHOD1(is_directory, bool(const std::string &api_path));
|
||||
MOCK_CONST_METHOD1(is_file, bool(const std::string &api_path));
|
||||
bool is_file_writeable(const std::string &api_path) const override { return true; }
|
||||
MOCK_CONST_METHOD0(IsOnline, bool());
|
||||
MOCK_METHOD(api_error, create_directory,
|
||||
(const std::string &api_path, api_meta_map &meta), (override));
|
||||
|
||||
MOCK_METHOD(api_error, create_directory_clone_source_meta,
|
||||
(const std::string &source_api_path, const std::string &api_path),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(api_error, create_file,
|
||||
(const std::string &api_path, api_meta_map &meta), (override));
|
||||
|
||||
MOCK_METHOD(api_error, get_api_path_from_source,
|
||||
(const std::string &source_path, std::string &api_path),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD(std::uint64_t, get_directory_item_count,
|
||||
(const std::string &api_path), (const, override));
|
||||
|
||||
MOCK_METHOD(api_error, get_directory_items,
|
||||
(const std::string &api_path, directory_item_list &list),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD(api_error, get_file,
|
||||
(const std::string &api_path, api_file &file), (const, override));
|
||||
|
||||
MOCK_METHOD(api_error, get_file_list, (api_file_list & list),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD(api_error, get_file_size,
|
||||
(const std::string &api_path, std::uint64_t &file_size),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD(api_error, get_filesystem_item,
|
||||
(const std::string &api_path, bool directory,
|
||||
filesystem_item &fsi),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD(api_error, get_filesystem_item_and_file,
|
||||
(const std::string &api_path, api_file &file,
|
||||
filesystem_item &fsi),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD(api_error, get_filesystem_item_from_source_path,
|
||||
(const std::string &source_path, filesystem_item &fsi),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD(api_error, get_item_meta,
|
||||
(const std::string &api_path, api_meta_map &meta),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD(api_error, get_item_meta,
|
||||
(const std::string &api_path, const std::string &key,
|
||||
std::string &value),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD((std::vector<std::string>), get_pinned_files, (),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD(provider_type, get_provider_type, (), (const, override));
|
||||
|
||||
MOCK_METHOD(std::uint64_t, get_total_drive_space, (), (const, override));
|
||||
|
||||
MOCK_METHOD(std::uint64_t, get_total_item_count, (), (const, override));
|
||||
|
||||
MOCK_METHOD(std::uint64_t, get_used_drive_space, (), (const, override));
|
||||
|
||||
MOCK_METHOD(bool, is_direct_only, (), (const, override));
|
||||
|
||||
MOCK_METHOD(api_error, is_directory,
|
||||
(const std::string &api_path, bool &exists), (const, override));
|
||||
|
||||
MOCK_METHOD(api_error, is_file, (const std::string &api_path, bool &exists),
|
||||
(const, override));
|
||||
|
||||
bool is_file_writeable(const std::string & /* api_path */) const override {
|
||||
return true;
|
||||
}
|
||||
|
||||
MOCK_METHOD(bool, is_online, (), (const, override));
|
||||
|
||||
bool is_rename_supported() const override { return allow_rename_; }
|
||||
MOCK_METHOD5(read_file_bytes, api_error(const std::string &path, const std::size_t &size,
|
||||
const std::uint64_t &offset, std::vector<char> &data,
|
||||
const bool &stop_requested));
|
||||
MOCK_METHOD1(remove_directory, api_error(const std::string &api_path));
|
||||
MOCK_METHOD1(remove_file, api_error(const std::string &api_path));
|
||||
MOCK_METHOD2(remove_item_meta, api_error(const std::string &api_path, const std::string &key));
|
||||
MOCK_METHOD2(rename_file,
|
||||
api_error(const std::string &from_api_path, const std::string &to_api_path));
|
||||
MOCK_METHOD3(set_item_meta, api_error(const std::string &api_path, const std::string &key,
|
||||
const std::string &value));
|
||||
MOCK_METHOD2(set_item_meta, api_error(const std::string &api_path, const api_meta_map &meta));
|
||||
MOCK_METHOD2(set_source_path,
|
||||
api_error(const std::string &api_path, const std::string &source_path));
|
||||
MOCK_METHOD2(start, bool(api_item_added_callback api_item_added, i_open_file_table *oft));
|
||||
MOCK_METHOD0(stop, void());
|
||||
MOCK_METHOD3(upload_file, api_error(const std::string &api_path, const std::string &source_path,
|
||||
const std::string &encryption_token));
|
||||
|
||||
MOCK_METHOD(api_error, read_file_bytes,
|
||||
(const std::string &path, std::size_t size, std::uint64_t offset,
|
||||
data_buffer &data, stop_type &stop_requested),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(api_error, remove_directory, (const std::string &api_path),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(api_error, remove_file, (const std::string &api_path),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(api_error, remove_item_meta,
|
||||
(const std::string &api_path, const std::string &key),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(api_error, rename_file,
|
||||
(const std::string &from_api_path,
|
||||
const std::string &to_api_path),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(api_error, set_item_meta,
|
||||
(const std::string &api_path, const std::string &key,
|
||||
const std::string &value),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(api_error, set_item_meta,
|
||||
(const std::string &api_path, const api_meta_map &meta),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(bool, start,
|
||||
(api_item_added_callback api_item_added, i_file_manager *fm),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(void, stop, (), (override));
|
||||
|
||||
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),
|
||||
(override));
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // TESTS_MOCKS_MOCKPROVIDER_HPP_
|
||||
#endif // TESTS_MOCKS_MOCK_PROVIDER_HPP_
|
||||
|
@ -1,79 +1,185 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
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
|
||||
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 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.
|
||||
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_
|
||||
#ifdef REPERTORY_ENABLE_S3_TESTING
|
||||
#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 { */
|
||||
/* private: */
|
||||
/* S3Config s3_config_; */
|
||||
/* */
|
||||
/* public: */
|
||||
/* MOCK_METHOD1(create_bucket, api_error(const std::string &api_path)); */
|
||||
/* MOCK_CONST_METHOD1(Exists, bool(const std::string &api_path)); */
|
||||
/* */
|
||||
/* MOCK_CONST_METHOD3(get_bucket_name_and_object_name, */
|
||||
/* void(const std::string &api_path, std::string &bucketName, */
|
||||
/* std::string &objectName)); */
|
||||
/* */
|
||||
/* MOCK_CONST_METHOD2(get_directory_item_count, */
|
||||
/* std::size_t(const std::string &api_path, */
|
||||
/* const MetaProviderCallback &metaProviderCallback)); */
|
||||
/* */
|
||||
/* MOCK_CONST_METHOD3(get_directory_items, */
|
||||
/* api_error(const std::string &api_path, */
|
||||
/* const MetaProviderCallback &metaProviderCallback, */
|
||||
/* directory_item_list &list)); */
|
||||
/* */
|
||||
/* S3Config GetS3Config() override { return s3Config_; } */
|
||||
/* */
|
||||
/* S3Config GetS3Config() const override { return s3Config_; } */
|
||||
/* */
|
||||
/* MOCK_CONST_METHOD2(GetFile, api_error(const std::string &api_path, ApiFile &apiFile)); */
|
||||
/* */
|
||||
/* MOCK_CONST_METHOD1(get_file_list, api_error(ApiFileList &apiFileList)); */
|
||||
/* */
|
||||
/* bool IsOnline() const override { return true; } */
|
||||
/* */
|
||||
/* MOCK_CONST_METHOD5(read_file_bytes, */
|
||||
/* api_error(const std::string &path, const std::size_t &size, */
|
||||
/* const std::uint64_t &offset, std::vector<char> &data, */
|
||||
/* const bool &stop_requested)); */
|
||||
/* */
|
||||
/* MOCK_METHOD1(remove_bucket, api_error(const std::string &api_path)); */
|
||||
/* */
|
||||
/* MOCK_METHOD1(RemoveFile, api_error(const std::string &api_path)); */
|
||||
/* */
|
||||
/* MOCK_METHOD2(RenameFile, */
|
||||
/* api_error(const std::string &api_path, const std::string &newApiFilePath));
|
||||
*/
|
||||
/* */
|
||||
/* void SetS3Config(S3Config s3Config) { s3Config_ = std::move(s3Config); } */
|
||||
/* */
|
||||
/* MOCK_METHOD3(upload_file, api_error(const std::string &api_path, */
|
||||
/* const std::string &sourcePath, const bool
|
||||
* &stop_requested)); */
|
||||
/* }; */
|
||||
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
|
||||
|
44
tests/mocks/mock_upload_manager.hpp
Normal file
44
tests/mocks/mock_upload_manager.hpp
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
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_UPLOAD_MANAGER_HPP_
|
||||
#define TESTS_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "file_manager/i_upload_manager.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class mock_upload_manager : public i_upload_manager {
|
||||
public:
|
||||
MOCK_METHOD(void, queue_upload, (const i_open_file &o), (override));
|
||||
|
||||
MOCK_METHOD(void, remove_resume,
|
||||
(const std::string &api_path, const std::string &source_path),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(void, remove_upload, (const std::string &api_path), (override));
|
||||
|
||||
MOCK_METHOD(void, store_resume, (const i_open_file &o), (override));
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // TESTS_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
|
@ -1,26 +1,30 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
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
|
||||
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 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.
|
||||
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_WINFSP_DRIVE_HPP_
|
||||
#define TESTS_MOCKS_MOCK_WINFSP_DRIVE_HPP_
|
||||
#ifdef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "drives/winfsp/i_winfsp_drive.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/path_utils.hpp"
|
||||
@ -29,15 +33,21 @@
|
||||
namespace repertory {
|
||||
class mock_winfsp_drive final : public virtual i_winfsp_drive {
|
||||
public:
|
||||
explicit mock_winfsp_drive(const std::string &mount_location) : mount_location_(mount_location) {}
|
||||
explicit mock_winfsp_drive(std::string mount_location)
|
||||
: mount_location_(std::move(mount_location)) {}
|
||||
|
||||
private:
|
||||
const std::string mount_location_;
|
||||
|
||||
public:
|
||||
std::uint64_t get_directory_item_count(const std::string &api_path) const override { return 1; }
|
||||
[[nodiscard]] auto
|
||||
get_directory_item_count(const std::string & /*api_path*/) const
|
||||
-> std::uint64_t override {
|
||||
return 1;
|
||||
}
|
||||
|
||||
directory_item_list get_directory_items(const std::string &api_path) const override {
|
||||
[[nodiscard]] auto get_directory_items(const std::string & /*api_path*/) const
|
||||
-> directory_item_list override {
|
||||
directory_item_list list{};
|
||||
|
||||
directory_item di{};
|
||||
@ -57,20 +67,26 @@ public:
|
||||
return list;
|
||||
}
|
||||
|
||||
std::uint64_t get_file_size(const std::string &api_path) const override { return 0; }
|
||||
[[nodiscard]] auto get_file_size(const std::string & /*api_path*/) const
|
||||
-> std::uint64_t override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, api_meta_map &meta) const override {
|
||||
auto get_item_meta(const std::string & /*api_path*/, api_meta_map &meta) const
|
||||
-> api_error override {
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, const std::string &name,
|
||||
std::string &value) const override {
|
||||
auto get_item_meta(const std::string & /*api_path*/,
|
||||
const std::string & /*name*/,
|
||||
std::string & /*value*/) const -> api_error override {
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
NTSTATUS get_security_by_name(PWSTR file_name, PUINT32 attributes,
|
||||
PSECURITY_DESCRIPTOR descriptor,
|
||||
std::uint64_t *descriptor_size) override {
|
||||
auto get_security_by_name(PWSTR /*file_name*/, PUINT32 attributes,
|
||||
PSECURITY_DESCRIPTOR descriptor,
|
||||
std::uint64_t *descriptor_size)
|
||||
-> NTSTATUS override {
|
||||
auto ret = STATUS_SUCCESS;
|
||||
|
||||
if (attributes) {
|
||||
@ -81,7 +97,8 @@ public:
|
||||
ULONG sz = 0;
|
||||
PSECURITY_DESCRIPTOR sd = nullptr;
|
||||
if (::ConvertStringSecurityDescriptorToSecurityDescriptor(
|
||||
"O:BAG:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;WD)", SDDL_REVISION_1, &sd, &sz)) {
|
||||
"O:BAG:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;WD)",
|
||||
SDDL_REVISION_1, &sd, &sz)) {
|
||||
if (sz > *descriptor_size) {
|
||||
ret = STATUS_BUFFER_TOO_SMALL;
|
||||
} else {
|
||||
@ -97,11 +114,17 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::uint64_t get_total_drive_space() const override { return 100 * 1024 * 1024; }
|
||||
[[nodiscard]] auto get_total_drive_space() const -> std::uint64_t override {
|
||||
return 100 * 1024 * 1024;
|
||||
}
|
||||
|
||||
std::uint64_t get_total_item_count() const override { return 0; }
|
||||
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::uint64_t get_used_drive_space() const override { return 0; }
|
||||
[[nodiscard]] auto get_used_drive_space() const -> std::uint64_t override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void get_volume_info(UINT64 &total_size, UINT64 &free_size,
|
||||
std::string &volume_label) const override {
|
||||
@ -110,14 +133,16 @@ public:
|
||||
volume_label = "TestVolumeLabel";
|
||||
}
|
||||
|
||||
api_error populate_file_info(const std::string &api_path, remote::file_info &file_info) override {
|
||||
auto populate_file_info(const std::string &api_path,
|
||||
remote::file_info &file_info) -> api_error override {
|
||||
const auto file_path = utils::path::combine(mount_location_, {api_path});
|
||||
const auto directory = utils::file::is_directory(file_path);
|
||||
const auto attributes =
|
||||
FILE_FLAG_BACKUP_SEMANTICS | (directory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL);
|
||||
FILE_FLAG_BACKUP_SEMANTICS |
|
||||
(directory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL);
|
||||
const auto share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
||||
auto handle = ::CreateFileA(&file_path[0], GENERIC_READ, share_mode, nullptr, OPEN_EXISTING,
|
||||
attributes, nullptr);
|
||||
auto handle = ::CreateFileA(&file_path[0], GENERIC_READ, share_mode,
|
||||
nullptr, OPEN_EXISTING, attributes, nullptr);
|
||||
FILE_BASIC_INFO fi{};
|
||||
::GetFileInformationByHandleEx(handle, FileBasicInfo, &fi, sizeof(fi));
|
||||
if (not directory) {
|
||||
@ -125,7 +150,8 @@ public:
|
||||
}
|
||||
file_info.AllocationSize =
|
||||
directory ? 0
|
||||
: utils::divide_with_ceiling(file_info.FileSize, WINFSP_ALLOCATION_UNIT) *
|
||||
: utils::divide_with_ceiling(file_info.FileSize,
|
||||
WINFSP_ALLOCATION_UNIT) *
|
||||
WINFSP_ALLOCATION_UNIT;
|
||||
file_info.FileAttributes = fi.FileAttributes;
|
||||
file_info.ChangeTime = fi.ChangeTime.QuadPart;
|
||||
|
Reference in New Issue
Block a user