mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
added test to show error
This commit is contained in:
parent
62e06032eb
commit
e1128fe3cd
@ -27,6 +27,7 @@ using testing::_;
|
||||
using testing::AnyNumber;
|
||||
using testing::AtMost;
|
||||
using testing::Return;
|
||||
using testing::Invoke;
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -315,6 +316,66 @@ TEST(server, read)
|
||||
ASSERT_TRUE(disconnected);
|
||||
}
|
||||
|
||||
TEST(server, read_large_file)
|
||||
{
|
||||
Server server;
|
||||
MockInvokationHander handler;
|
||||
EXPECT_CALL(handler, Invoke(StrEq("lookup"), _)).Times(AnyNumber());
|
||||
EXPECT_CALL(handler, Invoke(StrEq("lookup"), Lookup(1, "a.file"))).Times(1)
|
||||
.WillOnce(Return("{\"inode\": 2, \"mode\": 420, \"type\": \"file\", \"size\": 4096}"));
|
||||
EXPECT_CALL(handler, Invoke(StrEq("getattr"), GetAttr(1))).Times(AnyNumber())
|
||||
.WillOnce(Return("{\"mode\": 420, \"type\": \"dir\"}"));
|
||||
EXPECT_CALL(handler, Invoke(StrEq("open"), Open(2))).Times(1)
|
||||
.WillOnce(Return("{\"handle\": 42}"));
|
||||
EXPECT_CALL(handler, Invoke(StrEq("read"), _)).Times(AnyNumber())
|
||||
.WillRepeatedly(Invoke([](char const *, json_t * params) {
|
||||
int offset = json_integer_value(json_array_get(params, 3));
|
||||
int length = json_integer_value(json_array_get(params, 4));
|
||||
|
||||
std::cout << "offset: " << offset << std::endl;
|
||||
std::cout << "length: " << length << std::endl;
|
||||
|
||||
int remaining = (offset < 4096) ? 4096 - offset : 0;
|
||||
int count = (length < remaining) ? length : remaining;
|
||||
|
||||
std::string data = std::string(count, '*');
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "data", json_string(data.c_str()));
|
||||
json_object_set_new(result, "format", json_string("identity"));
|
||||
json_object_set_new(result, "count", json_integer(count));
|
||||
|
||||
char * result_text = json_dumps(result, 0);
|
||||
std::string result_str = result_text;
|
||||
free(result_text);
|
||||
|
||||
return result_str;
|
||||
}));
|
||||
EXPECT_CALL(handler, Invoke(StrEq("close"), _)).Times(AtMost(1));
|
||||
WsClient client(handler, WF_PROTOCOL_NAME_PROVIDER_CLIENT);
|
||||
|
||||
auto connected = client.Connect(server.GetPort(), WF_PROTOCOL_NAME_ADAPTER_SERVER);
|
||||
ASSERT_TRUE(connected);
|
||||
|
||||
std::string response_text = client.Invoke("{\"method\": \"add_filesystem\", \"params\": [\"test\"], \"id\": 42}");
|
||||
json_t * response = json_loads(response_text.c_str(), 0, nullptr);
|
||||
ASSERT_TRUE(json_is_object(response));
|
||||
json_t * result = json_object_get(response, "result");
|
||||
ASSERT_TRUE(json_is_object(result));
|
||||
json_t * id = json_object_get(response, "id");
|
||||
ASSERT_EQ(42, json_integer_value(id));
|
||||
json_decref(response);
|
||||
|
||||
std::string base_dir = server.GetBaseDir();
|
||||
ASSERT_TRUE(File(base_dir).isDirectory());
|
||||
File file(base_dir + "/test/a.file");
|
||||
ASSERT_TRUE(file.hasContents("*"));
|
||||
|
||||
auto disconnected = client.Disconnect();
|
||||
ASSERT_TRUE(disconnected);
|
||||
}
|
||||
|
||||
|
||||
TEST(server, readdir)
|
||||
{
|
||||
Server server;
|
||||
|
Loading…
Reference in New Issue
Block a user