mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
added test for wfp_impl_lookup
This commit is contained in:
parent
e9f371c14a
commit
2c62e16c98
@ -49,6 +49,7 @@ add_executable(alltests
|
|||||||
test/webfuse/tests/provider/test_client_protocol.cc
|
test/webfuse/tests/provider/test_client_protocol.cc
|
||||||
test/webfuse/tests/provider/operation/test_close.cc
|
test/webfuse/tests/provider/operation/test_close.cc
|
||||||
test/webfuse/tests/provider/operation/test_getattr.cc
|
test/webfuse/tests/provider/operation/test_getattr.cc
|
||||||
|
test/webfuse/tests/provider/operation/test_lookup.cc
|
||||||
test/webfuse/tests/integration/test_integration.cc
|
test/webfuse/tests/integration/test_integration.cc
|
||||||
test/webfuse/tests/integration/server.cc
|
test/webfuse/tests/integration/server.cc
|
||||||
test/webfuse/tests/integration/provider.cc
|
test/webfuse/tests/integration/provider.cc
|
||||||
|
@ -18,7 +18,7 @@ public:
|
|||||||
MOCK_METHOD2(respond_error, void(json_t * error, int id));
|
MOCK_METHOD2(respond_error, void(json_t * error, int id));
|
||||||
};
|
};
|
||||||
|
|
||||||
MATCHER_P3(GetAttrMatcher, inode, mode, file_type, "")
|
MATCHER_P3(StatMatcher, inode, mode, file_type, "")
|
||||||
{
|
{
|
||||||
json_t * inode_holder = json_object_get(arg, "inode");
|
json_t * inode_holder = json_object_get(arg, "inode");
|
||||||
if ((!json_is_integer(inode_holder)) || (inode != json_integer_value(inode_holder)))
|
if ((!json_is_integer(inode_holder)) || (inode != json_integer_value(inode_holder)))
|
||||||
@ -44,7 +44,6 @@ MATCHER_P3(GetAttrMatcher, inode, mode, file_type, "")
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MATCHER_P(ReaddirMatcher, contained_elements , "")
|
MATCHER_P(ReaddirMatcher, contained_elements , "")
|
||||||
{
|
{
|
||||||
if (!json_is_array(arg))
|
if (!json_is_array(arg))
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
using ::webfuse_test::MockProvider;
|
using ::webfuse_test::MockProvider;
|
||||||
using ::webfuse_test::MockRequest;
|
using ::webfuse_test::MockRequest;
|
||||||
using ::webfuse_test::GetAttrMatcher;
|
using ::webfuse_test::StatMatcher;
|
||||||
using ::webfuse_test::create_context;
|
using ::webfuse_test::create_context;
|
||||||
using ::testing::_;
|
using ::testing::_;
|
||||||
using ::testing::Invoke;
|
using ::testing::Invoke;
|
||||||
@ -36,7 +36,7 @@ TEST(wfp_impl_getattr, respond_file)
|
|||||||
{
|
{
|
||||||
MockRequest request;
|
MockRequest request;
|
||||||
auto * req = request.create_request(42);
|
auto * req = request.create_request(42);
|
||||||
EXPECT_CALL(request, respond(GetAttrMatcher(23, 0754, "file"), 42)).Times(1);
|
EXPECT_CALL(request, respond(StatMatcher(23, 0754, "file"), 42)).Times(1);
|
||||||
|
|
||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
memset(&buffer, 0, sizeof(buffer));
|
memset(&buffer, 0, sizeof(buffer));
|
||||||
@ -49,7 +49,7 @@ TEST(wfp_impl_getattr, respond_dir)
|
|||||||
{
|
{
|
||||||
MockRequest request;
|
MockRequest request;
|
||||||
auto * req = request.create_request(42);
|
auto * req = request.create_request(42);
|
||||||
EXPECT_CALL(request, respond(GetAttrMatcher(23, 0754, "dir"), 42)).Times(1);
|
EXPECT_CALL(request, respond(StatMatcher(23, 0754, "dir"), 42)).Times(1);
|
||||||
|
|
||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
memset(&buffer, 0, sizeof(buffer));
|
memset(&buffer, 0, sizeof(buffer));
|
||||||
|
129
test/webfuse/tests/provider/operation/test_lookup.cc
Normal file
129
test/webfuse/tests/provider/operation/test_lookup.cc
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
#include "webfuse/provider/impl/operation/lookup.h"
|
||||||
|
#include "webfuse/mocks/mock_request.hpp"
|
||||||
|
#include "webfuse/mocks/mock_provider.hpp"
|
||||||
|
#include "webfuse/mocks/fake_invokation_context.hpp"
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
using ::webfuse_test::MockProvider;
|
||||||
|
using ::webfuse_test::MockRequest;
|
||||||
|
using ::webfuse_test::StatMatcher;
|
||||||
|
using ::webfuse_test::create_context;
|
||||||
|
using ::testing::_;
|
||||||
|
using ::testing::Invoke;
|
||||||
|
using ::testing::StrEq;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
void free_request(wfp_request * request, ino_t, char const *)
|
||||||
|
{
|
||||||
|
free(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(wfp_impl_lookup, invoke_provider)
|
||||||
|
{
|
||||||
|
ino_t inode = 42;
|
||||||
|
MockProvider provider;
|
||||||
|
EXPECT_CALL(provider,lookup(_, inode,StrEq("some.file"))).Times(1)
|
||||||
|
.WillOnce(Invoke(free_request));
|
||||||
|
|
||||||
|
wfp_request request = {nullptr, nullptr, 0};
|
||||||
|
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||||
|
|
||||||
|
json_t * params = json_array();
|
||||||
|
json_array_append_new(params, json_string("test.filesystem"));
|
||||||
|
json_array_append_new(params, json_integer(inode));
|
||||||
|
json_array_append_new(params, json_string("some.file"));
|
||||||
|
|
||||||
|
wfp_impl_lookup(&context, params, 42);
|
||||||
|
json_decref(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(wfp_impl_lookup, fail_invalid_param_count)
|
||||||
|
{
|
||||||
|
MockProvider provider;
|
||||||
|
EXPECT_CALL(provider,lookup(_, _,_)).Times(0);
|
||||||
|
|
||||||
|
wfp_request request = {nullptr, nullptr, 0};
|
||||||
|
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||||
|
|
||||||
|
json_t * params = json_array();
|
||||||
|
json_array_append_new(params, json_string("test.filesystem"));
|
||||||
|
json_array_append_new(params, json_integer(23));
|
||||||
|
|
||||||
|
wfp_impl_lookup(&context, params, 42);
|
||||||
|
json_decref(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(wfp_impl_lookup, fail_invalid_inode_type)
|
||||||
|
{
|
||||||
|
MockProvider provider;
|
||||||
|
EXPECT_CALL(provider,lookup(_, _,_)).Times(0);
|
||||||
|
|
||||||
|
wfp_request request = {nullptr, nullptr, 0};
|
||||||
|
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||||
|
|
||||||
|
json_t * params = json_array();
|
||||||
|
json_array_append_new(params, json_string("test.filesystem"));
|
||||||
|
json_array_append_new(params, json_string("23"));
|
||||||
|
json_array_append_new(params, json_string("some.file"));
|
||||||
|
|
||||||
|
wfp_impl_lookup(&context, params, 42);
|
||||||
|
json_decref(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(wfp_impl_lookup, fail_invalid_name_type)
|
||||||
|
{
|
||||||
|
MockProvider provider;
|
||||||
|
EXPECT_CALL(provider,lookup(_, _,_)).Times(0);
|
||||||
|
|
||||||
|
wfp_request request = {nullptr, nullptr, 0};
|
||||||
|
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||||
|
|
||||||
|
json_t * params = json_array();
|
||||||
|
json_array_append_new(params, json_string("test.filesystem"));
|
||||||
|
json_array_append_new(params, json_string("23"));
|
||||||
|
json_array_append_new(params, json_integer(1));
|
||||||
|
|
||||||
|
wfp_impl_lookup(&context, params, 42);
|
||||||
|
json_decref(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(wfp_impl_lookup, default_responds_error)
|
||||||
|
{
|
||||||
|
MockRequest request;
|
||||||
|
auto * req = request.create_request(42);
|
||||||
|
EXPECT_CALL(request, respond_error(_,42)).Times(1);
|
||||||
|
|
||||||
|
wfp_impl_lookup_default(req, 1, "some.file", nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(wfp_impl_lookup, respond_file)
|
||||||
|
{
|
||||||
|
MockRequest request;
|
||||||
|
auto * req = request.create_request(42);
|
||||||
|
EXPECT_CALL(request, respond(StatMatcher(23, 0754, "file"), 42)).Times(1);
|
||||||
|
|
||||||
|
struct stat buffer;
|
||||||
|
memset(&buffer, 0, sizeof(buffer));
|
||||||
|
buffer.st_ino = 23;
|
||||||
|
buffer.st_mode = S_IFREG | 0754;
|
||||||
|
wfp_impl_respond_lookup(req, &buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(wfp_impl_lookup, respond_dir)
|
||||||
|
{
|
||||||
|
MockRequest request;
|
||||||
|
auto * req = request.create_request(42);
|
||||||
|
EXPECT_CALL(request, respond(StatMatcher(23, 0754, "dir"), 42)).Times(1);
|
||||||
|
|
||||||
|
struct stat buffer;
|
||||||
|
memset(&buffer, 0, sizeof(buffer));
|
||||||
|
buffer.st_ino = 23;
|
||||||
|
buffer.st_mode = S_IFDIR | 0754;
|
||||||
|
wfp_impl_respond_lookup(req, &buffer);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user