Skip to content

Commit 7c56ec3

Browse files
committed
Add basic test cases for Type::GetConfigTypesSortedByLoadDependencies()
1 parent ce0eb79 commit 7c56ec3

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ add_boost_test(base
121121
base_type/assign
122122
base_type/byname
123123
base_type/instantiate
124+
base_type/sort_by_load_after
124125
base_utility/parse_version
125126
base_utility/compare_version
126127
base_utility/comparepasswords_works

test/base-type.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "base/type.hpp"
88
#include <BoostTestTargetConfig.h>
99

10+
#include "icinga/service.hpp"
11+
1012
using namespace icinga;
1113

1214
BOOST_AUTO_TEST_SUITE(base_type)
@@ -44,4 +46,36 @@ BOOST_AUTO_TEST_CASE(instantiate)
4446
BOOST_CHECK(p);
4547
}
4648

49+
BOOST_AUTO_TEST_CASE(sort_by_load_after)
50+
{
51+
auto types (Type::GetConfigTypesSortedByLoadDependencies());
52+
BOOST_REQUIRE_GE(types.size(), 29);
53+
54+
std::unordered_set<Type*> previousTypes;
55+
for (auto type : types) {
56+
BOOST_CHECK_EQUAL(true, ConfigObject::TypeInstance->IsAssignableFrom(type));
57+
58+
if (previousTypes.size() == 0) {
59+
BOOST_CHECK_EQUAL(0, type->GetLoadDependencies().size());
60+
} else {
61+
if (Service::TypeInstance->IsAssignableFrom(type) || Endpoint::TypeInstance->IsAssignableFrom(type)) {
62+
BOOST_CHECK_MESSAGE(type->GetLoadDependencies().size() > 0, "load dependencies must be non-zero");
63+
}
64+
65+
for (Type* dependency : type->GetLoadDependencies()) {
66+
BOOST_CHECK_MESSAGE(previousTypes.find(dependency) != previousTypes.end(), "type '" << type->GetName()
67+
<< "' depends on '"<< dependency->GetName() << "' type, but it's not loaded before");
68+
}
69+
}
70+
71+
previousTypes.emplace(type.get());
72+
}
73+
74+
BOOST_CHECK_MESSAGE(previousTypes.find(Host::TypeInstance.get()) != previousTypes.end(), "host type should be in the list");
75+
BOOST_CHECK_MESSAGE(previousTypes.find(Service::TypeInstance.get()) != previousTypes.end(), "service type should be in the list");
76+
BOOST_CHECK_MESSAGE(previousTypes.find(Endpoint::TypeInstance.get()) != previousTypes.end(), "endpoint type should be in the list");
77+
BOOST_CHECK_MESSAGE(previousTypes.find(Downtime::TypeInstance.get()) != previousTypes.end(), "downtime type should be in the list");
78+
BOOST_CHECK_MESSAGE(previousTypes.find(Comment::TypeInstance.get()) != previousTypes.end(), "comment type should be in the list");
79+
}
80+
4781
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)