2020-06-09 20:41:38 +00:00
|
|
|
#include <gtest/gtest.h>
|
2020-06-12 17:00:28 +00:00
|
|
|
#include <gmock/gmock.h>
|
2020-06-09 20:41:38 +00:00
|
|
|
|
2020-06-13 16:24:45 +00:00
|
|
|
#include "webfuse/utils/adapter_client.hpp"
|
2020-06-14 17:35:50 +00:00
|
|
|
#include "webfuse/adapter/client_tlsconfig.h"
|
2020-06-12 18:38:20 +00:00
|
|
|
#include "webfuse/adapter/credentials.h"
|
2020-06-12 14:48:15 +00:00
|
|
|
#include "webfuse/core/protocol_names.h"
|
2020-06-13 12:59:58 +00:00
|
|
|
#include "webfuse/utils/ws_server2.hpp"
|
2020-06-12 17:00:28 +00:00
|
|
|
#include "webfuse/mocks/mock_adapter_client_callback.hpp"
|
2020-06-13 12:59:58 +00:00
|
|
|
#include "webfuse/mocks/mock_invokation_handler.hpp"
|
2020-06-12 17:05:10 +00:00
|
|
|
#include "webfuse/utils/timeout_watcher.hpp"
|
2020-06-14 08:39:33 +00:00
|
|
|
#include "webfuse/tests/integration/file.hpp"
|
|
|
|
#include "webfuse/mocks/lookup_matcher.hpp"
|
2020-06-11 20:57:56 +00:00
|
|
|
|
2020-06-13 16:24:45 +00:00
|
|
|
using webfuse_test::AdapterClient;
|
2020-06-13 12:59:58 +00:00
|
|
|
using webfuse_test::WsServer2;
|
|
|
|
using webfuse_test::MockInvokationHander;
|
2020-06-12 17:00:28 +00:00
|
|
|
using webfuse_test::MockAdapterClientCallback;
|
2020-06-12 17:05:10 +00:00
|
|
|
using webfuse_test::TimeoutWatcher;
|
2020-06-14 08:39:33 +00:00
|
|
|
using webfuse_test::File;
|
|
|
|
using webfuse_test::Lookup;
|
2020-06-12 17:00:28 +00:00
|
|
|
using testing::_;
|
2020-06-12 18:38:20 +00:00
|
|
|
using testing::Invoke;
|
2020-06-13 09:36:02 +00:00
|
|
|
using testing::AnyNumber;
|
2020-06-13 12:59:58 +00:00
|
|
|
using testing::Return;
|
|
|
|
using testing::Throw;
|
|
|
|
using testing::StrEq;
|
2020-06-09 20:41:38 +00:00
|
|
|
|
2020-06-13 12:59:58 +00:00
|
|
|
#define TIMEOUT (std::chrono::milliseconds(30 * 1000))
|
2020-06-12 17:05:10 +00:00
|
|
|
|
2020-06-09 20:41:38 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2020-06-12 18:38:20 +00:00
|
|
|
void GetCredentials(wf_client *, int, void * arg)
|
|
|
|
{
|
|
|
|
auto * creds = reinterpret_cast<wf_credentials*>(arg);
|
|
|
|
wf_credentials_set_type(creds, "username");
|
|
|
|
wf_credentials_add(creds, "username", "Bob");
|
|
|
|
wf_credentials_add(creds, "password", "secret");
|
|
|
|
}
|
|
|
|
|
2020-06-11 20:57:56 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 17:00:28 +00:00
|
|
|
TEST(AdapterClient, CreateAndDispose)
|
|
|
|
{
|
|
|
|
MockAdapterClientCallback callback;
|
|
|
|
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_INIT, nullptr)).Times(1);
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CREATED, nullptr)).Times(1);
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_GET_TLS_CONFIG, _)).Times(1);
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CLEANUP, nullptr)).Times(1);
|
|
|
|
|
|
|
|
wf_client * client = wf_client_create(
|
|
|
|
callback.GetCallbackFn(), callback.GetUserData());
|
|
|
|
|
|
|
|
wf_client_dispose(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(AdapterClient, Connect)
|
2020-06-11 20:57:56 +00:00
|
|
|
{
|
2020-06-12 17:05:10 +00:00
|
|
|
TimeoutWatcher watcher(TIMEOUT);
|
|
|
|
|
2020-06-13 12:59:58 +00:00
|
|
|
MockInvokationHander handler;
|
|
|
|
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
|
|
|
EXPECT_CALL(handler, Invoke(_,_)).Times(0);
|
2020-06-12 17:00:28 +00:00
|
|
|
|
2020-06-13 12:59:58 +00:00
|
|
|
MockAdapterClientCallback callback;
|
2020-06-12 17:00:28 +00:00
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_INIT, nullptr)).Times(1);
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CREATED, nullptr)).Times(1);
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_GET_TLS_CONFIG, _)).Times(1);
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CLEANUP, nullptr)).Times(1);
|
|
|
|
|
2020-06-13 21:47:52 +00:00
|
|
|
bool connected = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
|
|
|
|
|
|
|
bool disconnected = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
2020-06-11 20:57:56 +00:00
|
|
|
|
2020-06-13 16:24:45 +00:00
|
|
|
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
2020-06-11 20:57:56 +00:00
|
|
|
|
2020-06-13 16:24:45 +00:00
|
|
|
client.Connect();
|
2020-06-13 21:47:52 +00:00
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
2020-06-09 20:41:38 +00:00
|
|
|
|
2020-06-13 16:24:45 +00:00
|
|
|
client.Disconnect();
|
2020-06-13 21:47:52 +00:00
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
2020-06-12 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 17:35:50 +00:00
|
|
|
TEST(AdapterClient, ConnectWithTls)
|
|
|
|
{
|
|
|
|
TimeoutWatcher watcher(TIMEOUT);
|
|
|
|
|
|
|
|
MockInvokationHander handler;
|
|
|
|
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER, 0, true);
|
|
|
|
EXPECT_CALL(handler, Invoke(_,_)).Times(0);
|
|
|
|
|
|
|
|
MockAdapterClientCallback callback;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_INIT, nullptr)).Times(1);
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CREATED, nullptr)).Times(1);
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_GET_TLS_CONFIG, _)).Times(1)
|
|
|
|
.WillOnce(Invoke([](wf_client *, int, void * arg) {
|
|
|
|
auto * tls = reinterpret_cast<wf_client_tlsconfig*>(arg);
|
|
|
|
wf_client_tlsconfig_set_keypath (tls, "client-key.pem");
|
|
|
|
wf_client_tlsconfig_set_certpath(tls, "client-cert.pem");
|
|
|
|
wf_client_tlsconfig_set_cafilepath(tls, "server-cert.pem");
|
|
|
|
}));
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CLEANUP, nullptr)).Times(1);
|
|
|
|
|
|
|
|
bool connected = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
|
|
|
|
|
|
|
bool disconnected = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
|
|
|
|
|
|
|
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
|
|
|
|
|
|
|
client.Connect();
|
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
|
|
|
|
|
|
|
client.Disconnect();
|
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
|
|
|
}
|
|
|
|
|
2020-06-14 18:20:14 +00:00
|
|
|
TEST(AdapterClient, FailedToConnectInvalidPort)
|
|
|
|
{
|
|
|
|
TimeoutWatcher watcher(TIMEOUT);
|
|
|
|
|
|
|
|
|
|
|
|
MockAdapterClientCallback callback;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_INIT, nullptr)).Times(1);
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CREATED, nullptr)).Times(1);
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_GET_TLS_CONFIG, _)).Times(1);
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CLEANUP, nullptr)).Times(1);
|
|
|
|
|
|
|
|
bool disconnected = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
|
|
|
|
|
|
|
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), "ws://localhost:4/");
|
|
|
|
|
|
|
|
client.Connect();
|
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
|
|
|
}
|
|
|
|
|
2020-06-14 17:35:50 +00:00
|
|
|
|
2020-06-12 18:38:20 +00:00
|
|
|
TEST(AdapterClient, Authenticate)
|
|
|
|
{
|
|
|
|
TimeoutWatcher watcher(TIMEOUT);
|
|
|
|
|
2020-06-13 12:59:58 +00:00
|
|
|
MockInvokationHander handler;
|
|
|
|
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
|
|
|
EXPECT_CALL(handler, Invoke(StrEq("authenticate"),_)).Times(1)
|
|
|
|
.WillOnce(Return("{}"));
|
2020-06-12 18:38:20 +00:00
|
|
|
|
2020-06-13 12:59:58 +00:00
|
|
|
MockAdapterClientCallback callback;
|
2020-06-13 09:36:02 +00:00
|
|
|
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
2020-06-13 21:47:52 +00:00
|
|
|
|
|
|
|
bool connected = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
|
|
|
|
|
|
|
bool disconnected = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
|
|
|
|
2020-06-12 18:38:20 +00:00
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATE_GET_CREDENTIALS, _)).Times(1)
|
|
|
|
.WillOnce(Invoke(GetCredentials));
|
2020-06-13 21:47:52 +00:00
|
|
|
|
|
|
|
bool authenticated = false;
|
2020-06-12 18:38:20 +00:00
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATED, nullptr)).Times(1)
|
2020-06-13 21:47:52 +00:00
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { authenticated = true; }));
|
2020-06-12 18:38:20 +00:00
|
|
|
|
2020-06-13 16:24:45 +00:00
|
|
|
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
2020-06-13 12:59:58 +00:00
|
|
|
|
2020-06-13 16:24:45 +00:00
|
|
|
client.Connect();
|
2020-06-13 21:47:52 +00:00
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
2020-06-12 18:38:20 +00:00
|
|
|
|
2020-06-13 16:24:45 +00:00
|
|
|
client.Authenticate();
|
2020-06-13 21:47:52 +00:00
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return authenticated; }));
|
2020-06-13 12:59:58 +00:00
|
|
|
|
2020-06-13 16:24:45 +00:00
|
|
|
client.Disconnect();
|
2020-06-13 21:47:52 +00:00
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
2020-06-13 12:59:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-13 15:08:05 +00:00
|
|
|
TEST(AdapterClient, AuthenticateFailedWithoutConnect)
|
|
|
|
{
|
|
|
|
TimeoutWatcher watcher(TIMEOUT);
|
|
|
|
|
|
|
|
MockAdapterClientCallback callback;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATE_GET_CREDENTIALS, _)).Times(1)
|
|
|
|
.WillOnce(Invoke(GetCredentials));
|
|
|
|
bool called = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATION_FAILED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&called] (wf_client *, int, void *) mutable {
|
|
|
|
called = true;
|
|
|
|
}));
|
|
|
|
|
2020-06-13 16:24:45 +00:00
|
|
|
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), "");
|
2020-06-13 15:08:05 +00:00
|
|
|
|
2020-06-13 16:24:45 +00:00
|
|
|
client.Authenticate();
|
2020-06-13 21:47:52 +00:00
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return called; }));
|
2020-06-13 15:08:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-13 12:59:58 +00:00
|
|
|
TEST(AdapterClient, AuthenticationFailed)
|
|
|
|
{
|
|
|
|
TimeoutWatcher watcher(TIMEOUT);
|
|
|
|
|
|
|
|
MockInvokationHander handler;
|
|
|
|
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
|
|
|
EXPECT_CALL(handler, Invoke(StrEq("authenticate"),_)).Times(1)
|
|
|
|
.WillOnce(Throw(std::runtime_error("authentication failed")));
|
|
|
|
|
|
|
|
MockAdapterClientCallback callback;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
2020-06-13 21:47:52 +00:00
|
|
|
|
|
|
|
bool connected = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
|
|
|
|
|
|
|
bool disconnected = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
|
|
|
|
2020-06-13 12:59:58 +00:00
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATE_GET_CREDENTIALS, _)).Times(1)
|
|
|
|
.WillOnce(Invoke(GetCredentials));
|
2020-06-13 21:47:52 +00:00
|
|
|
|
2020-06-13 12:59:58 +00:00
|
|
|
bool called = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATION_FAILED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&called] (wf_client *, int, void *) mutable {
|
|
|
|
called = true;
|
|
|
|
}));
|
|
|
|
|
2020-06-13 16:24:45 +00:00
|
|
|
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
2020-06-13 12:59:58 +00:00
|
|
|
|
2020-06-13 16:24:45 +00:00
|
|
|
client.Connect();
|
2020-06-13 21:47:52 +00:00
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
2020-06-13 12:59:58 +00:00
|
|
|
|
2020-06-13 16:24:45 +00:00
|
|
|
client.Authenticate();
|
2020-06-13 21:47:52 +00:00
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return called; }));
|
2020-06-12 18:38:20 +00:00
|
|
|
|
2020-06-13 16:24:45 +00:00
|
|
|
client.Disconnect();
|
2020-06-13 21:47:52 +00:00
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
2020-06-13 16:24:45 +00:00
|
|
|
}
|
2020-06-14 08:39:33 +00:00
|
|
|
|
|
|
|
TEST(AdapterClient, AddFileSystem)
|
|
|
|
{
|
|
|
|
TimeoutWatcher watcher(TIMEOUT);
|
|
|
|
|
|
|
|
MockInvokationHander handler;
|
|
|
|
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
|
|
|
EXPECT_CALL(handler, Invoke(StrEq("add_filesystem"),_)).Times(1)
|
|
|
|
.WillOnce(Return("{\"id\": \"test\"}"));
|
|
|
|
EXPECT_CALL(handler, Invoke(StrEq("lookup"), _)).Times(AnyNumber())
|
|
|
|
.WillRepeatedly(Throw(std::runtime_error("unknown")));
|
|
|
|
|
|
|
|
MockAdapterClientCallback callback;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
|
|
|
|
|
|
|
bool connected = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
|
|
|
|
|
|
|
bool disconnected = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
|
|
|
|
|
|
|
bool called = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_FILESYSTEM_ADDED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&called] (wf_client *, int, void *) mutable {
|
|
|
|
called = true;
|
|
|
|
}));
|
|
|
|
|
|
|
|
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
|
|
|
|
|
|
|
client.Connect();
|
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
|
|
|
|
|
|
|
client.AddFileSystem();
|
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return called; }));
|
|
|
|
|
|
|
|
client.Disconnect();
|
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(AdapterClient, AddFileSystemFailed)
|
|
|
|
{
|
|
|
|
TimeoutWatcher watcher(TIMEOUT);
|
|
|
|
|
|
|
|
MockInvokationHander handler;
|
|
|
|
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
|
|
|
EXPECT_CALL(handler, Invoke(StrEq("add_filesystem"),_)).Times(1)
|
|
|
|
.WillOnce(Throw(std::runtime_error("failed")));
|
|
|
|
|
|
|
|
MockAdapterClientCallback callback;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
|
|
|
|
|
|
|
bool connected = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
|
|
|
|
|
|
|
bool disconnected = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
|
|
|
|
|
|
|
bool called = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_FILESYSTEM_ADD_FAILED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&called] (wf_client *, int, void *) mutable {
|
|
|
|
called = true;
|
|
|
|
}));
|
|
|
|
|
|
|
|
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
|
|
|
|
|
|
|
client.Connect();
|
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
|
|
|
|
|
|
|
client.AddFileSystem();
|
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return called; }));
|
|
|
|
|
|
|
|
client.Disconnect();
|
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(AdapterClient, LookupFile)
|
|
|
|
{
|
|
|
|
TimeoutWatcher watcher(TIMEOUT);
|
|
|
|
|
|
|
|
MockInvokationHander handler;
|
|
|
|
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
|
|
|
EXPECT_CALL(handler, Invoke(StrEq("add_filesystem"),_)).Times(1)
|
|
|
|
.WillOnce(Return("{\"id\": \"test\"}"));
|
|
|
|
EXPECT_CALL(handler, Invoke(StrEq("lookup"), _)).Times(AnyNumber())
|
|
|
|
.WillRepeatedly(Throw(std::runtime_error("unknown")));
|
|
|
|
EXPECT_CALL(handler, Invoke(StrEq("lookup"), Lookup(1, "Hello.txt"))).Times(AnyNumber())
|
|
|
|
.WillRepeatedly(Return(
|
|
|
|
"{"
|
|
|
|
"\"inode\": 2,"
|
|
|
|
"\"mode\": 420," //0644
|
|
|
|
"\"type\": \"file\","
|
|
|
|
"\"size\": 42,"
|
|
|
|
"\"atime\": 0,"
|
|
|
|
"\"mtime\": 0,"
|
|
|
|
"\"ctime\": 0"
|
|
|
|
"}"
|
|
|
|
));
|
|
|
|
|
|
|
|
MockAdapterClientCallback callback;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
|
|
|
|
|
|
|
bool connected = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
|
|
|
|
|
|
|
bool disconnected = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
|
|
|
|
|
|
|
bool called = false;
|
|
|
|
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_FILESYSTEM_ADDED, nullptr)).Times(1)
|
|
|
|
.WillOnce(Invoke([&called] (wf_client *, int, void *) mutable {
|
|
|
|
called = true;
|
|
|
|
}));
|
|
|
|
|
|
|
|
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
|
|
|
|
|
|
|
client.Connect();
|
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
|
|
|
|
|
|
|
client.AddFileSystem();
|
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return called; }));
|
|
|
|
|
|
|
|
std::string file_name = client.GetDir() + "/Hello.txt";
|
|
|
|
File file(file_name);
|
|
|
|
ASSERT_TRUE(file.isFile());
|
|
|
|
|
|
|
|
client.Disconnect();
|
|
|
|
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
|
|
|
}
|