]> granicus.if.org Git - icinga2/blob - test/livestatus-fixture.cpp
Merge pull request #5940 from Icinga/fix/chocolatey
[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 <BoostTestTargetConfig.h>
25
26 using namespace icinga;
27
28 struct LivestatusFixture
29 {
30         LivestatusFixture()
31         {
32                 BOOST_TEST_MESSAGE("Preparing config objects...");
33
34                 ConfigItem::RunWithActivationContext(new Function("CreateTestObjects", CreateTestObjects));
35         }
36
37         static void CreateTestObjects()
38         {
39                 String config = R"CONFIG(
40 object CheckCommand "dummy" {
41   command = "/bin/echo"
42 }
43
44 object Host "test-01" {
45   address = "127.0.0.1"
46   check_command = "dummy"
47 }
48
49 object Host "test-02" {
50   address = "127.0.0.2"
51   check_command = "dummy"
52 }
53
54 apply Service "livestatus" {
55   check_command = "dummy"
56   notes = "test livestatus"
57   assign where match("test-*", host.name)
58 }
59 )CONFIG";
60
61                 std::unique_ptr<Expression> expr = ConfigCompiler::CompileText("<livestatus>", config);
62                 expr->Evaluate(*ScriptFrame::GetCurrentFrame());
63         }
64 };
65
66 BOOST_GLOBAL_FIXTURE(LivestatusFixture);