mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
added tests for wfp_impl_getattr
This commit is contained in:
parent
70e9f0a278
commit
e9f371c14a
@ -25,6 +25,7 @@ add_executable(alltests
|
||||
test/webfuse/utils/path.c
|
||||
test/webfuse/utils/static_filesystem.c
|
||||
test/webfuse/utils/ws_server.cc
|
||||
test/webfuse/mocks/fake_invokation_context.cc
|
||||
test/webfuse/mocks/mock_authenticator.cc
|
||||
test/webfuse/mocks/mock_request.cc
|
||||
test/webfuse/mocks/mock_provider_client.cc
|
||||
|
17
test/webfuse/mocks/fake_invokation_context.cc
Normal file
17
test/webfuse/mocks/fake_invokation_context.cc
Normal file
@ -0,0 +1,17 @@
|
||||
#include "webfuse/mocks/fake_invokation_context.hpp"
|
||||
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
wfp_impl_invokation_context create_context(MockProvider& provider, wfp_request * request)
|
||||
{
|
||||
wfp_impl_invokation_context context =
|
||||
{
|
||||
provider.get_provider(),
|
||||
provider.get_userdata(),
|
||||
request
|
||||
};
|
||||
return context;
|
||||
}
|
||||
|
||||
}
|
16
test/webfuse/mocks/fake_invokation_context.hpp
Normal file
16
test/webfuse/mocks/fake_invokation_context.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef FAKE_INVOCATION_CONTEXT_HPP
|
||||
#define FAKE_INVOCATION_CONTEXT_HPP
|
||||
|
||||
#include "webfuse/provider/impl/provider.h"
|
||||
#include "webfuse/mocks/mock_provider.hpp"
|
||||
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
wfp_impl_invokation_context create_context(
|
||||
MockProvider& provider,
|
||||
wfp_request * request = nullptr);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,25 +1,13 @@
|
||||
#include "webfuse/provider/impl/operation/close.h"
|
||||
#include "webfuse/mocks/mock_provider.hpp"
|
||||
#include "webfuse/mocks/fake_invokation_context.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using ::webfuse_test::MockProvider;
|
||||
using ::webfuse_test::create_context;
|
||||
using ::testing::_;
|
||||
|
||||
namespace
|
||||
{
|
||||
wfp_impl_invokation_context create_context(MockProvider& provider)
|
||||
{
|
||||
wfp_impl_invokation_context context =
|
||||
{
|
||||
provider.get_provider(),
|
||||
provider.get_userdata(),
|
||||
nullptr
|
||||
};
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(wfp_close, close)
|
||||
{
|
||||
int inode = 42;
|
||||
|
@ -1,10 +1,27 @@
|
||||
#include "webfuse/provider/impl/operation/getattr.h"
|
||||
#include "webfuse/mocks/mock_request.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
#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::GetAttrMatcher;
|
||||
using ::webfuse_test::create_context;
|
||||
using ::testing::_;
|
||||
using ::testing::Invoke;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void free_request(wfp_request * request, ino_t)
|
||||
{
|
||||
free(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(wfp_impl_getattr, default_responds_error)
|
||||
{
|
||||
@ -39,4 +56,52 @@ TEST(wfp_impl_getattr, respond_dir)
|
||||
buffer.st_ino = 23;
|
||||
buffer.st_mode = S_IFDIR | 0754;
|
||||
wfp_impl_respond_getattr(req, &buffer);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(wfp_impl_getattr, invoke_provider)
|
||||
{
|
||||
ino_t inode = 23;
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,getattr(_, inode)).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));
|
||||
|
||||
wfp_impl_getattr(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_getattr, fail_invalid_param_count)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,getattr(_, _)).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"));
|
||||
|
||||
wfp_impl_getattr(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_getattr, fail_invalid_inode_type)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,getattr(_, _)).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("42"));
|
||||
|
||||
wfp_impl_getattr(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user