Skip to content

Commit

Permalink
Add basic test cases for `Type::GetConfigTypesSortedByLoadDependencie…
Browse files Browse the repository at this point in the history
…s()`
  • Loading branch information
yhabteab committed Sep 11, 2024
1 parent ce0eb79 commit bfcfe80
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ add_boost_test(base
base_type/assign
base_type/byname
base_type/instantiate
base_type/sort_by_load_after
base_utility/parse_version
base_utility/compare_version
base_utility/comparepasswords_works
Expand Down
34 changes: 34 additions & 0 deletions test/base-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "base/objectlock.hpp"
#include "base/application.hpp"
#include "base/type.hpp"
#include "icinga/host.hpp"
#include "icinga/service.hpp"
#include <BoostTestTargetConfig.h>

using namespace icinga;
Expand Down Expand Up @@ -44,4 +46,36 @@ BOOST_AUTO_TEST_CASE(instantiate)
BOOST_CHECK(p);
}

BOOST_AUTO_TEST_CASE(sort_by_load_after)
{
auto types (Type::GetConfigTypesSortedByLoadDependencies());
BOOST_REQUIRE_GE(types.size(), 29);

std::unordered_set<Type*> previousTypes;
for (auto type : types) {
BOOST_CHECK_EQUAL(true, ConfigObject::TypeInstance->IsAssignableFrom(type));

if (previousTypes.size() == 0) {
BOOST_CHECK_EQUAL(0, type->GetLoadDependencies().size());
} else {
if (Service::TypeInstance->IsAssignableFrom(type) || Endpoint::TypeInstance->IsAssignableFrom(type)) {
BOOST_CHECK_MESSAGE(type->GetLoadDependencies().size() > 0, "load dependencies must be non-zero");
}

for (Type* dependency : type->GetLoadDependencies()) {
BOOST_CHECK_MESSAGE(previousTypes.find(dependency) != previousTypes.end(), "type '" << type->GetName()
<< "' depends on '"<< dependency->GetName() << "' type, but it's not loaded before");
}
}

previousTypes.emplace(type.get());
}

BOOST_CHECK_MESSAGE(previousTypes.find(Host::TypeInstance.get()) != previousTypes.end(), "host type should be in the list");
BOOST_CHECK_MESSAGE(previousTypes.find(Service::TypeInstance.get()) != previousTypes.end(), "service type should be in the list");
BOOST_CHECK_MESSAGE(previousTypes.find(Endpoint::TypeInstance.get()) != previousTypes.end(), "endpoint type should be in the list");
BOOST_CHECK_MESSAGE(previousTypes.find(Downtime::TypeInstance.get()) != previousTypes.end(), "downtime type should be in the list");
BOOST_CHECK_MESSAGE(previousTypes.find(Comment::TypeInstance.get()) != previousTypes.end(), "comment type should be in the list");
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit bfcfe80

Please sign in to comment.