1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00
falk-werner_webfuse-provider/test/webfuse/tests/integration/test_integration.cc

97 lines
2.2 KiB
C++
Raw Normal View History

#include <gtest/gtest.h>
2020-02-20 16:15:13 +00:00
#include "webfuse/tests/integration/server.hpp"
#include "webfuse/tests/integration/provider.hpp"
2020-04-05 18:11:07 +00:00
#include "webfuse/tests/integration/file.hpp"
#include <cstdio>
#include <csignal>
#include <cstring>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <jansson.h>
#include "webfuse/core/lws_log.h"
using webfuse_test::Server;
using webfuse_test::Provider;
2020-04-05 18:11:07 +00:00
using webfuse_test::File;
namespace
{
class IntegrationTest: public ::testing::Test
{
public:
IntegrationTest()
: server(nullptr)
, provider(nullptr)
{
json_object_seed(0);
wf_lwslog_disable();
}
protected:
void SetUp()
{
server = new Server();
provider = new Provider(server->GetUrl().c_str());
}
void TearDown()
{
delete provider;
delete server;
}
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, ProvidesTextFile)
{
2020-03-21 08:11:18 +00:00
std::string file_name = std::string(GetBaseDir()) + "/cprovider/hello.txt";
2020-04-05 18:11:07 +00:00
File file(file_name);
ASSERT_TRUE(file.isFile());
ASSERT_TRUE(file.hasAccessRights(0444));
ASSERT_TRUE(file.hasSize(12));
}
TEST_F(IntegrationTest, ReadTextFile)
{
2020-03-21 08:11:18 +00:00
std::string file_name = std::string(GetBaseDir()) + "/cprovider/hello.txt";
2020-04-05 18:11:07 +00:00
File file(file_name);
ASSERT_TRUE(file.hasContents("Hello, World"));
}
TEST_F(IntegrationTest, ReadDir)
{
2020-03-21 08:11:18 +00:00
std::string dir_name = std::string(GetBaseDir()) + "/cprovider";
2020-04-05 18:11:07 +00:00
File dir(dir_name);
ASSERT_TRUE(dir.isDirectory());
ASSERT_TRUE(dir.hasSubdirectory("."));
ASSERT_TRUE(dir.hasSubdirectory(".."));
ASSERT_TRUE(dir.hasSubdirectory("hello.txt"));
ASSERT_FALSE(dir.hasSubdirectory("other"));
}