1
0
mirror of https://github.com/falk-werner/webfused synced 2024-10-27 20:44:08 +00:00

split factory tests

This commit is contained in:
Falk Werner 2020-03-20 15:10:58 +01:00
parent bd4323e53b
commit 390acffe7b
9 changed files with 814 additions and 712 deletions

View File

@ -127,7 +127,13 @@ add_executable(alltests
test/mock/libconfig.cc
test/mock/linux.cc
test/mock/server.cc
test/config/factory.cc
test/config/configfile.cc
test/config/configfile_version.cc
test/config/configfile_server.cc
test/config/configfile_auth.cc
test/config/configfile_filesystem.cc
test/config/configfile_log.cc
test/config/configfile_user.cc
test/config/config.cc
test/config/settings.cc
test/auth/factory.cc

74
test/config/configfile.cc Normal file
View File

@ -0,0 +1,74 @@
#include <gtest/gtest.h>
#include "webfused/config/factory.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
#include "mock/logger.hpp"
#include "mock/config_builder.hpp"
#include "mock/libconfig.hpp"
using ::testing::_;
using ::testing::Return;
using ::testing::StrictMock;
using ::testing::StrEq;
using ::webfused_test::MockLogger;
using ::webfused_test::MockConfigBuilder;
using ::webfused_test::MockLibConfig;
TEST(configfile, is_loadable)
{
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_logger(_,_,_,_)).Times(1).WillOnce(Return(true));
EXPECT_CALL(builder, wfd_config_set_server_vhostname(_,StrEq("localhost"))).Times(1);
EXPECT_CALL(builder, wfd_config_set_server_port(_,8080)).Times(1);
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(true));
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_,_)).Times(1).WillOnce(Return(true));
struct wfd_config * config = wfd_config_load_file("webfused.conf");
ASSERT_NE(nullptr, config);
}
TEST(configfile, minimal_config)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
char const minimal[] = "version = { major = 1, minor = 0 }\n";
struct wfd_config * config = wfd_config_load_string(minimal);
ASSERT_NE(nullptr, config);
}
TEST(configfile, invalid_config)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(0);
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(0);
char const syntax_error[] = "version.major = 1\n";
wfd_config * config = wfd_config_load_string(syntax_error);
ASSERT_EQ(nullptr, config);
}
TEST(configfile, invalid_config_file)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(0);
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(0);
struct wfd_config * config = wfd_config_load_file("invalid.conf");
ASSERT_EQ(nullptr, config);
}

View File

@ -0,0 +1,138 @@
#include <gtest/gtest.h>
#include "webfused/config/factory.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
#include "mock/logger.hpp"
#include "mock/config_builder.hpp"
#include "mock/libconfig.hpp"
using ::testing::_;
using ::testing::Return;
using ::testing::StrictMock;
using ::testing::StrEq;
using ::webfused_test::MockLogger;
using ::webfused_test::MockConfigBuilder;
using ::webfused_test::MockLibConfig;
TEST(config_auth, authentication)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(true));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"authentication:\n"
"(\n"
" {\n"
" provider = \"test\"\n"
" settings: { }\n"
" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config_auth, failed_create_authenticator)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(false));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"authentication:\n"
"(\n"
" {\n"
" provider = \"test\"\n"
" settings: { }\n"
" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config_auth, failed_missing_auth_provider)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"authentication:\n"
"(\n"
" {\n"
" settings: { }\n"
" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config_auth, failed_missing_auth_settings)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"authentication:\n"
"(\n"
" {\n"
" provider = \"test\"\n"
" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config_auth, failed_auth_settings_get_elem)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
MockLibConfig libconfig;
EXPECT_CALL(libconfig, config_setting_get_elem(_,_)).Times(1).WillOnce(Return(nullptr));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"authentication:\n"
"(\n"
" {\n"
" provider = \"test\"\n"
" settings: { }\n"
" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}

View File

