Add function to find assocs based on endpoint
The helper function findAssociations can find all
associations based on an endpoint path and return
enough information to recreate those associations
later.
For example, searching for something like "endpointA"
could return:
owner: "ownerA"
Association{"typeA", "typeB", "endpointB"}
Which implies the association:
endpointA/typeA -> endpointB/typeB
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I0fbcf5397435f10b3072dd2640b342ee47d52f9b
diff --git a/src/test/associations.cpp b/src/test/associations.cpp
index dee991d..7ac2e79 100644
--- a/src/test/associations.cpp
+++ b/src/test/associations.cpp
@@ -471,3 +471,49 @@
EXPECT_EQ(assocMaps.owners.size(), 1);
EXPECT_EQ(assocMaps.ifaces.size(), 2);
}
+
+TEST_F(TestAssociations, findAssociations)
+{
+ std::vector<std::tuple<std::string, Association>> associationData;
+ AssociationMaps assocMaps;
+
+ assocMaps.owners = {
+ {"pathA",
+ {{"ownerA",
+ {{"pathA/typeA", {"endpointA", "endpointB"}},
+ {"endpointA/type0", {"pathA"}}}}}},
+
+ {"pathJ",
+ {{"ownerC",
+ {{"pathJ/typeA", {"endpointF"}}, {"endpointF/type0", {"pathJ"}}}}}},
+
+ {"pathX",
+ {{"ownerB",
+ {{"pathX/typeB", {"endpointA"}}, {"endpointA/type1", {"pathX"}}}}}}};
+
+ findAssociations("endpointA", assocMaps, associationData);
+ ASSERT_EQ(associationData.size(), 2);
+
+ {
+ auto ad = std::find_if(
+ associationData.begin(), associationData.end(),
+ [](const auto& ad) { return std::get<0>(ad) == "ownerA"; });
+ ASSERT_NE(ad, associationData.end());
+
+ auto& a = std::get<1>(*ad);
+ ASSERT_EQ(std::get<0>(a), "type0");
+ ASSERT_EQ(std::get<1>(a), "typeA");
+ ASSERT_EQ(std::get<2>(a), "pathA");
+ }
+ {
+ auto ad = std::find_if(
+ associationData.begin(), associationData.end(),
+ [](const auto& ad) { return std::get<0>(ad) == "ownerB"; });
+ ASSERT_NE(ad, associationData.end());
+
+ auto& a = std::get<1>(*ad);
+ ASSERT_EQ(std::get<0>(a), "type1");
+ ASSERT_EQ(std::get<1>(a), "typeB");
+ ASSERT_EQ(std::get<2>(a), "pathX");
+ }
+}