Skip to content

Commit 91cbc7f

Browse files
committed
tests: Fix containers per element comparisons
1 parent 4bdda1f commit 91cbc7f

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

test/icinga-dependencies.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ static void AssertCheckableRedundancyGroup(Checkable::Ptr checkable, int depende
6363
}
6464
}
6565

66+
static std::vector<DependencyGroup::Ptr> ExtractGroups(const Checkable::Ptr& checkable)
67+
{
68+
auto dependencyGroups(checkable->GetDependencyGroups());
69+
std::sort(dependencyGroups.begin(), dependencyGroups.end());
70+
return dependencyGroups;
71+
}
72+
6673
BOOST_AUTO_TEST_CASE(multi_parent)
6774
{
6875
/* One child host, two parent hosts. Simulate multi-parent dependencies. */
@@ -182,7 +189,7 @@ BOOST_AUTO_TEST_CASE(push_dependency_groups_to_registry)
182189
childHostC->PushDependencyGroupsToRegistry();
183190
childHostD->PushDependencyGroupsToRegistry();
184191

185-
BOOST_TEST(childHostC->GetDependencyGroups() == childHostD->GetDependencyGroups(), boost::test_tools::per_element());
192+
BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
186193
BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());
187194
for (auto& checkable : {childHostC, childHostD}) {
188195
BOOST_CHECK_EQUAL(2, checkable->GetDependencyGroups().size());
@@ -221,7 +228,7 @@ BOOST_AUTO_TEST_CASE(default_redundancy_group_registration_unregistration)
221228
RegisterDependency(depDB, "");
222229
AssertCheckableRedundancyGroup(childHostD, 2, 2, 2);
223230
AssertCheckableRedundancyGroup(childHostC, 2, 2, 2);
224-
BOOST_TEST(childHostC->GetDependencyGroups() == childHostD->GetDependencyGroups(), boost::test_tools::per_element());
231+
BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
225232
BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());
226233

227234
// This is an exact duplicate of depCA, but with a different dependency name.
@@ -238,7 +245,7 @@ BOOST_AUTO_TEST_CASE(default_redundancy_group_registration_unregistration)
238245
RegisterDependency(dependency, "");
239246

240247
if (isAnExactDuplicate) {
241-
BOOST_TEST(childHostC->GetDependencyGroups() == childHostD->GetDependencyGroups(), boost::test_tools::per_element());
248+
BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
242249
}
243250

244251
for (auto& dependencyGroup : childHostD->GetDependencyGroups()) {
@@ -269,7 +276,7 @@ BOOST_AUTO_TEST_CASE(default_redundancy_group_registration_unregistration)
269276
childHostD->RemoveDependency(depDA);
270277
AssertCheckableRedundancyGroup(childHostC, 1, 1, 2);
271278
AssertCheckableRedundancyGroup(childHostD, 1, 1, 2);
272-
BOOST_TEST(childHostC->GetDependencyGroups() == childHostD->GetDependencyGroups(), boost::test_tools::per_element());
279+
BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
273280
BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());
274281

275282
childHostC->RemoveDependency(depCB);
@@ -304,7 +311,7 @@ BOOST_AUTO_TEST_CASE(simple_redundancy_group_registration_unregistration)
304311
// Still 1 redundancy group, but there should be 4 members now, i.e. 2 for each child Checkable.
305312
AssertCheckableRedundancyGroup(childHostC, 2, 1, 4);
306313
AssertCheckableRedundancyGroup(childHostD, 2, 1, 4);
307-
BOOST_TEST(childHostC->GetDependencyGroups() == childHostD->GetDependencyGroups(), boost::test_tools::per_element());
314+
BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
308315
BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());
309316

310317
childHostC->RemoveDependency(depCA);
@@ -319,7 +326,7 @@ BOOST_AUTO_TEST_CASE(simple_redundancy_group_registration_unregistration)
319326
// both child hosts should have the same redundancy group with only depCB and depDB as member.
320327
AssertCheckableRedundancyGroup(childHostC, 1, 1, 2);
321328
AssertCheckableRedundancyGroup(childHostD, 1, 1, 2);
322-
BOOST_TEST(childHostC->GetDependencyGroups() == childHostD->GetDependencyGroups(), boost::test_tools::per_element());
329+
BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
323330
BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());
324331

325332
RegisterDependency(depDA, depDA->GetRedundancyGroup());
@@ -348,7 +355,7 @@ BOOST_AUTO_TEST_CASE(mixed_redundancy_group_registration_unregsitration)
348355
Dependency::Ptr depDA(CreateDependency(depCA->GetParent(), childHostD, "depDA"));
349356
RegisterDependency(depDA, "redundant");
350357
AssertCheckableRedundancyGroup(childHostD, 1, 1, 2);
351-
BOOST_TEST(childHostC->GetDependencyGroups() == childHostD->GetDependencyGroups(), boost::test_tools::per_element());
358+
BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
352359
BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());
353360