@ -0,0 +1,148 @@
#include <gtest/gtest.h>
#include "webfused/config/factory.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
#include "mock/logger.hpp"
#include "mock/config_builder.hpp"
#include "mock/libconfig.hpp"
using ::testing::_;
using ::testing::Return;
using ::testing::StrictMock;
using ::testing::StrEq;
using ::webfused_test::MockLogger;
using ::webfused_test::MockConfigBuilder;
using ::webfused_test::MockLibConfig;
TEST(configfile_fs, filesystems)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(1).WillOnce(Return(true));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(configfile_fs, filesystems_empty)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(configfile_fs, filesystems_failed_add)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(1).WillOnce(Return(false));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(configfile_fs, filesystems_failed_missing_name)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
" {mount_point = \"/tmp/test\" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(configfile_fs, filesystems_failed_missing_mountpoint)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
" {name = \"foo\"}\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(configfile_fs, filesystems_failed_missing_elem)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
MockLibConfig libconfig;
EXPECT_CALL(libconfig, config_setting_get_elem(_,_)).Times(1).WillOnce(Return(nullptr));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}

View File

@ -0,0 +1,128 @@
#include <gtest/gtest.h>
#include "webfused/config/factory.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
#include "mock/logger.hpp"
#include "mock/config_builder.hpp"
#include "mock/libconfig.hpp"
using ::testing::_;
using ::testing::Return;
using ::testing::StrictMock;
using ::testing::StrEq;
using ::webfused_test::MockLogger;
using ::webfused_test::MockConfigBuilder;
using ::webfused_test::MockLibConfig;
TEST(configfile_log, set_logger)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(1).WillOnce(Return(true));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"log:\n"
"{\n"
" provider = \"stderr\"\n"
" level = \"all\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(configfile_log, log_fail_set_logger)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(1).WillOnce(Return(false));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"log:\n"
"{\n"
" provider = \"stderr\"\n"
" level = \"all\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(configfile_log, log_fail_missing_provider)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"log:\n"
"{\n"
" level = \"all\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(configfile_log, log_fail_missing_level)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"log:\n"
"{\n"
" provider = \"stderr\"\n"
" level = \"fancy\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(configfile_log, log_fail_invalid_level)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_logger(_, _, _, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"log:\n"
"{\n"
" provider = \"stderr\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}

View File

@ -0,0 +1,127 @@
#include <gtest/gtest.h>
#include "webfused/config/factory.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
#include "mock/logger.hpp"
#include "mock/config_builder.hpp"
#include "mock/libconfig.hpp"
using ::testing::_;
using ::testing::Return;
using ::testing::StrictMock;
using ::testing::StrEq;
using ::webfused_test::MockLogger;
using ::webfused_test::MockConfigBuilder;
using ::webfused_test::MockLibConfig;
TEST(configfile_server, vhost_name)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_server_vhostname(_,StrEq("some.host"))).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"server:\n"
"{\n"
" vhost_name = \"some.host\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(configfile_server, port)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_server_port(_,54321)).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"server:\n"
"{\n"
" port = 54321\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(configfile_server, tls_certificate)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_server_cert(_, StrEq("/path/to/cert.pem"))).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"server:\n"
"{\n"
" tls:\n"
" {\n"
" certificate = \"/path/to/cert.pem\"\n"
" }\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(configfile_server, tls_key)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_server_key(_,StrEq("/path/to/key.pem"))).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"server:\n"
"{\n"
" tls:\n"
" {\n"
" key = \"/path/to/key.pem\"\n"
" }\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(configfile_server, document_root)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_server_document_root(_,StrEq("/var/www"))).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"server:\n"
"{\n"
" document_root = \"/var/www\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}

View File

@ -0,0 +1,82 @@
#include <gtest/gtest.h>
#include "webfused/config/factory.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
#include "mock/logger.hpp"
#include "mock/config_builder.hpp"
#include "mock/libconfig.hpp"
using ::testing::_;
using ::testing::Return;
using ::testing::StrictMock;
using ::testing::StrEq;
using ::webfused_test::MockLogger;
using ::webfused_test::MockConfigBuilder;
using ::webfused_test::MockLibConfig;
TEST(configfile_user, set_user)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"user:\n"
"{\n"
" name = \"webfused\"\n"
" group = \"webfused\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(configfile_user, set_user_fail_missing_name)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"user:\n"
"{\n"
" group = \"webfused\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(configfile_user, set_user_fail_missing_group)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"user:\n"
"{\n"
" name = \"webfused\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}

