mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
add test for write
This commit is contained in:
parent
861671741f
commit
534ae9efa8
@ -86,6 +86,7 @@ if(NOT(WITHOUT_TEST))
|
||||
test-src/integration/test_mknod.cpp
|
||||
test-src/integration/test_unlink.cpp
|
||||
test-src/integration/test_read.cpp
|
||||
test-src/integration/test_write.cpp
|
||||
)
|
||||
|
||||
target_include_directories(integration_tests PRIVATE test-src/integration ${GTEST_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS})
|
||||
|
@ -106,6 +106,9 @@ public:
|
||||
case request_type::read:
|
||||
fs_read(reader, writer);
|
||||
break;
|
||||
case request_type::write:
|
||||
fs_write(reader, writer);
|
||||
break;
|
||||
case request_type::readdir:
|
||||
fs_readdir(reader, writer);
|
||||
break;
|
||||
@ -303,6 +306,17 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void fs_write(messagereader & reader, messagewriter & writer)
|
||||
{
|
||||
auto const path = reader.read_str();
|
||||
auto const buffer = reader.read_bytes();
|
||||
auto const offset = reader.read_u64();
|
||||
auto const handle = reader.read_u64();
|
||||
|
||||
auto const result = fs_.write(path, buffer.c_str(), buffer.size(), offset, handle);
|
||||
writer.write_i32(result);
|
||||
}
|
||||
|
||||
void fs_readdir(messagereader & reader, messagewriter & writer)
|
||||
{
|
||||
auto const path = reader.read_str();
|
||||
|
53
test-src/integration/test_write.cpp
Normal file
53
test-src/integration/test_write.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include "webfuse/webfuse.hpp"
|
||||
#include "webfuse/test/fixture.hpp"
|
||||
#include "webfuse/test/filesystem_mock.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using testing::_;
|
||||
using testing::Return;
|
||||
using testing::Invoke;
|
||||
using testing::AnyNumber;
|
||||
using testing::AtMost;
|
||||
|
||||
TEST(write, success)
|
||||
{
|
||||
webfuse::filesystem_mock fs;
|
||||
EXPECT_CALL(fs, access("/",_)).Times(AnyNumber()).WillRepeatedly(Return(0));
|
||||
EXPECT_CALL(fs, getattr(_,_)).WillRepeatedly(Invoke([](std::string const & path, struct stat * attr){
|
||||
memset(reinterpret_cast<void*>(attr),0, sizeof(struct stat));
|
||||
|
||||
if (path == "/")
|
||||
{
|
||||
attr->st_nlink = 1;
|
||||
attr->st_mode = S_IFDIR | 0755;
|
||||
return 0;
|
||||
}
|
||||
if (path == "/some_file")
|
||||
{
|
||||
attr->st_nlink = 1;
|
||||
attr->st_mode = S_IFREG | 0644;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
}));
|
||||
EXPECT_CALL(fs, open("/some_file", _, _)).WillOnce(Return(0));
|
||||
EXPECT_CALL(fs, write("/some_file", _, _, _, _)).Times(AnyNumber()).WillRepeatedly(Invoke([](auto const &, char const * buffer, size_t buffer_size, uint64_t offset, auto){
|
||||
return buffer_size;
|
||||
}));
|
||||
EXPECT_CALL(fs, release("/some_file", _)).Times(AtMost(1)).WillOnce(Return(0));
|
||||
|
||||
webfuse::fixture fixture(fs);
|
||||
auto const path = fixture.get_path() + "/some_file";
|
||||
|
||||
{
|
||||
std::ofstream out(path);
|
||||
out << "Test";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user