2019-05-19 12:33:42 +00:00
|
|
|
#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"
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
#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>
|
2020-06-28 17:43:08 +00:00
|
|
|
#include "webfuse/impl/lws_log.h"
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
using webfuse_test::Server;
|
|
|
|
using webfuse_test::Provider;
|
2020-04-05 18:11:07 +00:00
|
|
|
using webfuse_test::File;
|
2019-05-19 12:33:42 +00:00
|
|
|
|
|
|
|
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();
|
2020-06-12 11:32:31 +00:00
|
|
|
provider = new Provider(server->GetUrl().c_str());
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
2019-05-19 12:33:42 +00:00
|
|
|
|
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));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IntegrationTest, ReadTextFile)
|
|
|
|
{
|
2020-03-21 08:11:18 +00:00
|
|
|
std::string file_name = std::string(GetBaseDir()) + "/cprovider/hello.txt";
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-04-05 18:11:07 +00:00
|
|
|
File file(file_name);
|
|
|
|
ASSERT_TRUE(file.hasContents("Hello, World"));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IntegrationTest, ReadDir)
|
|
|
|
{
|
2020-03-21 08:11:18 +00:00
|
|
|
std::string dir_name = std::string(GetBaseDir()) + "/cprovider";
|
2019-05-19 12:33:42 +00:00
|
|
|
|
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"));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|