View File

@ -0,0 +1,110 @@
#include <gtest/gtest.h>
#include "webfused/config/factory.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
#include "mock/logger.hpp"
#include "mock/config_builder.hpp"
#include "mock/libconfig.hpp"
using ::testing::_;
using ::testing::Return;
using ::testing::StrictMock;
using ::testing::StrEq;
using ::webfused_test::MockLogger;
using ::webfused_test::MockConfigBuilder;
using ::webfused_test::MockLibConfig;
TEST(configfile_version, invalid_major_version_too_low)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
char const too_low[] = "version = { major = 0, minor = 0 }\n";
struct wfd_config * config= wfd_config_load_string(too_low);
ASSERT_EQ(nullptr, config);
}
TEST(configfile_version, invalid_major_version_too_high)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
char const too_high[] = "version = { major = 2, minor = 0 }\n";
struct wfd_config * config = wfd_config_load_string(too_high);
ASSERT_EQ(nullptr, config);
}
TEST(configfile_version, invalid_missing_major_version)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
char const too_high[] = "version = { minor = 0 }\n";
struct wfd_config * config = wfd_config_load_string(too_high);
ASSERT_EQ(nullptr, config);
}
TEST(configfile_version, invalid_missing_minor_version)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
char const too_high[] = "version = { major = 1 }\n";
struct wfd_config * config = wfd_config_load_string(too_high);
ASSERT_EQ(nullptr, config);
}
TEST(configfile_version, valid_older_minor)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_INFO, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
char const valid[] = "version = { major = 1, minor = -1 }\n";
struct wfd_config * config = wfd_config_load_string(valid);
ASSERT_NE(nullptr, config);
}
TEST(configfile_version, valid_newer_minor)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_WARN, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
char const valid[] = "version = { major = 1, minor = 1 }\n";
struct wfd_config * config = wfd_config_load_string(valid);
ASSERT_NE(nullptr, config);
}

View File