354361
Dependency::Ptr depCB(CreateDependency(CreateHost("B"), childHostC, "depCB"));
@@ -361,7 +368,7 @@ BOOST_AUTO_TEST_CASE(mixed_redundancy_group_registration_unregsitration)
361368
RegisterDependency(depDB, "redundant");
362369
AssertCheckableRedundancyGroup(childHostC, 2, 1, 4);
363370
AssertCheckableRedundancyGroup(childHostD, 2, 1, 4);
364-
BOOST_TEST(childHostC->GetDependencyGroups() == childHostD->GetDependencyGroups(), boost::test_tools::per_element());
371+
BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
365372
BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());
366373

367374
Checkable::Ptr childHostE(CreateHost("childE"));
@@ -376,23 +383,23 @@ BOOST_AUTO_TEST_CASE(mixed_redundancy_group_registration_unregsitration)
376383
AssertCheckableRedundancyGroup(childHostC, 2, 1, 6);
377384
AssertCheckableRedundancyGroup(childHostD, 2, 1, 6);
378385
AssertCheckableRedundancyGroup(childHostE, 2, 1, 6);
379-
auto childHostCGroups(childHostC->GetDependencyGroups());
380-
BOOST_TEST((childHostCGroups == childHostD->GetDependencyGroups() && childHostCGroups == childHostE->GetDependencyGroups()));
386+
auto childHostCGroups(ExtractGroups(childHostC));
387+
BOOST_TEST((childHostCGroups == ExtractGroups(childHostD) && childHostCGroups == ExtractGroups(childHostE)));
381388
BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());
382389

383390
Dependency::Ptr depEZ(CreateDependency(CreateHost("Z"), childHostE, "depEZ"));
384391
RegisterDependency(depEZ, "redundant");
385392
// Child host E should have a new redundancy group with 3 members and the other two should still share the same group.
386393
AssertCheckableRedundancyGroup(childHostC, 2, 1, 4);
387394
AssertCheckableRedundancyGroup(childHostD, 2, 1, 4);
388-
BOOST_TEST(childHostC->GetDependencyGroups() == childHostD->GetDependencyGroups(), boost::test_tools::per_element());
395+
BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
389396
AssertCheckableRedundancyGroup(childHostE, 3, 1, 3);
390397
BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());
391398

392399
childHostE->RemoveDependency(depEA);
393400
AssertCheckableRedundancyGroup(childHostC, 2, 1, 4);
394401
AssertCheckableRedundancyGroup(childHostD, 2, 1, 4);
395-
BOOST_TEST(childHostC->GetDependencyGroups() == childHostD->GetDependencyGroups(), boost::test_tools::per_element());
402+
BOOST_TEST(ExtractGroups(childHostC) == ExtractGroups(childHostD), boost::test_tools::per_element());
396403
AssertCheckableRedundancyGroup(childHostE, 2, 1, 2);
397404
BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());
398405

@@ -402,8 +409,8 @@ BOOST_AUTO_TEST_CASE(mixed_redundancy_group_registration_unregsitration)
402409
AssertCheckableRedundancyGroup(childHostC, 2, 1, 6);
403410
AssertCheckableRedundancyGroup(childHostD, 2, 1, 6);
404411
AssertCheckableRedundancyGroup(childHostE, 2, 1, 6);
405-
childHostCGroups = childHostC->GetDependencyGroups();
406-
BOOST_TEST((childHostCGroups == childHostD->GetDependencyGroups() && childHostCGroups == childHostE->GetDependencyGroups()));
412+
childHostCGroups = ExtractGroups(childHostC);
413+
BOOST_TEST((childHostCGroups == ExtractGroups(childHostD) && childHostCGroups == ExtractGroups(childHostE)));
407414
BOOST_CHECK_EQUAL(1, DependencyGroup::GetRegistrySize());
408415

409416
childHostC->RemoveDependency(depCA);
@@ -413,7 +420,7 @@ BOOST_AUTO_TEST_CASE(mixed_redundancy_group_registration_unregsitration)
413420
AssertCheckableRedundancyGroup(childHostC, 1, 1, 1);
414421
AssertCheckableRedundancyGroup(childHostD, 1, 1, 2);
415422
AssertCheckableRedundancyGroup(childHostE, 1, 1, 2);
416-
BOOST_TEST(childHostD->GetDependencyGroups() == childHostE->GetDependencyGroups(), boost::test_tools::per_element());
423+
BOOST_TEST(ExtractGroups(childHostD) == ExtractGroups(childHostE), boost::test_tools::per_element());
417424
BOOST_CHECK_EQUAL(2, DependencyGroup::GetRegistrySize());
418425

419426
childHostC->RemoveDependency(depCB);

0 commit comments

Comments
 (0)