From 777466bc7c2ae8d4aa96c382f9950ac3ac4a189e Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Wed, 4 Jan 2023 19:33:01 +0100 Subject: [PATCH] add test for mkdir --- CMakeLists.txt | 1 + src/webfuse/provider.cpp | 12 +++++++ test-src/integration/test_mkdir.cpp | 51 +++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 test-src/integration/test_mkdir.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index bbdfa06..daef840 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,7 @@ if(NOT(WITHOUT_TEST)) test-src/integration/test_unlink.cpp test-src/integration/test_read.cpp test-src/integration/test_write.cpp + test-src/integration/test_mkdir.cpp ) target_include_directories(integration_tests PRIVATE test-src/integration ${GTEST_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS}) diff --git a/src/webfuse/provider.cpp b/src/webfuse/provider.cpp index 01a56e2..66ad206 100644 --- a/src/webfuse/provider.cpp +++ b/src/webfuse/provider.cpp @@ -109,6 +109,9 @@ public: case request_type::write: fs_write(reader, writer); break; + case request_type::mkdir: + fs_mkdir(reader, writer); + break; case request_type::readdir: fs_readdir(reader, writer); break; @@ -317,6 +320,15 @@ private: writer.write_i32(result); } + void fs_mkdir(messagereader & reader, messagewriter & writer) + { + auto const path = reader.read_str(); + auto const mode = reader.read_mode(); + + auto const result = fs_.mkdir(path, mode); + writer.write_i32(result); + } + void fs_readdir(messagereader & reader, messagewriter & writer) { auto const path = reader.read_str(); diff --git a/test-src/integration/test_mkdir.cpp b/test-src/integration/test_mkdir.cpp new file mode 100644 index 0000000..7cce68a --- /dev/null +++ b/test-src/integration/test_mkdir.cpp @@ -0,0 +1,51 @@ +#include "webfuse/webfuse.hpp" +#include "webfuse/test/fixture.hpp" +#include "webfuse/test/filesystem_mock.hpp" + +#include +#include +#include + + +using testing::_; +using testing::Return; +using testing::Invoke; +using testing::AnyNumber; +using testing::AtMost; + +TEST(mkdir, success) +{ + bool created = false; + + webfuse::filesystem_mock fs; + EXPECT_CALL(fs, access("/",_)).Times(AnyNumber()).WillRepeatedly(Return(0)); + EXPECT_CALL(fs, getattr(_,_)).WillRepeatedly(Invoke([&created](std::string const & path, struct stat * attr){ + memset(reinterpret_cast(attr),0, sizeof(struct stat)); + + if (path == "/") + { + attr->st_nlink = 1; + attr->st_mode = S_IFDIR | 0755; + return 0; + } + if ((path == "/some_dir") && (created)) + { + attr->st_nlink = 1; + attr->st_mode = S_IFDIR | 0644; + return 0; + } + else + { + return -ENOENT; + } + })); + EXPECT_CALL(fs, mkdir("/some_dir", _)).WillOnce(Invoke([&created](auto const &, auto) { + created = true; + return 0; + })); + + webfuse::fixture fixture(fs); + auto const path = fixture.get_path() + "/some_dir"; + + ASSERT_EQ(0, ::mkdir(path.c_str(), 0644)); +}