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 12, 2024
1 parent 0e50220 commit b21a41f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ set(base_test_SOURCES
$<TARGET_OBJECTS:methods>
)

if(ICINGA2_WITH_CHECKER)
list(APPEND base_test_SOURCES $<TARGET_OBJECTS:checker>)
endif()

if(ICINGA2_WITH_MYSQL)
list(APPEND base_test_SOURCES $<TARGET_OBJECTS:db_ido> $<TARGET_OBJECTS:db_ido_mysql>)
endif()

if(ICINGA2_WITH_PGSQL)
list(APPEND base_test_SOURCES $<TARGET_OBJECTS:db_ido> $<TARGET_OBJECTS:db_ido_pgsql>)
endif()

if(ICINGA2_WITH_ICINGADB)
list(APPEND base_test_SOURCES $<TARGET_OBJECTS:icingadb>)
endif()

if(ICINGA2_WITH_NOTIFICATION)
list(APPEND base_test_SOURCES $<TARGET_OBJECTS:notification>)
endif()

if(ICINGA2_WITH_PERFDATA)
list(APPEND base_test_SOURCES $<TARGET_OBJECTS:perfdata>)
endif()

if(ICINGA2_UNITY_BUILD)
mkunity_target(base test base_test_SOURCES)
endif()
Expand Down Expand Up @@ -121,6 +145,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
29 changes: 29 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,31 @@ BOOST_AUTO_TEST_CASE(instantiate)
BOOST_CHECK(p);
}

BOOST_AUTO_TEST_CASE(sort_by_load_after)
{
int totalDependencies{0};
std::unordered_set<Type*> previousTypes;
for (auto type : Type::GetConfigTypesSortedByLoadDependencies()) {
BOOST_CHECK_EQUAL(true, ConfigObject::TypeInstance->IsAssignableFrom(type));

totalDependencies += type->GetLoadDependencies().size();
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());
}

// The magic number 12 is the sum of host,service,comment,downtime and endpoint load_after dependencies.
BOOST_CHECK_MESSAGE(totalDependencies >= 12, "total size of load dependency must be at least 12");
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(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_CHECK_MESSAGE(previousTypes.find(Notification::TypeInstance.get()) != previousTypes.end(), "Notification type should be in the list");
BOOST_CHECK_MESSAGE(previousTypes.find(Zone::TypeInstance.get()) != previousTypes.end(), "Zone type should be in the list");
BOOST_CHECK_MESSAGE(previousTypes.find(Endpoint::TypeInstance.get()) != previousTypes.end(), "Endpoint type should be in the list");
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit b21a41f

Please sign in to comment.