mirror of
https://github.com/falk-werner/webfuse
synced 2025-06-13 12:54:15 +00:00
adds some integration tests
This commit is contained in:
parent
4da34f0e92
commit
c9eb703da1
@ -292,6 +292,7 @@ pkg_check_modules(GMOCK gmock)
|
|||||||
|
|
||||||
add_executable(alltests
|
add_executable(alltests
|
||||||
test/msleep.cc
|
test/msleep.cc
|
||||||
|
test/die_if.cc
|
||||||
test/mock_authenticator.cc
|
test/mock_authenticator.cc
|
||||||
test/mock_request.cc
|
test/mock_request.cc
|
||||||
test/core/test_container_of.cc
|
test/core/test_container_of.cc
|
||||||
|
15
test/die_if.cc
Normal file
15
test/die_if.cc
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "die_if.hpp"
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
void die_if(bool expression)
|
||||||
|
{
|
||||||
|
if (expression)
|
||||||
|
{
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
test/die_if.hpp
Normal file
11
test/die_if.hpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef WF_TEST_DIE_IF_HPP
|
||||||
|
#define WF_TEST_DIE_IF_HPP
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
extern void die_if(bool expression);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -18,7 +18,7 @@ public:
|
|||||||
config = wfp_client_config_create();
|
config = wfp_client_config_create();
|
||||||
|
|
||||||
fs = wfp_static_filesystem_create(config);
|
fs = wfp_static_filesystem_create(config);
|
||||||
wfp_static_filesystem_add_text(fs, "hello.txt", 0x444, "Hello, World");
|
wfp_static_filesystem_add_text(fs, "hello.txt", 0444, "Hello, World");
|
||||||
|
|
||||||
client = wfp_client_create(config);
|
client = wfp_client_create(config);
|
||||||
wfp_client_connect(client, url);
|
wfp_client_connect(client, url);
|
||||||
|
@ -2,20 +2,25 @@
|
|||||||
#include "integration/server.hpp"
|
#include "integration/server.hpp"
|
||||||
#include "integration/provider.hpp"
|
#include "integration/provider.hpp"
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
#include "webfuse/core/lws_log.h"
|
#include "webfuse/core/lws_log.h"
|
||||||
#include "msleep.hpp"
|
#include "msleep.hpp"
|
||||||
|
#include "die_if.hpp"
|
||||||
|
|
||||||
using webfuse_test::Server;
|
using webfuse_test::Server;
|
||||||
using webfuse_test::Provider;
|
using webfuse_test::Provider;
|
||||||
|
using webfuse_test::die_if;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@ -69,10 +74,85 @@ TEST_F(IntegrationTest, ProvidesTextFile)
|
|||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
int rc = stat(file_name.c_str(), &buffer);
|
int rc = stat(file_name.c_str(), &buffer);
|
||||||
|
|
||||||
exit(rc);
|
die_if(0 != rc);
|
||||||
|
die_if(!S_ISREG(buffer.st_mode));
|
||||||
|
die_if(0444 != (buffer.st_mode & 0777));
|
||||||
|
die_if(12 != buffer.st_size);
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}, ::testing::ExitedWithCode(0), ".*");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(IntegrationTest, ReadTextFile)
|
||||||
|
{
|
||||||
|
webfuse_test::msleep(200);
|
||||||
|
std::string file_name = std::string(GetBaseDir()) + "/cprovider/default/hello.txt";
|
||||||
|
|
||||||
|
ASSERT_EXIT({
|
||||||
|
FILE * file = fopen(file_name.c_str(), "rb");
|
||||||
|
die_if(nullptr == file);
|
||||||
|
|
||||||
|
char buffer[13];
|
||||||
|
ssize_t count = fread(buffer, 1, 12, file);
|
||||||
|
int rc = fclose(file);
|
||||||
|
|
||||||
|
die_if(12 != count);
|
||||||
|
die_if(0 != strncmp("Hello, World", buffer, 12));
|
||||||
|
die_if(0 != rc);
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}, ::testing::ExitedWithCode(0), ".*");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(IntegrationTest, ReadDir)
|
||||||
|
{
|
||||||
|
webfuse_test::msleep(200);
|
||||||
|
std::string dir_name = std::string(GetBaseDir()) + "/cprovider/default";
|
||||||
|
|
||||||
|
ASSERT_EXIT({
|
||||||
|
|
||||||
|
DIR * dir = opendir(dir_name.c_str());
|
||||||
|
die_if(nullptr == dir);
|
||||||
|
|
||||||
|
bool found_self = false;
|
||||||
|
bool found_parent = false;
|
||||||
|
bool found_hello_txt = false;
|
||||||
|
bool found_other = false;
|
||||||
|
|
||||||
|
dirent * entry = readdir(dir);
|
||||||
|
while (NULL != entry)
|
||||||
|
{
|
||||||
|
if (0 == strcmp(".", entry->d_name))
|
||||||
|
{
|
||||||
|
found_self = true;
|
||||||
|
}
|
||||||
|
else if (0 == strcmp("..", entry->d_name))
|
||||||
|
{
|
||||||
|
found_parent = true;
|
||||||
|
}
|
||||||
|
else if (0 == strcmp("hello.txt", entry->d_name))
|
||||||
|
{
|
||||||
|
found_hello_txt = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
found_other = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
entry = readdir(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
|
||||||
|
die_if(!found_self);
|
||||||
|
die_if(!found_parent);
|
||||||
|
die_if(!found_hello_txt);
|
||||||
|
|
||||||
|
die_if(found_other);
|
||||||
|
|
||||||
|
exit(0);
|
||||||
}, ::testing::ExitedWithCode(0), ".*");
|
}, ::testing::ExitedWithCode(0), ".*");
|
||||||
|
|
||||||
// ASSERT_TRUE(S_ISREG(buffer.st_mode));
|
|
||||||
// ASSERT_EQ(0444, (buffer.st_mode & 0777));
|
|
||||||
// ASSERT_EQ(12, buffer.st_size);
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user