1#define BOOST_TEST_MODULE add_file_system
2#include <boost/test/included/unit_test.hpp>
10using namespace boost::system;
22 bfs::space_info
get_space(
const bfs::path&
p, boost::system::error_code& ec)
const {
29 boost::asio::io_context
ctx;
50 mock_get_space = [ i = 0, capacity, available ](
const bfs::path&
p, boost::system::error_code& ec)
mutable -> bfs::space_info {
51 ec = boost::system::errc::make_error_code(errc::success);
54 rc.capacity = capacity[i];
55 rc.available = available[i];
62 buf->st_dev = devs[
j];
70 for (
size_t k = 0; k < capacity.size(); k++) {
76 std::function<bfs::space_info(
const bfs::path&
p, boost::system::error_code& ec)>
mock_get_space;
82BOOST_AUTO_TEST_SUITE(space_handler_tests)
85 mock_get_stat = [](
const char *
path,
struct stat *
buf ) ->
int {
89 BOOST_REQUIRE_THROW(add_file_system(
"/test"), chain::plugin_config_exception);
94 mock_get_space = [](
const bfs::path&
p, boost::system::error_code& ec) -> bfs::space_info {
95 ec = boost::system::errc::make_error_code(errc::no_such_file_or_directory);
100 mock_get_stat = [](
const char *
path,
struct stat *
buf ) ->
int {
105 BOOST_REQUIRE_THROW(add_file_system(
"/test"), chain::plugin_config_exception);
110 std::vector<int> capacity {1000000, 2000000, 3000000, 4000000};
111 std::vector<int> available {500000, 1500000, 2500000, 3500000};
112 std::vector<int> devs {0, 1, 2, 3};
115 BOOST_REQUIRE_NO_THROW(test_add_file_systems_common(capacity, available, devs));
120 std::vector<int> capacity {1000000, 2000000, 3000000, 4000000};
121 std::vector<int> available {500000, 1500000, 2500000, 3500000};
122 std::vector<int> devs {0, 0, 0, 0};
125 BOOST_REQUIRE_NO_THROW(test_add_file_systems_common(capacity, available, devs));
130 std::vector<int> capacity {1000000, 2000000, 3000000, 4000000, 50000};
131 std::vector<int> available {500000, 1500000, 2500000, 3500000, 20000};
132 std::vector<int> devs {0, 2, 2, 0, 3};
135 BOOST_REQUIRE_NO_THROW(test_add_file_systems_common(capacity, available, devs));
138BOOST_AUTO_TEST_SUITE_END()
wraps boost::filesystem::path to provide platform independent path manipulation.
bool is_threshold_exceeded()
void set_threshold(uint32_t new_threshold, uint32_t new_warning_threshold)
void add_file_system(const bfs::path &path_name)
bfs::space_info get_space(const bfs::path &p, boost::system::error_code &ec) const
mock_space_provider(add_file_system_fixture &fixture)
add_file_system_fixture & fixture
int get_stat(const char *path, struct stat *buf) const
file_space_handler_t space_handler
void add_file_system(const bfs::path &path_name)
add_file_system_fixture()
void test_add_file_systems_common(std::vector< int > &capacity, std::vector< int > &available, std::vector< int > &devs)
bool is_threshold_exceeded()
std::function< int(const char *path, struct stat *buf)> mock_get_stat
boost::asio::io_context ctx
void set_threshold(uint32_t threshold, uint32_t warning_threshold)
std::function< bfs::space_info(const bfs::path &p, boost::system::error_code &ec)> mock_get_space
BOOST_FIXTURE_TEST_CASE(get_stat_failure, add_file_system_fixture)