@ -1,711 +0,0 @@
#include <gtest/gtest.h>
#include "webfused/config/factory.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
#include "mock/logger.hpp"
#include "mock/config_builder.hpp"
#include "mock/libconfig.hpp"
using ::testing::_;
using ::testing::Return;
using ::testing::StrictMock;
using ::testing::StrEq;
using ::webfused_test::MockLogger;
using ::webfused_test::MockConfigBuilder;
using ::webfused_test::MockLibConfig;
TEST(config, is_loadable)
{
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_logger(_,_,_,_)).Times(1).WillOnce(Return(true));
EXPECT_CALL(builder, wfd_config_set_server_vhostname(_,StrEq("localhost"))).Times(1);
EXPECT_CALL(builder, wfd_config_set_server_port(_,8080)).Times(1);
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(true));
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_,_)).Times(1).WillOnce(Return(true));
struct wfd_config * config = wfd_config_load_file("webfused.conf");
ASSERT_NE(nullptr, config);
}
TEST(config, minimal_config)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
char const minimal[] = "version = { major = 1, minor = 0 }\n";
struct wfd_config * config = wfd_config_load_string(minimal);
ASSERT_NE(nullptr, config);
}
TEST(config, invalid_config)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(0);
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(0);
char const syntax_error[] = "version.major = 1\n";
wfd_config * config = wfd_config_load_string(syntax_error);
ASSERT_EQ(nullptr, config);
}
TEST(config, invalid_config_file)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(0);
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(0);
struct wfd_config * config = wfd_config_load_file("invalid.conf");
ASSERT_EQ(nullptr, config);
}
TEST(config, invalid_major_version_too_low)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
char const too_low[] = "version = { major = 0, minor = 0 }\n";
struct wfd_config * config= wfd_config_load_string(too_low);
ASSERT_EQ(nullptr, config);
}
TEST(config, invalid_major_version_too_high)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
char const too_high[] = "version = { major = 2, minor = 0 }\n";
struct wfd_config * config = wfd_config_load_string(too_high);
ASSERT_EQ(nullptr, config);
}
TEST(config, invalid_missing_major_version)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
char const too_high[] = "version = { minor = 0 }\n";
struct wfd_config * config = wfd_config_load_string(too_high);
ASSERT_EQ(nullptr, config);
}
TEST(config, invalid_missing_minor_version)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
char const too_high[] = "version = { major = 1 }\n";
struct wfd_config * config = wfd_config_load_string(too_high);
ASSERT_EQ(nullptr, config);
}
TEST(config, valid_older_minor)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_INFO, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
char const valid[] = "version = { major = 1, minor = -1 }\n";
struct wfd_config * config = wfd_config_load_string(valid);
ASSERT_NE(nullptr, config);
}
TEST(config, valid_newer_minor)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_WARN, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
char const valid[] = "version = { major = 1, minor = 1 }\n";
struct wfd_config * config = wfd_config_load_string(valid);
ASSERT_NE(nullptr, config);
}
TEST(config, vhost_name)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_server_vhostname(_,StrEq("some.host"))).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"server:\n"
"{\n"
" vhost_name = \"some.host\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, port)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_server_port(_,54321)).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"server:\n"
"{\n"
" port = 54321\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, tls_certificate)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_server_cert(_, StrEq("/path/to/cert.pem"))).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"server:\n"
"{\n"
" tls:\n"
" {\n"
" certificate = \"/path/to/cert.pem\"\n"
" }\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, tls_key)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_server_key(_,StrEq("/path/to/key.pem"))).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"server:\n"
"{\n"
" tls:\n"
" {\n"
" key = \"/path/to/key.pem\"\n"
" }\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, document_root)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_server_document_root(_,StrEq("/var/www"))).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"server:\n"
"{\n"
" document_root = \"/var/www\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, authentication)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(true));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"authentication:\n"
"(\n"
" {\n"
" provider = \"test\"\n"
" settings: { }\n"
" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, failed_create_authenticator)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(false));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"authentication:\n"
"(\n"
" {\n"
" provider = \"test\"\n"
" settings: { }\n"
" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, failed_missing_auth_provider)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"authentication:\n"
"(\n"
" {\n"
" settings: { }\n"
" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, failed_missing_auth_settings)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"authentication:\n"
"(\n"
" {\n"
" provider = \"test\"\n"
" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, failed_auth_settings_get_elem)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
MockLibConfig libconfig;
EXPECT_CALL(libconfig, config_setting_get_elem(_,_)).Times(1).WillOnce(Return(nullptr));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"authentication:\n"
"(\n"
" {\n"
" provider = \"test\"\n"
" settings: { }\n"
" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, filesystems)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(1).WillOnce(Return(true));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, filesystems_empty)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, filesystems_failed_add)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(1).WillOnce(Return(false));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, filesystems_failed_missing_name)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
" {mount_point = \"/tmp/test\" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, filesystems_failed_missing_mountpoint)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
" {name = \"foo\"}\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, filesystems_failed_missing_elem)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
MockLibConfig libconfig;
EXPECT_CALL(libconfig, config_setting_get_elem(_,_)).Times(1).WillOnce(Return(nullptr));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, log)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(1).WillOnce(Return(true));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"log:\n"
"{\n"
" provider = \"stderr\"\n"
" level = \"all\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, log_fail_set_logger)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(1).WillOnce(Return(false));
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"log:\n"
"{\n"
" provider = \"stderr\"\n"
" level = \"all\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, log_fail_missing_provider)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"log:\n"
"{\n"
" level = \"all\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, log_fail_missing_level)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"log:\n"
"{\n"
" provider = \"stderr\"\n"
" level = \"fancy\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, log_fail_invalid_level)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_logger(_, _, _, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"log:\n"
"{\n"
" provider = \"stderr\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, set_user)
{
MockLogger logger;
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"user:\n"
"{\n"
" name = \"webfused\"\n"
" group = \"webfused\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, set_user_fail_missing_name)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"user:\n"
"{\n"
" group = \"webfused\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, set_user_fail_missing_group)
{
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(0);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"user:\n"
"{\n"
" name = \"webfused\"\n"
"}\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}