Skip to content

Commit

Permalink
use test fixtures and setup with InitDirGlobals
Browse files Browse the repository at this point in the history
  • Loading branch information
alaaeddineelamri authored and pstorz committed May 11, 2023
1 parent e8b16cb commit 80743c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion core/src/tests/CMakeLists.txt
Expand Up @@ -287,7 +287,7 @@ if(NOT client-only)
bareos_add_test(sort_stringvector LINK_LIBRARIES bareos GTest::gtest_main)
bareos_add_test(
test_config_parser_dir LINK_LIBRARIES dird_objects bareos bareosfind
bareossql GTest::gtest_main
testing_common bareossql GTest::gtest_main
)
set_tests_properties(
gtest:ConfigParser_Dir.bareos_configparser_tests
Expand Down
35 changes: 17 additions & 18 deletions core/src/tests/test_config_parser_dir.cc
Expand Up @@ -30,6 +30,7 @@
#include "dird/dird_globals.h"
#include "dird/dird_conf.h"
#include "lib/output_formatter_resource.h"
#include "testing_dir_common.h"

#include <thread>
#include <condition_variable>
Expand All @@ -53,10 +54,12 @@ bool sprintit(void*, const char* fmt, ...)
return true;
}

TEST(ConfigParser_Dir, ParseSchedulerOddEvenDaysCorrectly)
{
OSDependentInit();
class ConfigParser_Dir : public ::testing::Test {
void SetUp() override { InitDirGlobals(); }
};

TEST_F(ConfigParser_Dir, ParseSchedulerOddEvenDaysCorrectly)
{
std::string path_to_config_file = std::string(
RELATIVE_PROJECT_SOURCE_DIR "/configs/bareos-configparser-tests");
my_config = InitDirConfig(path_to_config_file.c_str(), M_ERROR_TERM);
Expand Down Expand Up @@ -96,9 +99,8 @@ TEST(ConfigParser_Dir, ParseSchedulerOddEvenDaysCorrectly)
EXPECT_EQ(sprintoutput, expected_output);
}

TEST(ConfigParser_Dir, bareos_configparser_tests)
TEST_F(ConfigParser_Dir, bareos_configparser_tests)
{
OSDependentInit();
std::string path_to_config_file = std::string(
RELATIVE_PROJECT_SOURCE_DIR "/configs/bareos-configparser-tests");
my_config = InitDirConfig(path_to_config_file.c_str(), M_ERROR_TERM);
Expand Down Expand Up @@ -133,9 +135,8 @@ TEST(ConfigParser_Dir, bareos_configparser_tests)
delete my_config;
}

TEST(ConfigParser_Dir, foreach_res_and_reload)
TEST_F(ConfigParser_Dir, foreach_res_and_reload)
{
OSDependentInit();
std::string path_to_config_file = std::string(
RELATIVE_PROJECT_SOURCE_DIR "/configs/bareos-configparser-tests");
my_config = InitDirConfig(path_to_config_file.c_str(), M_ERROR_TERM);
Expand Down Expand Up @@ -190,10 +191,8 @@ TEST(ConfigParser_Dir, foreach_res_and_reload)
delete my_config;
} // namespace directordaemon

TEST(ConfigParser_Dir, runscript_test)
TEST_F(ConfigParser_Dir, runscript_test)
{
OSDependentInit();

std::string path_to_config_file = std::string(
RELATIVE_PROJECT_SOURCE_DIR "/configs/runscript-tests/bareos-dir.conf");
my_config = InitDirConfig(path_to_config_file.c_str(), M_ERROR_TERM);
Expand Down Expand Up @@ -240,7 +239,7 @@ void test_CFG_TYPE_AUDIT(DirectorResource* me)
EXPECT_EQ(me->audit_events->size(), 8);
}

TEST(ConfigParser_Dir, CFG_TYPE_AUDIT)
TEST_F(ConfigParser_Dir, CFG_TYPE_AUDIT)
{
test_config_directive_type(test_CFG_TYPE_AUDIT);
}
Expand All @@ -253,7 +252,7 @@ void test_CFG_TYPE_PLUGIN_NAMES(DirectorResource* me)
EXPECT_EQ(me->plugin_names->size(), 16);
}

TEST(ConfigParser_Dir, CFG_TYPE_PLUGIN_NAMES)
TEST_F(ConfigParser_Dir, CFG_TYPE_PLUGIN_NAMES)
{
test_config_directive_type(test_CFG_TYPE_PLUGIN_NAMES);
}
Expand All @@ -264,7 +263,7 @@ void test_CFG_TYPE_STR_VECTOR(DirectorResource* me)
EXPECT_EQ(me->tls_cert_.allowed_certificate_common_names_.size(), 8);
}

TEST(ConfigParser_Dir, CFG_TYPE_STR_VECTOR)
TEST_F(ConfigParser_Dir, CFG_TYPE_STR_VECTOR)
{
test_config_directive_type(test_CFG_TYPE_STR_VECTOR);
}
Expand All @@ -285,7 +284,7 @@ void test_CFG_TYPE_ALIST_STR(DirectorResource*)
EXPECT_EQ(job2->run_cmds->size(), 8);
}

TEST(ConfigParser_Dir, CFG_TYPE_ALIST_STR)
TEST_F(ConfigParser_Dir, CFG_TYPE_ALIST_STR)
{
test_config_directive_type(test_CFG_TYPE_ALIST_STR);
}
Expand All @@ -299,7 +298,7 @@ void test_CFG_TYPE_ALIST_RES(DirectorResource*)
EXPECT_EQ(job1->base->size(), 8);
}

TEST(ConfigParser_Dir, CFG_TYPE_ALIST_RES)
TEST_F(ConfigParser_Dir, CFG_TYPE_ALIST_RES)
{
test_config_directive_type(test_CFG_TYPE_ALIST_RES);
}
Expand All @@ -312,7 +311,7 @@ void test_CFG_TYPE_STR(DirectorResource* me)
EXPECT_STREQ(me->description_, "item31");
}

TEST(ConfigParser_Dir, CFG_TYPE_STR)
TEST_F(ConfigParser_Dir, CFG_TYPE_STR)
{
test_config_directive_type(test_CFG_TYPE_STR);
}
Expand All @@ -332,7 +331,7 @@ void test_CFG_TYPE_FNAME(DirectorResource*)
foreach_alist (val, files) { printf("Files = %s\n", val); }
}

TEST(ConfigParser_Dir, CFG_TYPE_FNAME)
TEST_F(ConfigParser_Dir, CFG_TYPE_FNAME)
{
test_config_directive_type(test_CFG_TYPE_FNAME);
}
Expand All @@ -345,7 +344,7 @@ void test_CFG_TYPE_TIME(DirectorResource* me)
EXPECT_EQ(me->heartbeat_interval, 38898367);
}

TEST(ConfigParser_Dir, CFG_TYPE_TIME)
TEST_F(ConfigParser_Dir, CFG_TYPE_TIME)
{
test_config_directive_type(test_CFG_TYPE_TIME);
}
Expand Down

0 comments on commit 80743c9

Please sign in to comment.