Skip to content

Commit

Permalink
unittest: setting up test
Browse files Browse the repository at this point in the history
Test crashes in case the checks do not work properly
  • Loading branch information
alaaeddineelamri committed Apr 6, 2022
1 parent 07610ed commit d5afd6f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
8 changes: 8 additions & 0 deletions core/src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,11 @@ endif() # NOT client-only
if(NOT client-only)
bareos_add_test(select_functions LINK_LIBRARIES dird_objects bareosfind bareossql GTest::gtest_main)
endif() # NOT client-only

if(NOT client-only)
bareos_add_test(
dir_fd_connection
LINK_LIBRARIES testing_common dird_objects bareos bareossql bareosfind
GTest::gtest_main
)
endif() # NOT client-only
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Client {
Name = fd-no-connection
Address = localhost
Password = ""
Connection From Director To Client = no
}
46 changes: 46 additions & 0 deletions core/src/tests/dir_fd_connection.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2022-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/

#include "testing_dir_common.h"

#include "dird/ua.h"
#include "dird/fd_cmds.cc"
#include "dird/job.cc"

TEST(DirectorToClientConnection, DoesNotConnectWhenDisabled)
{
InitDirGlobals();
std::string path_to_config
= std::string(RELATIVE_PROJECT_SOURCE_DIR
"/configs/dir_fd_connection/dir_to_fd_connection_no/");

PConfigParser director_config(DirectorPrepareResources(path_to_config));


JobControlRecord* jcr = directordaemon::NewDirectorJcr();

jcr->impl->res.client = static_cast<directordaemon::ClientResource*>(
directordaemon::my_config->GetResWithName(directordaemon::R_CLIENT,
"fd-no-connection"));
directordaemon::UaContext* ua = nullptr;

EXPECT_FALSE(ConnectToFileDaemon(jcr, 0, 0, false, ua));
}
6 changes: 3 additions & 3 deletions core/src/tests/testing_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

#if defined(HAVE_MINGW)
# include "include/bareos.h"
# include "gtest/gtest.h"
#else
# include "gtest/gtest.h"
#endif

#include "gtest/gtest.h"
#include "gmock/gmock.h"

#include "lib/parse_conf.h"

typedef std::unique_ptr<ConfigurationParser> PConfigParser;
Expand Down
1 change: 0 additions & 1 deletion core/src/tests/testing_dir_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ PConfigParser DirectorPrepareResources(const std::string& path_to_config)
EXPECT_TRUE(parse_director_config_ok) << "Could not parse director config";
if (!parse_director_config_ok) { return nullptr; }

Dmsg0(200, "Start UA server\n");
directordaemon::me
= (directordaemon::DirectorResource*)director_config->GetNextRes(
directordaemon::R_DIRECTOR, nullptr);
Expand Down

0 comments on commit d5afd6f

Please sign in to comment.