mirror of
https://github.com/falk-werner/webfuse
synced 2025-06-13 12:54:15 +00:00
added matcher of readdir results
This commit is contained in:
parent
b9ea7245c3
commit
e2ff66b4c1
@ -35,18 +35,21 @@ MATCHER_P3(GetAttrMatcher, 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)))
|
||||||
{
|
{
|
||||||
|
*result_listener << "missing inode";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
json_t * mode_holder = json_object_get(arg, "mode");
|
json_t * mode_holder = json_object_get(arg, "mode");
|
||||||
if ((!json_is_integer(mode_holder)) || (mode != json_integer_value(mode_holder)))
|
if ((!json_is_integer(mode_holder)) || (mode != json_integer_value(mode_holder)))
|
||||||
{
|
{
|
||||||
|
*result_listener << "missing mode";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
json_t * type_holder = json_object_get(arg, "type");
|
json_t * type_holder = json_object_get(arg, "type");
|
||||||
if ((!json_is_string(type_holder)) || (0 != strcmp(file_type, json_string_value(type_holder))))
|
if ((!json_is_string(type_holder)) || (0 != strcmp(file_type, json_string_value(type_holder))))
|
||||||
{
|
{
|
||||||
|
*result_listener << "missing type";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +57,65 @@ MATCHER_P3(GetAttrMatcher, inode, mode, file_type, "")
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MATCHER_P(ReaddirMatcher, contained_elements , "")
|
||||||
|
{
|
||||||
|
if (!json_is_array(arg))
|
||||||
|
{
|
||||||
|
*result_listener << "result is not array";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
json_t * value;
|
||||||
|
|
||||||
|
json_array_foreach(arg, i, value)
|
||||||
|
{
|
||||||
|
json_t * inode = json_object_get(value, "inode");
|
||||||
|
json_t * name = json_object_get(value, "name");
|
||||||
|
|
||||||
|
if(!json_is_integer(inode))
|
||||||
|
{
|
||||||
|
*result_listener << "invalid result: missing inode";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!json_is_string(name))
|
||||||
|
{
|
||||||
|
*result_listener << "invalid result: missing name";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(size_t i = 0; NULL != contained_elements[i]; i++)
|
||||||
|
{
|
||||||
|
char const * element = contained_elements[i];
|
||||||
|
bool found = false;
|
||||||
|
size_t j;
|
||||||
|
json_t * value;
|
||||||
|
|
||||||
|
json_array_foreach(arg, j, value)
|
||||||
|
{
|
||||||
|
json_t * name = json_object_get(value, "name");
|
||||||
|
|
||||||
|
found = (0 == strcmp(element, json_string_value(name)));
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
*result_listener << "missing required directory element: " << element;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,21 +9,35 @@
|
|||||||
using webfuse_test::request_create;
|
using webfuse_test::request_create;
|
||||||
using webfuse_test::MockRequest;
|
using webfuse_test::MockRequest;
|
||||||
using webfuse_test::GetAttrMatcher;
|
using webfuse_test::GetAttrMatcher;
|
||||||
|
using webfuse_test::ReaddirMatcher;
|
||||||
using testing::_;
|
using testing::_;
|
||||||
|
|
||||||
TEST(wfp_static_filesystem, init)
|
TEST(wfp_static_filesystem, has_root_dir)
|
||||||
{
|
{
|
||||||
struct wfp_client_config * config = wfp_client_config_create();
|
struct wfp_client_config * config = wfp_client_config_create();
|
||||||
struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config);
|
struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config);
|
||||||
|
|
||||||
MockRequest mock;
|
MockRequest mock;
|
||||||
struct wfp_request * request = request_create(&mock, 42);
|
struct wfp_request * request = request_create(&mock, 42);
|
||||||
|
|
||||||
EXPECT_CALL(mock, respond(GetAttrMatcher(1, 0555, "dir"), 42)).Times(1);
|
EXPECT_CALL(mock, respond(GetAttrMatcher(1, 0555, "dir"), 42)).Times(1);
|
||||||
|
|
||||||
config->provider.getattr(request, 1, config->user_data);
|
config->provider.getattr(request, 1, config->user_data);
|
||||||
|
|
||||||
|
wfp_impl_static_filesystem_dispose(filesystem);
|
||||||
|
wfp_client_config_dispose(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(wfp_static_filesystem, contains_default_dirs)
|
||||||
|
{
|
||||||
|
struct wfp_client_config * config = wfp_client_config_create();
|
||||||
|
struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config);
|
||||||
|
|
||||||
|
MockRequest mock;
|
||||||
|
struct wfp_request * request = request_create(&mock, 23);
|
||||||
|
char const * default_dirs[] = {".", "..a", nullptr};
|
||||||
|
EXPECT_CALL(mock, respond(ReaddirMatcher(default_dirs), 23)).Times(1);
|
||||||
|
|
||||||
|
config->provider.readdir(request, 1, config->user_data);
|
||||||
|
|
||||||
wfp_impl_static_filesystem_dispose(filesystem);
|
wfp_impl_static_filesystem_dispose(filesystem);
|
||||||
wfp_client_config_dispose(config);
|
wfp_client_config_dispose(config);
|
||||||
|
Loading…
Reference in New Issue
Block a user