mirror of https://github.com/Icinga/icinga2.git
parent
7b371f20d8
commit
99735a5b2d
|
@ -23,13 +23,13 @@ set(base_test_SOURCES
|
|||
base-serialize.cpp base-shellescape.cpp base-stacktrace.cpp
|
||||
base-stream.cpp base-string.cpp base-timer.cpp base-type.cpp
|
||||
base-value.cpp config-ops.cpp icinga-macros.cpp
|
||||
icinga-perfdata.cpp test.cpp
|
||||
icinga-perfdata.cpp base-test.cpp
|
||||
remote-base64.cpp remote-url.cpp
|
||||
)
|
||||
|
||||
set(livestatus_test_SOURCES
|
||||
livestatus.cpp
|
||||
test.cpp
|
||||
livestatus-test.cpp
|
||||
)
|
||||
|
||||
set_property(SOURCE test.cpp PROPERTY EXCLUDE_UNITY_BUILD TRUE)
|
||||
|
@ -39,7 +39,7 @@ if(ICINGA2_UNITY_BUILD)
|
|||
endif()
|
||||
|
||||
add_boost_test(base
|
||||
SOURCES test.cpp ${base_test_SOURCES}
|
||||
SOURCES base-test.cpp ${base_test_SOURCES}
|
||||
LIBRARIES base config icinga
|
||||
TESTS base_array/construct
|
||||
base_array/getset
|
||||
|
@ -117,8 +117,9 @@ add_boost_test(base
|
|||
|
||||
if(ICINGA2_WITH_LIVESTATUS)
|
||||
add_boost_test(livestatus
|
||||
SOURCES test.cpp ${livestatus_test_SOURCES}
|
||||
SOURCES livestatus-test.cpp ${livestatus_test_SOURCES}
|
||||
LIBRARIES base config icinga cli livestatus
|
||||
DEPENDENCIES methods
|
||||
TESTS livestatus/hosts livestatus/services
|
||||
)
|
||||
endif()
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* 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 General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#define BOOST_TEST_MODULE icinga2_test
|
||||
|
||||
#include "cli/daemonutility.hpp"
|
||||
#include "config/configcompiler.hpp"
|
||||
#include "config/configitem.hpp"
|
||||
#include "base/application.hpp"
|
||||
#include "base/loader.hpp"
|
||||
#include <fstream>
|
||||
#include <BoostTestTargetConfig.h>
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
struct LivestatusFixture
|
||||
{
|
||||
LivestatusFixture(void)
|
||||
: TestConfig("test-config.conf")
|
||||
{
|
||||
BOOST_TEST_MESSAGE("setup global config fixture");
|
||||
|
||||
Application::InitializeBase();
|
||||
|
||||
String cfg_file_path = TestConfig;
|
||||
String cfg_file_path_tmp = TestConfig + ".tmp";
|
||||
|
||||
std::ofstream cfgfp;
|
||||
cfgfp.open(cfg_file_path_tmp.CStr(), std::ofstream::out | std::ofstream::trunc);
|
||||
cfgfp << std::fixed;
|
||||
cfgfp << "object CheckCommand \"dummy\" {\n";
|
||||
cfgfp << " execute = PluginCheck\n";
|
||||
cfgfp << " command = \"/bin/echo\"\n";
|
||||
cfgfp << "}\n";
|
||||
cfgfp << "object Host \"test-01\" {\n";
|
||||
cfgfp << " address = \"127.0.0.1\"\n";
|
||||
cfgfp << " check_command = \"dummy\"\n";
|
||||
cfgfp << "}\n";
|
||||
cfgfp << "object Host \"test-02\" {\n";
|
||||
cfgfp << " address = \"127.0.0.2\"\n";
|
||||
cfgfp << " check_command = \"dummy\"\n";
|
||||
cfgfp << "}\n";
|
||||
cfgfp << "apply Service \"livestatus\"{\n";
|
||||
cfgfp << " check_command = \"dummy\"\n";
|
||||
cfgfp << " notes = \"test livestatus\"\n";
|
||||
cfgfp << " assign where match(\"test-*\", host.name)\n";
|
||||
cfgfp << "}\n";
|
||||
|
||||
cfgfp.close();
|
||||
#ifdef _WIN32
|
||||
_unlink(cfg_file_path.CStr());
|
||||
#endif /* _WIN32 */
|
||||
|
||||
if (rename(cfg_file_path_tmp.CStr(), cfg_file_path.CStr()) < 0) {
|
||||
BOOST_THROW_EXCEPTION(posix_error()
|
||||
<< boost::errinfo_api_function("rename")
|
||||
<< boost::errinfo_errno(errno)
|
||||
<< boost::errinfo_file_name(cfg_file_path_tmp));
|
||||
}
|
||||
|
||||
BOOST_TEST_MESSAGE( "Preparing config objects...");
|
||||
|
||||
/* start the Icinga application and load the configuration */
|
||||
Application::DeclareSysconfDir("etc");
|
||||
Application::DeclareLocalStateDir("var");
|
||||
|
||||
ActivationScope ascope;
|
||||
|
||||
Loader::LoadExtensionLibrary("icinga");
|
||||
Loader::LoadExtensionLibrary("methods"); //loaded by ITL
|
||||
|
||||
std::vector<std::string> configs;
|
||||
configs.push_back(TestConfig);
|
||||
|
||||
std::vector<ConfigItem::Ptr> newItems;
|
||||
|
||||
DaemonUtility::LoadConfigFiles(configs, newItems, "icinga2.debug", "icinga2.vars");
|
||||
|
||||
/* ignore config errors */
|
||||
WorkQueue upq;
|
||||
ConfigItem::ActivateItems(upq, newItems);
|
||||
}
|
||||
|
||||
~LivestatusFixture(void)
|
||||
{
|
||||
BOOST_TEST_MESSAGE("cleanup global config fixture");
|
||||
|
||||
unlink(TestConfig.CStr());
|
||||
|
||||
Application::UninitializeBase();
|
||||
}
|
||||
|
||||
String TestConfig;
|
||||
};
|
||||
|
||||
BOOST_GLOBAL_FIXTURE(LivestatusFixture);
|
||||
|
|
@ -18,100 +18,13 @@
|
|||
******************************************************************************/
|
||||
|
||||
#include "livestatus/livestatusquery.hpp"
|
||||
#include "config/configcompiler.hpp"
|
||||
#include "config/configitem.hpp"
|
||||
#include "base/application.hpp"
|
||||
#include "base/stdiostream.hpp"
|
||||
#include "base/json.hpp"
|
||||
#include "base/loader.hpp"
|
||||
#include "cli/daemonutility.hpp"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <fstream>
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
struct GlobalConfigFixture {
|
||||
GlobalConfigFixture()
|
||||
: TestConfig("test-config.conf")
|
||||
{
|
||||
BOOST_TEST_MESSAGE("setup global config fixture");
|
||||
|
||||
String cfg_file_path = TestConfig;
|
||||
String cfg_file_path_tmp = TestConfig + ".tmp";
|
||||
|
||||
std::ofstream cfgfp;
|
||||
cfgfp.open(cfg_file_path_tmp.CStr(), std::ofstream::out | std::ofstream::trunc);
|
||||
cfgfp << std::fixed;
|
||||
cfgfp << "object CheckCommand \"dummy\" {\n";
|
||||
cfgfp << " execute = PluginCheck\n";
|
||||
cfgfp << " command = \"/bin/echo\"\n";
|
||||
cfgfp << "}\n";
|
||||
cfgfp << "object Host \"test-01\" {\n";
|
||||
cfgfp << " address = \"127.0.0.1\"\n";
|
||||
cfgfp << " check_command = \"dummy\"\n";
|
||||
cfgfp << "}\n";
|
||||
cfgfp << "object Host \"test-02\" {\n";
|
||||
cfgfp << " address = \"127.0.0.2\"\n";
|
||||
cfgfp << " check_command = \"dummy\"\n";
|
||||
cfgfp << "}\n";
|
||||
cfgfp << "apply Service \"livestatus\"{\n";
|
||||
cfgfp << " check_command = \"dummy\"\n";
|
||||
cfgfp << " notes = \"test livestatus\"\n";
|
||||
cfgfp << " assign where match(\"test-*\", host.name)\n";
|
||||
cfgfp << "}\n";
|
||||
|
||||
cfgfp.close();
|
||||
#ifdef _WIN32
|
||||
_unlink(cfg_file_path.CStr());
|
||||
#endif /* _WIN32 */
|
||||
|
||||
if (rename(cfg_file_path_tmp.CStr(), cfg_file_path.CStr()) < 0) {
|
||||
BOOST_THROW_EXCEPTION(posix_error()
|
||||
<< boost::errinfo_api_function("rename")
|
||||
<< boost::errinfo_errno(errno)
|
||||
<< boost::errinfo_file_name(cfg_file_path_tmp));
|
||||
}
|
||||
|
||||
BOOST_TEST_MESSAGE( "Preparing config objects...");
|
||||
|
||||
/* start the Icinga application and load the configuration */
|
||||
Application::DeclareSysconfDir("etc");
|
||||
Application::DeclareLocalStateDir("var");
|
||||
|
||||
ActivationScope ascope;
|
||||
|
||||
Loader::LoadExtensionLibrary("icinga");
|
||||
Loader::LoadExtensionLibrary("methods"); //loaded by ITL
|
||||
|
||||
std::vector<std::string> configs;
|
||||
configs.push_back(TestConfig);
|
||||
|
||||
std::vector<ConfigItem::Ptr> newItems;
|
||||
|
||||
DaemonUtility::LoadConfigFiles(configs, newItems, "icinga2.debug", "icinga2.vars");
|
||||
|
||||
/* ignore config errors */
|
||||
WorkQueue upq;
|
||||
ConfigItem::ActivateItems(upq, newItems);
|
||||
}
|
||||
|
||||
~GlobalConfigFixture()
|
||||
{
|
||||
BOOST_TEST_MESSAGE("cleanup global config fixture");
|
||||
|
||||
unlink(TestConfig.CStr());
|
||||
}
|
||||
|
||||
String TestConfig;
|
||||
};
|
||||
|
||||
BOOST_GLOBAL_FIXTURE(GlobalConfigFixture);
|
||||
|
||||
struct LocalFixture {
|
||||
LocalFixture() { }
|
||||
~LocalFixture() { }
|
||||
};
|
||||
|
||||
String LivestatusQueryHelper(const std::vector<String>& lines)
|
||||
{
|
||||
LivestatusQuery::Ptr query = new LivestatusQuery(lines, "");
|
||||
|
@ -147,7 +60,7 @@ String LivestatusQueryHelper(const std::vector<String>& lines)
|
|||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(livestatus, LocalFixture)
|
||||
BOOST_AUTO_TEST_SUITE(livestatus)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(hosts)
|
||||
{
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
# [LAUNCHER <generic launcher script>]
|
||||
# [LIBRARIES <library> [<library>...]]
|
||||
# [RESOURCES <resource> [<resource>...]]
|
||||
# [TESTS <testcasename> [<testcasename>...]])
|
||||
# [TESTS <testcasename> [<testcasename>...]]
|
||||
# [DEPENDENCIES <dependency> [<dependency>...]])
|
||||
#
|
||||
# If for some reason you need access to the executable target created,
|
||||
# it can be found in ${${testdriver_name}_TARGET_NAME} as specified when
|
||||
|
@ -116,7 +117,8 @@ function(add_boost_test _name)
|
|||
LAUNCHER
|
||||
LIBRARIES
|
||||
RESOURCES
|
||||
TESTS)
|
||||
TESTS
|
||||
DEPENDENCIES)
|
||||
set(_bool_args
|
||||
USE_COMPILED_LIBRARY)
|
||||
foreach(_arg ${_val_args} ${_bool_args})
|
||||
|
@ -265,6 +267,10 @@ function(add_boost_test _name)
|
|||
endif()
|
||||
endif()
|
||||
|
||||
if (DEPENDENCIES)
|
||||
add_dependencies(${_target_name} ${DEPENDENCIES})
|
||||
endif()
|
||||
|
||||
# CppCheck the test if we can.
|
||||
if(COMMAND add_cppcheck)
|
||||
add_cppcheck(${_target_name} STYLE UNUSED_FUNCTIONS)
|
||||
|
|
Loading…
Reference in New Issue