]> granicus.if.org Git - icinga2/blob - test/livestatus-fixture.cpp
Merge pull request #7383 from K0nne/K0nne-patch-1
[icinga2] / test / livestatus-fixture.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "config/configcompiler.hpp"
4 #include "config/configitem.hpp"
5 #include "base/application.hpp"
6 #include "base/loader.hpp"
7 #include "icingaapplication-fixture.hpp"
8 #include <BoostTestTargetConfig.h>
9
10 using namespace icinga;
11
12 struct LivestatusFixture
13 {
14         LivestatusFixture()
15         {
16                 // ensure IcingaApplication is initialized before we try to add config
17                 IcingaApplicationFixture icinga;
18
19                 BOOST_TEST_MESSAGE("Preparing config objects...");
20
21                 ConfigItem::RunWithActivationContext(new Function("CreateTestObjects", CreateTestObjects));
22         }
23
24         static void CreateTestObjects()
25         {
26                 String config = R"CONFIG(
27 object CheckCommand "dummy" {
28   command = "/bin/echo"
29 }
30
31 object Host "test-01" {
32   address = "127.0.0.1"
33   check_command = "dummy"
34 }
35
36 object Host "test-02" {
37   address = "127.0.0.2"
38   check_command = "dummy"
39 }
40
41 apply Service "livestatus" {
42   check_command = "dummy"
43   notes = "test livestatus"
44   assign where match("test-*", host.name)
45 }
46 )CONFIG";
47
48                 std::unique_ptr<Expression> expr = ConfigCompiler::CompileText("<livestatus>", config);
49                 expr->Evaluate(*ScriptFrame::GetCurrentFrame());
50         }
51 };
52
53 BOOST_GLOBAL_FIXTURE(LivestatusFixture);