adds integration test (found some issues)

pull/34/head
Falk Werner 5 years ago
parent 54f31d4263
commit 0dc3d6ea02

@ -317,6 +317,9 @@ add_executable(alltests
test/adapter/jsonrpc/test_proxy.cc
test/provider/test_url.cc
test/provider/test_static_filesystem.cc
test/integration/test_integration.cc
test/integration/server.cc
test/integration/provider.cc
)
target_link_libraries(alltests PUBLIC webfuse-adapter-static webfuse-provider-static webfuse-core ${EXTRA_LIBS} ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES})

@ -0,0 +1,121 @@
#include "integration/provider.hpp"
#include "webfuse_provider.h"
#include <thread>
#include <mutex>
#include <string>
#include "msleep.hpp"
namespace webfuse_test
{
class Provider::Private
{
public:
Private(char const * url_)
: url(url_)
, is_running(false)
, is_shutdown_requested(false)
{
}
~Private()
{
Stop();
}
void Start()
{
std::lock_guard<std::mutex> lock(run_lock);
if (!is_running)
{
thread = std::thread(Run, this);
is_running = true;
msleep(200);
}
}
void Stop()
{
std::lock_guard<std::mutex> lock(run_lock);
if (is_running)
{
RequestShutdown();
thread.join();
is_running = false;
}
}
bool IsShutdownRequested()
{
std::lock_guard<std::mutex> lock(shutdown_lock);
return is_shutdown_requested;
}
char const * GetUrl() const
{
return url.c_str();
}
private:
void RequestShutdown()
{
std::lock_guard<std::mutex> lock(shutdown_lock);
is_shutdown_requested = true;
}
static void Run(Provider::Private * context)
{
wfp_client_config * config = wfp_client_config_create();
wfp_static_filesystem * fs = wfp_static_filesystem_create(config);
wfp_static_filesystem_add_text(fs, "hello.txt", 0x444, "Hello, World");
wfp_client * client = wfp_client_create(config);
if (nullptr != client)
{
wfp_client_connect(client, context->GetUrl());
while (!context->IsShutdownRequested())
{
wfp_client_service(client, 100);
}
wfp_client_dispose(client);
}
wfp_static_filesystem_dispose(fs);
wfp_client_config_dispose(config);
}
std::string url;
bool is_running;
std::mutex run_lock;
bool is_shutdown_requested;
std::mutex shutdown_lock;
std::thread thread;
};
Provider::Provider(char const * url)
: d(new Provider::Private(url))
{
}
Provider::~Provider()
{
delete d;
}
void Provider::Start(void)
{
d->Start();
}
void Provider::Stop(void)
{
d->Stop();
}
}

@ -0,0 +1,21 @@
#ifndef WF_TEST_INTEGRATION_PROVIDER
#define WF_TEST_INTEGRATION_PROVIDER
namespace webfuse_test
{
class Provider
{
public:
Provider(char const * url);
~Provider();
void Start(void);
void Stop(void);
private:
class Private;
Private * d;
};
}
#endif

@ -0,0 +1,132 @@
#include "integration/server.hpp"
#include <thread>
#include <mutex>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include "webfuse_adapter.h"
#include "msleep.hpp"
#define WF_PATH_MAX (100)
namespace webfuse_test
{
class Server::Private
{
public:
Private()
: is_running(false)
, is_shutdown_requested(false)
{
snprintf(base_dir, WF_PATH_MAX, "%s", "/tmp/webfuse_test_integration_XXXXXX");
mkdtemp(base_dir);
}
~Private()
{
Stop();
rmdir(base_dir);
}
void Start()
{
std::lock_guard<std::mutex> lock(run_lock);
if (!is_running)
{
thread = std::thread(Run, this);
is_running = true;
msleep(200);
}
}
void Stop()
{
std::lock_guard<std::mutex> lock(run_lock);
if (is_running)
{
RequestShutdown();
thread.join();
is_running = false;
}
}
bool IsShutdownRequested()
{
std::lock_guard<std::mutex> lock(shutdown_lock);
return is_shutdown_requested;
}
char const * GetBaseDir()
{
return base_dir;
}
private:
void RequestShutdown()
{
std::lock_guard<std::mutex> lock(shutdown_lock);
is_shutdown_requested = true;
}
static void Run(Server::Private * context)
{
wf_server_config * config = wf_server_config_create();
wf_server_config_set_port(config, 8080);
wf_server_config_set_mountpoint(config, context->GetBaseDir());
wf_server * server = wf_server_create(config);
if (nullptr != server)
{
while (!context->IsShutdownRequested())
{
wf_server_service(server, 100);
}
wf_server_dispose(server);
}
wf_server_config_dispose(config);
}
char base_dir[WF_PATH_MAX];
bool is_running;
std::mutex run_lock;
bool is_shutdown_requested;
std::mutex shutdown_lock;
std::thread thread;
};
Server::Server()
: d(new Server::Private())
{
}
Server::~Server()
{
delete d;
}
void Server::Start(void)
{
d->Start();
}
void Server::Stop(void)
{
d->Stop();
}
char const * Server::GetBaseDir(void) const
{
return d->GetBaseDir();
}
}

@ -0,0 +1,22 @@
#ifndef WF_TEST_INTEGRATION_SERVER_HPP
#define WF_TEST_INTEGRATION_SERVER_HPP
namespace webfuse_test
{
class Server
{
public:
Server();
~Server();
void Start(void);
void Stop(void);
char const * GetBaseDir(void) const;
private:
class Private;
Private * d;
};
}
#endif

@ -0,0 +1,67 @@
#include <gtest/gtest.h>
#include "integration/server.hpp"
#include "integration/provider.hpp"
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
using webfuse_test::Server;
using webfuse_test::Provider;
namespace
{
class IntegrationTest: public ::testing::Test
{
public:
IntegrationTest()
: provider("ws://localhost:8080/")
{
}
protected:
void SetUp()
{
server.Start();
provider.Start();
}
void TearDown()
{
provider.Stop();
server.Stop();
}
char const * GetBaseDir() const
{
return server.GetBaseDir();
}
private:
Server server;
Provider provider;
};
}
TEST_F(IntegrationTest, HasMountpoint)
{
struct stat buffer;
int rc = stat(GetBaseDir(), &buffer);
ASSERT_EQ(0, rc);
ASSERT_TRUE(S_ISDIR(buffer.st_mode));
}
TEST_F(IntegrationTest, DISABLED_ProvidesTextFile)
{
std::string file_name = std::string(GetBaseDir()) + "/cprovider/default/hello.txt";
struct stat buffer;
int rc = stat(file_name.c_str(), &buffer);
ASSERT_EQ(0, rc);
// ASSERT_TRUE(S_ISREG(buffer.st_mode));
// ASSERT_EQ(0444, (buffer.st_mode & 0777));
// ASSERT_EQ(12, buffer.st_size);
}
Loading…
Cancel
Save