]> granicus.if.org Git - icinga2/blob - test/livestatus-fixture.cpp
Merge pull request #6544 from gunnarbeutner/fix/deprecated-strstream-header
[icinga2] / test / livestatus-fixture.cpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)  *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #include "config/configcompiler.hpp"
21 #include "config/configitem.hpp"
22 #include "base/application.hpp"
23 #include "base/loader.hpp"
24 #include "icingaapplication-fixture.hpp"
25 #include <BoostTestTargetConfig.h>
26
27 using namespace icinga;
28
29 struct LivestatusFixture
30 {
31         LivestatusFixture()
32         {
33                 // ensure IcingaApplication is initialized before we try to add config
34                 IcingaApplicationFixture icinga;
35
36                 BOOST_TEST_MESSAGE("Preparing config objects...");
37
38                 ConfigItem::RunWithActivationContext(new Function("CreateTestObjects", CreateTestObjects));
39         }
40
41         static void CreateTestObjects()
42         {
43                 String config = R"CONFIG(
44 object CheckCommand "dummy" {
45   command = "/bin/echo"
46 }
47
48 object Host "test-01" {
49   address = "127.0.0.1"
50   check_command = "dummy"
51 }
52
53 object Host "test-02" {
54   address = "127.0.0.2"
55   check_command = "dummy"
56 }
57
58 apply Service "livestatus" {
59   check_command = "dummy"
60   notes = "test livestatus"
61   assign where match("test-*", host.name)
62 }
63 )CONFIG";
64
65                 std::unique_ptr<Expression> expr = ConfigCompiler::CompileText("<livestatus>", config);
66                 expr->Evaluate(*ScriptFrame::GetCurrentFrame());
67         }
68 };
69
70 BOOST_GLOBAL_FIXTURE(LivestatusFixture);