fixes
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit

This commit is contained in:
2024-08-07 19:58:51 -05:00
parent 33fa52f5a4
commit efb2be5839
5 changed files with 68 additions and 21 deletions

View File

@ -22,6 +22,58 @@
#include "test.hpp"
namespace repertory {
TEST(utils_file, can_create_file) {
auto path = test::generate_test_file_name("utils_file");
EXPECT_FALSE(utils::file::is_file(path) || utils::file::is_directory(path));
auto file = utils::file::file::open_or_create_file(path);
EXPECT_TRUE(file);
EXPECT_TRUE(utils::file::is_file(path));
}
TEST(utils_file, can_open_file) {
auto path = test::generate_test_file_name("utils_file");
{
auto file = utils::file::file::open_or_create_file(path);
EXPECT_TRUE(file);
}
{
auto file = utils::file::file::open_file(path);
EXPECT_TRUE(file);
}
}
TEST(utils_file, open_file_fails_if_not_found) {
auto path = test::generate_test_file_name("utils_file");
auto file = utils::file::file::open_file(path);
EXPECT_FALSE(file);
}
TEST(utils_file, write_fails_for_read_only_file) {
auto path = test::generate_test_file_name("utils_file");
auto file = utils::file::file::open_or_create_file(path, true);
EXPECT_TRUE(utils::file::is_file(path));
EXPECT_TRUE(file);
std::size_t bytes_written{};
EXPECT_FALSE(file.write(reinterpret_cast<const unsigned char *>("0"), 1U, 0U,
&bytes_written));
EXPECT_EQ(0U, bytes_written);
}
TEST(utils_file, can_attach_file) {
auto path = test::generate_test_file_name("utils_file");
auto file = utils::file::file::open_or_create_file(path);
auto file2 = utils::file::file::attach_file(file.get_handle());
EXPECT_TRUE(file);
EXPECT_TRUE(file2);
EXPECT_EQ(file.get_path(), file2.get_path());
}
#if defined(PROJECT_ENABLE_JSON)
TEST(utils_file, read_and_write_json_file) {
auto path = test::generate_test_file_name("utils_file");