From e0195567199d6c22cb75f6484e54298f32f5e60d Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Tue, 10 Sep 2024 09:28:28 +0200 Subject: [PATCH] Add basic test cases for `Type::GetConfigTypesSortedByLoadDependencies()` --- test/CMakeLists.txt | 1 + test/base-type.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e3772886abd..80d49772125 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 diff --git a/test/base-type.cpp b/test/base-type.cpp index 21bcf439d35..99a883c4f3a 100644 --- a/test/base-type.cpp +++ b/test/base-type.cpp @@ -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 using namespace icinga; @@ -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 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()