|
5 | 5 | #include "base/objectlock.hpp"
|
6 | 6 | #include "base/application.hpp"
|
7 | 7 | #include "base/type.hpp"
|
| 8 | +#include "icinga/host.hpp" |
| 9 | +#include "icinga/service.hpp" |
8 | 10 | #include <BoostTestTargetConfig.h>
|
9 | 11 |
|
10 | 12 | using namespace icinga;
|
11 | 13 |
|
12 |
| -BOOST_AUTO_TEST_SUITE(base_type) |
| 14 | +BOOST_AUTO_TEST_SUITE(types) |
13 | 15 |
|
14 | 16 | BOOST_AUTO_TEST_CASE(gettype)
|
15 | 17 | {
|
@@ -44,4 +46,33 @@ BOOST_AUTO_TEST_CASE(instantiate)
|
44 | 46 | BOOST_CHECK(p);
|
45 | 47 | }
|
46 | 48 |
|
| 49 | +BOOST_AUTO_TEST_CASE(sort_by_load_after) |
| 50 | +{ |
| 51 | + int totalDependencies{0}; |
| 52 | + std::unordered_set<Type*> previousTypes; |
| 53 | + for (auto type : Type::GetConfigTypesSortedByLoadDependencies()) { |
| 54 | + BOOST_CHECK_EQUAL(true, ConfigObject::TypeInstance->IsAssignableFrom(type)); |
| 55 | + |
| 56 | + totalDependencies += type->GetLoadDependencies().size(); |
| 57 | + for (Type* dependency : type->GetLoadDependencies()) { |
| 58 | + // Note, Type::GetConfigTypesSortedByLoadDependencies() does not detect any cyclic load dependencies, |
| 59 | + // instead, it relies on this test case to fail. |
| 60 | + BOOST_CHECK_MESSAGE(previousTypes.find(dependency) != previousTypes.end(), "type '" << type->GetName() |
| 61 | + << "' depends on '"<< dependency->GetName() << "' type, but it's not loaded before"); |
| 62 | + } |
| 63 | + |
| 64 | + previousTypes.emplace(type.get()); |
| 65 | + } |
| 66 | + |
| 67 | + // The magic number 12 is the sum of host,service,comment,downtime and endpoint load_after dependencies. |
| 68 | + BOOST_CHECK_MESSAGE(totalDependencies >= 12, "total size of load dependency must be at least 12"); |
| 69 | + BOOST_CHECK_MESSAGE(previousTypes.find(Host::TypeInstance.get()) != previousTypes.end(), "Host type should be in the list"); |
| 70 | + BOOST_CHECK_MESSAGE(previousTypes.find(Service::TypeInstance.get()) != previousTypes.end(), "Service type should be in the list"); |
| 71 | + BOOST_CHECK_MESSAGE(previousTypes.find(Downtime::TypeInstance.get()) != previousTypes.end(), "Downtime type should be in the list"); |
| 72 | + BOOST_CHECK_MESSAGE(previousTypes.find(Comment::TypeInstance.get()) != previousTypes.end(), "Comment type should be in the list"); |
| 73 | + BOOST_CHECK_MESSAGE(previousTypes.find(Notification::TypeInstance.get()) != previousTypes.end(), "Notification type should be in the list"); |
| 74 | + BOOST_CHECK_MESSAGE(previousTypes.find(Zone::TypeInstance.get()) != previousTypes.end(), "Zone type should be in the list"); |
| 75 | + BOOST_CHECK_MESSAGE(previousTypes.find(Endpoint::TypeInstance.get()) != previousTypes.end(), "Endpoint type should be in the list"); |
| 76 | +} |
| 77 | + |
47 | 78 | BOOST_AUTO_TEST_SUITE_END()
|
0 commit comments