Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 1 | #include "src/associations.hpp" |
| 2 | |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 3 | #include "src/test/util/asio_server_class.hpp" |
Andrew Geissler | bb7b592 | 2019-02-08 14:16:48 -0600 | [diff] [blame] | 4 | #include "src/test/util/association_objects.hpp" |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 5 | #include "src/test/util/debug_output.hpp" |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 6 | |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 7 | #include <sdbusplus/asio/connection.hpp> |
| 8 | #include <sdbusplus/asio/object_server.hpp> |
| 9 | |
| 10 | #include <gtest/gtest.h> |
| 11 | |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 12 | class TestAssociations : public AsioServerClassTest |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 13 | { |
| 14 | public: |
| 15 | boost::asio::io_context io; |
| 16 | virtual void SetUp() |
| 17 | { |
| 18 | io.run(); |
| 19 | } |
| 20 | }; |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 21 | sdbusplus::asio::object_server* TestAssociations::AsioServerClassTest::server = |
| 22 | nullptr; |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 23 | |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 24 | // Verify call when path is not in associated owners |
| 25 | TEST_F(TestAssociations, SourcePathNotInAssociations) |
| 26 | { |
| 27 | EXPECT_NE(nullptr, server); |
| 28 | std::string sourcePath = "/xyz/openbmc_project/no/association"; |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 29 | AssociationMaps assocMaps; |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 30 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 31 | removeAssociation(io, sourcePath, defaultDbusSvc, *server, assocMaps); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | // Verify call when owner is not in associated owners |
| 35 | TEST_F(TestAssociations, OwnerNotInAssociations) |
| 36 | { |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 37 | AssociationMaps assocMaps; |
| 38 | assocMaps.owners = createDefaultOwnerAssociation(); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 39 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 40 | removeAssociation(io, defaultSourcePath, defaultDbusSvc, *server, |
| 41 | assocMaps); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | // Verify call when path is not in associated interfaces |
| 45 | TEST_F(TestAssociations, PathNotInAssocInterfaces) |
| 46 | { |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 47 | AssociationMaps assocMaps; |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 48 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 49 | assocMaps.owners = createDefaultOwnerAssociation(); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 50 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 51 | removeAssociation(io, defaultSourcePath, defaultDbusSvc, *server, |
| 52 | assocMaps); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 53 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 54 | EXPECT_TRUE(assocMaps.owners.empty()); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | // Verify call when path is in associated interfaces |
| 58 | TEST_F(TestAssociations, PathIsInAssociatedInterfaces) |
| 59 | { |
| 60 | // Build up these objects so that an associated interface will match |
| 61 | // with the associated owner being removed |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 62 | AssociationMaps assocMaps; |
| 63 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 64 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 65 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 66 | removeAssociation(io, defaultSourcePath, defaultDbusSvc, *server, |
| 67 | assocMaps); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 68 | |
| 69 | // Verify owner association was deleted |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 70 | EXPECT_TRUE(assocMaps.owners.empty()); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 71 | |
| 72 | // Verify endpoint was deleted from interface association |
| 73 | auto intfEndpoints = |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 74 | std::get<endpointsPos>(assocMaps.ifaces[defaultFwdPath]); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 75 | EXPECT_EQ(intfEndpoints.size(), 0); |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 76 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[defaultRevPath]); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 77 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 78 | } |
| 79 | |
| 80 | // Verify call when path is in associated interfaces, with extra endpoints |
| 81 | TEST_F(TestAssociations, PathIsInAssociatedInterfacesExtraEndpoints) |
| 82 | { |
| 83 | // Build up these objects so that an associated interface will match |
| 84 | // with the associated owner being removed |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 85 | AssociationMaps assocMaps; |
| 86 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 87 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 88 | |
| 89 | // Add another endpoint to the assoc interfaces |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 90 | addEndpointToInterfaceAssociation(assocMaps.ifaces); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 91 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 92 | removeAssociation(io, defaultSourcePath, defaultDbusSvc, *server, |
| 93 | assocMaps); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 94 | |
| 95 | // Verify owner association was deleted |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 96 | EXPECT_TRUE(assocMaps.owners.empty()); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 97 | |
| 98 | // Verify all endpoints are deleted since source path was deleted |
| 99 | auto intfEndpoints = |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 100 | std::get<endpointsPos>(assocMaps.ifaces[defaultFwdPath]); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 101 | EXPECT_EQ(intfEndpoints.size(), 0); |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 102 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[defaultRevPath]); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 103 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 104 | } |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 105 | |
| 106 | // Verify no associations or endpoints removed when the change is identical |
| 107 | TEST_F(TestAssociations, checkAssociationEndpointRemovesNoEpRemove) |
| 108 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 109 | AssociationPaths newAssocPaths = {{defaultFwdPath, {defaultEndpoint}}, |
| 110 | {defaultRevPath, {defaultSourcePath}}}; |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 111 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 112 | AssociationMaps assocMaps; |
| 113 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 114 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 115 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 116 | checkAssociationEndpointRemoves(io, defaultSourcePath, defaultDbusSvc, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 117 | newAssocPaths, *server, assocMaps); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 118 | |
| 119 | // Verify endpoints were not deleted because they matche with what was |
| 120 | // in the original |
| 121 | auto intfEndpoints = |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 122 | std::get<endpointsPos>(assocMaps.ifaces[defaultFwdPath]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 123 | EXPECT_EQ(intfEndpoints.size(), 1); |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 124 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[defaultRevPath]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 125 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 126 | } |
| 127 | |
| 128 | // Verify endpoint is removed when assoc path is different |
| 129 | TEST_F(TestAssociations, checkAssociationEndpointRemovesEpRemoveApDiff) |
| 130 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 131 | AssociationPaths newAssocPaths = {{"/different/path", {defaultEndpoint}}}; |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 132 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 133 | AssociationMaps assocMaps; |
| 134 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 135 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 136 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 137 | checkAssociationEndpointRemoves(io, defaultSourcePath, defaultDbusSvc, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 138 | newAssocPaths, *server, assocMaps); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 139 | |
| 140 | // Verify initial endpoints were deleted because the new path |
| 141 | auto intfEndpoints = |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 142 | std::get<endpointsPos>(assocMaps.ifaces[defaultFwdPath]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 143 | EXPECT_EQ(intfEndpoints.size(), 0); |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 144 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[defaultRevPath]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 145 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 146 | } |
| 147 | |
| 148 | // Verify endpoint is removed when endpoint is different |
| 149 | TEST_F(TestAssociations, checkAssociationEndpointRemovesEpRemoveEpChanged) |
| 150 | { |
| 151 | AssociationPaths newAssocPaths = { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 152 | {defaultFwdPath, {defaultEndpoint + "/different"}}, |
| 153 | {defaultRevPath, {defaultSourcePath + "/different"}}}; |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 154 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 155 | AssociationMaps assocMaps; |
| 156 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 157 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 158 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 159 | checkAssociationEndpointRemoves(io, defaultSourcePath, defaultDbusSvc, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 160 | newAssocPaths, *server, assocMaps); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 161 | |
| 162 | // Verify initial endpoints were deleted because of different endpoints |
| 163 | auto intfEndpoints = |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 164 | std::get<endpointsPos>(assocMaps.ifaces[defaultFwdPath]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 165 | EXPECT_EQ(intfEndpoints.size(), 0); |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 166 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[defaultRevPath]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 167 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 168 | } |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 169 | |
| 170 | // Verify existing endpoint deleted when empty endpoint is provided |
| 171 | TEST_F(TestAssociations, associationChangedEmptyEndpoint) |
| 172 | { |
Andrew Geissler | eecc196 | 2020-06-10 19:58:35 -0500 | [diff] [blame] | 173 | std::vector<Association> associations = { |
| 174 | {"inventory_cee", "error_cee", ""}}; |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 175 | InterfaceMapType interfaceMap; |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 176 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 177 | AssociationMaps assocMaps; |
| 178 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 179 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 180 | |
| 181 | // Empty endpoint will result in deletion of corresponding assocInterface |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 182 | associationChanged(io, *server, associations, defaultSourcePath, |
| 183 | defaultDbusSvc, interfaceMap, assocMaps); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 184 | |
Andrew Geissler | 0a560a5 | 2019-03-22 10:59:07 -0500 | [diff] [blame] | 185 | // Both of these should be 0 since we have an invalid endpoint |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 186 | auto intfEndpoints = |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 187 | std::get<endpointsPos>(assocMaps.ifaces[defaultFwdPath]); |
Andrew Geissler | 0a560a5 | 2019-03-22 10:59:07 -0500 | [diff] [blame] | 188 | EXPECT_EQ(intfEndpoints.size(), 0); |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 189 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[defaultRevPath]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 190 | EXPECT_EQ(intfEndpoints.size(), 0); |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 191 | |
| 192 | EXPECT_EQ(assocMaps.pending.size(), 0); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | // Add a new association with endpoint |
| 196 | TEST_F(TestAssociations, associationChangedAddNewAssoc) |
| 197 | { |
| 198 | std::vector<Association> associations = { |
| 199 | {"abc", "def", "/xyz/openbmc_project/new/endpoint"}}; |
| 200 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 201 | AssociationMaps assocMaps; |
| 202 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 203 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 204 | |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 205 | // Make it look like the assoc endpoints are on D-Bus |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 206 | InterfaceMapType interfaceMap = { |
| 207 | {"/new/source/path", {{defaultDbusSvc, {"a"}}}}, |
| 208 | {"/xyz/openbmc_project/new/endpoint", {{defaultDbusSvc, {"a"}}}}}; |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 209 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 210 | associationChanged(io, *server, associations, "/new/source/path", |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 211 | defaultDbusSvc, interfaceMap, assocMaps); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 212 | |
| 213 | // Two source paths |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 214 | EXPECT_EQ(assocMaps.owners.size(), 2); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 215 | |
| 216 | // Four interfaces |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 217 | EXPECT_EQ(assocMaps.ifaces.size(), 4); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 218 | |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 219 | // Nothing pending |
| 220 | EXPECT_EQ(assocMaps.pending.size(), 0); |
| 221 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 222 | // New endpoint so assocMaps.ifaces should be same size |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 223 | auto intfEndpoints = |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 224 | std::get<endpointsPos>(assocMaps.ifaces[defaultFwdPath]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 225 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 226 | } |
| 227 | |
| 228 | // Add a new association to empty objects |
| 229 | TEST_F(TestAssociations, associationChangedAddNewAssocEmptyObj) |
| 230 | { |
| 231 | std::string sourcePath = "/logging/entry/1"; |
| 232 | std::string owner = "xyz.openbmc_project.Test"; |
| 233 | std::vector<Association> associations = { |
Andrew Geissler | eecc196 | 2020-06-10 19:58:35 -0500 | [diff] [blame] | 234 | {"inventory_canaeo", "error_canaeo", |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 235 | "/xyz/openbmc_project/inventory/system/chassis"}}; |
| 236 | |
| 237 | // Empty objects because this test will ensure assocOwners adds the |
| 238 | // changed association and interface |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 239 | AssociationMaps assocMaps; |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 240 | |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 241 | // Make it look like the assoc endpoints are on D-Bus |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 242 | InterfaceMapType interfaceMap = createDefaultInterfaceMap(); |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 243 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 244 | associationChanged(io, *server, associations, defaultSourcePath, |
| 245 | defaultDbusSvc, interfaceMap, assocMaps); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 246 | |
| 247 | // New associations so ensure it now contains a single entry |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 248 | EXPECT_EQ(assocMaps.owners.size(), 1); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 249 | |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 250 | // Nothing pending |
| 251 | EXPECT_EQ(assocMaps.pending.size(), 0); |
| 252 | |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 253 | // Verify corresponding assoc paths each have one endpoint in assoc |
| 254 | // interfaces and that those endpoints match |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 255 | auto singleOwner = assocMaps.owners[defaultSourcePath]; |
| 256 | auto singleIntf = singleOwner[defaultDbusSvc]; |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 257 | for (auto i : singleIntf) |
| 258 | { |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 259 | auto intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[i.first]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 260 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 261 | EXPECT_EQ(intfEndpoints[0], *i.second.begin()); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | // Add a new association to same source path but with new owner |
| 266 | TEST_F(TestAssociations, associationChangedAddNewAssocNewOwner) |
| 267 | { |
| 268 | std::string newOwner = "xyz.openbmc_project.Test2"; |
| 269 | std::vector<Association> associations = { |
Andrew Geissler | eecc196 | 2020-06-10 19:58:35 -0500 | [diff] [blame] | 270 | {"inventory_canano", "error_canano", |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 271 | "/xyz/openbmc_project/inventory/system/chassis"}}; |
| 272 | |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 273 | // Make it look like the assoc endpoints are on D-Bus |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 274 | InterfaceMapType interfaceMap = createDefaultInterfaceMap(); |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 275 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 276 | AssociationMaps assocMaps; |
| 277 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 278 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 279 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 280 | associationChanged(io, *server, associations, defaultSourcePath, newOwner, |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 281 | interfaceMap, assocMaps); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 282 | |
| 283 | // New endpoint so assocOwners should be same size |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 284 | EXPECT_EQ(assocMaps.owners.size(), 1); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 285 | |
| 286 | // Ensure only one endpoint under first path |
| 287 | auto intfEndpoints = |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 288 | std::get<endpointsPos>(assocMaps.ifaces[defaultFwdPath]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 289 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 290 | |
| 291 | // Ensure the 2 new association endpoints are under the new owner |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 292 | auto a = assocMaps.owners.find(defaultSourcePath); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 293 | auto o = a->second.find(newOwner); |
| 294 | EXPECT_EQ(o->second.size(), 2); |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 295 | |
| 296 | // Nothing pending |
| 297 | EXPECT_EQ(assocMaps.pending.size(), 0); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | // Add a new association to existing interface path |
| 301 | TEST_F(TestAssociations, associationChangedAddNewAssocSameInterface) |
| 302 | { |
| 303 | std::vector<Association> associations = { |
| 304 | {"abc", "error", "/xyz/openbmc_project/inventory/system/chassis"}}; |
| 305 | |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 306 | // Make it look like the assoc endpoints are on D-Bus |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 307 | InterfaceMapType interfaceMap = createDefaultInterfaceMap(); |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 308 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 309 | AssociationMaps assocMaps; |
| 310 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 311 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 312 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 313 | associationChanged(io, *server, associations, defaultSourcePath, |
| 314 | defaultDbusSvc, interfaceMap, assocMaps); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 315 | |
| 316 | // Should have 3 entries in AssociationInterfaces, one is just missing an |
| 317 | // endpoint |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 318 | EXPECT_EQ(assocMaps.ifaces.size(), 3); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 319 | |
| 320 | // Change to existing interface so it will be removed here |
| 321 | auto intfEndpoints = |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 322 | std::get<endpointsPos>(assocMaps.ifaces[defaultFwdPath]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 323 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 324 | |
| 325 | // The new endpoint should exist though in it's place |
| 326 | intfEndpoints = std::get<endpointsPos>( |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 327 | assocMaps.ifaces[defaultSourcePath + "/" + "abc"]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 328 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 329 | |
| 330 | // Added to an existing owner path so still 1 |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 331 | EXPECT_EQ(assocMaps.owners.size(), 1); |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 332 | |
| 333 | EXPECT_EQ(assocMaps.pending.size(), 0); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 334 | } |
Matt Spinler | 9f1adbc | 2019-04-08 10:47:19 -0500 | [diff] [blame] | 335 | |
| 336 | // Add 2 pending associations |
| 337 | TEST_F(TestAssociations, addPendingAssocs) |
| 338 | { |
| 339 | AssociationMaps assocMaps; |
| 340 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 341 | addPendingAssociation(defaultSourcePath, "inventory", defaultEndpoint, |
| 342 | "error", defaultDbusSvc, assocMaps); |
Matt Spinler | 9f1adbc | 2019-04-08 10:47:19 -0500 | [diff] [blame] | 343 | |
| 344 | EXPECT_TRUE(assocMaps.ifaces.empty()); |
| 345 | EXPECT_TRUE(assocMaps.owners.empty()); |
| 346 | |
| 347 | EXPECT_EQ(assocMaps.pending.size(), 1); |
| 348 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 349 | addPendingAssociation("some/other/path", "inventory", defaultEndpoint, |
| 350 | "error", defaultDbusSvc, assocMaps); |
Matt Spinler | 9f1adbc | 2019-04-08 10:47:19 -0500 | [diff] [blame] | 351 | |
| 352 | EXPECT_TRUE(assocMaps.ifaces.empty()); |
| 353 | EXPECT_TRUE(assocMaps.owners.empty()); |
| 354 | |
| 355 | EXPECT_EQ(assocMaps.pending.size(), 2); |
| 356 | } |
| 357 | |
| 358 | // Test adding a new endpoint to a pending association |
| 359 | TEST_F(TestAssociations, addPendingAssocsNewEndpoints) |
| 360 | { |
| 361 | AssociationMaps assocMaps; |
| 362 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 363 | addPendingAssociation(defaultSourcePath, "inventory", defaultEndpoint, |
| 364 | "error", defaultDbusSvc, assocMaps); |
Matt Spinler | 9f1adbc | 2019-04-08 10:47:19 -0500 | [diff] [blame] | 365 | |
| 366 | EXPECT_EQ(assocMaps.pending.size(), 1); |
| 367 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 368 | addPendingAssociation(defaultSourcePath, "inventory", "some/other/endpoint", |
| 369 | "error", defaultDbusSvc, assocMaps); |
Matt Spinler | 9f1adbc | 2019-04-08 10:47:19 -0500 | [diff] [blame] | 370 | |
| 371 | // Same pending path, so still just 1 entry |
| 372 | EXPECT_EQ(assocMaps.pending.size(), 1); |
| 373 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 374 | auto assoc = assocMaps.pending.find(defaultSourcePath); |
Matt Spinler | 9f1adbc | 2019-04-08 10:47:19 -0500 | [diff] [blame] | 375 | EXPECT_NE(assoc, assocMaps.pending.end()); |
| 376 | |
| 377 | auto& endpoints = assoc->second; |
| 378 | EXPECT_EQ(endpoints.size(), 2); |
| 379 | } |
| 380 | |
| 381 | // Test adding a new owner to a pending association |
| 382 | TEST_F(TestAssociations, addPendingAssocsNewOwner) |
| 383 | { |
| 384 | AssociationMaps assocMaps; |
| 385 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 386 | addPendingAssociation(defaultSourcePath, "inventory", defaultEndpoint, |
| 387 | "error", defaultDbusSvc, assocMaps); |
Matt Spinler | 9f1adbc | 2019-04-08 10:47:19 -0500 | [diff] [blame] | 388 | |
| 389 | EXPECT_EQ(assocMaps.pending.size(), 1); |
| 390 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 391 | addPendingAssociation(defaultSourcePath, "inventory", defaultEndpoint, |
Matt Spinler | 9f1adbc | 2019-04-08 10:47:19 -0500 | [diff] [blame] | 392 | "error", "new owner", assocMaps); |
| 393 | |
| 394 | EXPECT_EQ(assocMaps.pending.size(), 1); |
| 395 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 396 | auto assoc = assocMaps.pending.find(defaultSourcePath); |
Matt Spinler | 9f1adbc | 2019-04-08 10:47:19 -0500 | [diff] [blame] | 397 | EXPECT_NE(assoc, assocMaps.pending.end()); |
| 398 | |
| 399 | auto& endpoints = assoc->second; |
| 400 | EXPECT_EQ(endpoints.size(), 2); |
| 401 | } |
| 402 | |
| 403 | // Add a pending association inside associationChanged |
| 404 | TEST_F(TestAssociations, associationChangedPending) |
| 405 | { |
| 406 | std::vector<Association> associations = { |
| 407 | {"abc", "def", "/xyz/openbmc_project/new/endpoint"}}; |
| 408 | |
| 409 | AssociationMaps assocMaps; |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 410 | InterfaceMapType interfaceMap; |
Matt Spinler | 9f1adbc | 2019-04-08 10:47:19 -0500 | [diff] [blame] | 411 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 412 | associationChanged(io, *server, associations, "/new/source/path", |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 413 | defaultDbusSvc, interfaceMap, assocMaps); |
Matt Spinler | 9f1adbc | 2019-04-08 10:47:19 -0500 | [diff] [blame] | 414 | |
| 415 | // No associations were actually added |
| 416 | EXPECT_EQ(assocMaps.owners.size(), 0); |
| 417 | EXPECT_EQ(assocMaps.ifaces.size(), 0); |
| 418 | |
| 419 | // 1 pending association |
| 420 | EXPECT_EQ(assocMaps.pending.size(), 1); |
| 421 | } |
Matt Spinler | cb9bcdb | 2019-04-08 10:58:49 -0500 | [diff] [blame] | 422 | |
| 423 | // Test removing pending associations |
| 424 | TEST_F(TestAssociations, testRemoveFromPendingAssociations) |
| 425 | { |
| 426 | AssociationMaps assocMaps; |
| 427 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 428 | addPendingAssociation(defaultSourcePath, "inventory", defaultEndpoint, |
| 429 | "error", defaultDbusSvc, assocMaps); |
Matt Spinler | cb9bcdb | 2019-04-08 10:58:49 -0500 | [diff] [blame] | 430 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 431 | addPendingAssociation(defaultSourcePath, "inventory", "some/other/endpoint", |
| 432 | "error", defaultDbusSvc, assocMaps); |
Matt Spinler | cb9bcdb | 2019-04-08 10:58:49 -0500 | [diff] [blame] | 433 | |
| 434 | EXPECT_EQ(assocMaps.pending.size(), 1); |
| 435 | |
| 436 | removeFromPendingAssociations("some/other/endpoint", assocMaps); |
| 437 | |
| 438 | // Still 1 pending entry, but down to 1 endpoint |
| 439 | EXPECT_EQ(assocMaps.pending.size(), 1); |
| 440 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 441 | auto assoc = assocMaps.pending.find(defaultSourcePath); |
Matt Spinler | cb9bcdb | 2019-04-08 10:58:49 -0500 | [diff] [blame] | 442 | EXPECT_NE(assoc, assocMaps.pending.end()); |
| 443 | auto& endpoints = assoc->second; |
| 444 | EXPECT_EQ(endpoints.size(), 1); |
| 445 | |
| 446 | // Now nothing pending |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 447 | removeFromPendingAssociations(defaultEndpoint, assocMaps); |
Matt Spinler | cb9bcdb | 2019-04-08 10:58:49 -0500 | [diff] [blame] | 448 | EXPECT_EQ(assocMaps.pending.size(), 0); |
| 449 | } |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 450 | |
| 451 | // Test moving a pending association to a real one |
| 452 | TEST_F(TestAssociations, checkIfPending) |
| 453 | { |
| 454 | AssociationMaps assocMaps; |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 455 | InterfaceMapType interfaceMap = { |
| 456 | {defaultSourcePath, {{defaultDbusSvc, {"a"}}}}, |
| 457 | {defaultEndpoint, {{defaultDbusSvc, {"b"}}}}}; |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 458 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 459 | addPendingAssociation(defaultSourcePath, "inventory_cip", defaultEndpoint, |
| 460 | "error_cip", defaultDbusSvc, assocMaps); |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 461 | EXPECT_EQ(assocMaps.pending.size(), 1); |
| 462 | |
| 463 | // Move the pending association to a real association |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 464 | checkIfPendingAssociation(io, defaultSourcePath, interfaceMap, assocMaps, |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 465 | *server); |
| 466 | |
| 467 | EXPECT_TRUE(assocMaps.pending.empty()); |
| 468 | EXPECT_EQ(assocMaps.owners.size(), 1); |
| 469 | EXPECT_EQ(assocMaps.ifaces.size(), 2); |
| 470 | |
| 471 | // This shouldn't do anything, since /new/path isn't pending |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 472 | checkIfPendingAssociation(io, "/new/path", interfaceMap, assocMaps, |
| 473 | *server); |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 474 | EXPECT_TRUE(assocMaps.pending.empty()); |
| 475 | EXPECT_EQ(assocMaps.owners.size(), 1); |
| 476 | EXPECT_EQ(assocMaps.ifaces.size(), 2); |
| 477 | } |
Matt Spinler | 7f8fd1f | 2019-04-08 15:21:59 -0500 | [diff] [blame] | 478 | |
| 479 | TEST_F(TestAssociations, findAssociations) |
| 480 | { |
| 481 | std::vector<std::tuple<std::string, Association>> associationData; |
| 482 | AssociationMaps assocMaps; |
| 483 | |
| 484 | assocMaps.owners = { |
| 485 | {"pathA", |
| 486 | {{"ownerA", |
| 487 | {{"pathA/typeA", {"endpointA", "endpointB"}}, |
| 488 | {"endpointA/type0", {"pathA"}}}}}}, |
| 489 | |
| 490 | {"pathJ", |
| 491 | {{"ownerC", |
| 492 | {{"pathJ/typeA", {"endpointF"}}, {"endpointF/type0", {"pathJ"}}}}}}, |
| 493 | |
| 494 | {"pathX", |
| 495 | {{"ownerB", |
| 496 | {{"pathX/typeB", {"endpointA"}}, {"endpointA/type1", {"pathX"}}}}}}}; |
| 497 | |
| 498 | findAssociations("endpointA", assocMaps, associationData); |
| 499 | ASSERT_EQ(associationData.size(), 2); |
| 500 | |
| 501 | { |
Patrick Williams | 670edd1 | 2023-02-15 15:06:52 -0600 | [diff] [blame^] | 502 | auto ad = std::find_if(associationData.begin(), associationData.end(), |
| 503 | [](const auto& ad) { |
| 504 | return std::get<0>(ad) == "ownerA"; |
| 505 | }); |
Matt Spinler | 7f8fd1f | 2019-04-08 15:21:59 -0500 | [diff] [blame] | 506 | ASSERT_NE(ad, associationData.end()); |
| 507 | |
| 508 | auto& a = std::get<1>(*ad); |
| 509 | ASSERT_EQ(std::get<0>(a), "type0"); |
| 510 | ASSERT_EQ(std::get<1>(a), "typeA"); |
| 511 | ASSERT_EQ(std::get<2>(a), "pathA"); |
| 512 | } |
| 513 | { |
Patrick Williams | 670edd1 | 2023-02-15 15:06:52 -0600 | [diff] [blame^] | 514 | auto ad = std::find_if(associationData.begin(), associationData.end(), |
| 515 | [](const auto& ad) { |
| 516 | return std::get<0>(ad) == "ownerB"; |
| 517 | }); |
Matt Spinler | 7f8fd1f | 2019-04-08 15:21:59 -0500 | [diff] [blame] | 518 | ASSERT_NE(ad, associationData.end()); |
| 519 | |
| 520 | auto& a = std::get<1>(*ad); |
| 521 | ASSERT_EQ(std::get<0>(a), "type1"); |
| 522 | ASSERT_EQ(std::get<1>(a), "typeB"); |
| 523 | ASSERT_EQ(std::get<2>(a), "pathX"); |
| 524 | } |
| 525 | } |
Matt Spinler | 9c3d285 | 2019-04-08 15:57:19 -0500 | [diff] [blame] | 526 | |
| 527 | TEST_F(TestAssociations, moveAssocToPendingNoOp) |
| 528 | { |
| 529 | AssociationMaps assocMaps; |
| 530 | |
| 531 | // Not an association, so it shouldn't do anything |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 532 | moveAssociationToPending(io, defaultEndpoint, assocMaps, *server); |
Matt Spinler | 9c3d285 | 2019-04-08 15:57:19 -0500 | [diff] [blame] | 533 | |
| 534 | EXPECT_TRUE(assocMaps.pending.empty()); |
| 535 | EXPECT_TRUE(assocMaps.owners.empty()); |
| 536 | EXPECT_TRUE(assocMaps.ifaces.empty()); |
| 537 | } |
| 538 | |
| 539 | TEST_F(TestAssociations, moveAssocToPending) |
| 540 | { |
| 541 | AssociationMaps assocMaps; |
| 542 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 543 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
| 544 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 545 | moveAssociationToPending(io, defaultEndpoint, assocMaps, *server); |
Matt Spinler | 9c3d285 | 2019-04-08 15:57:19 -0500 | [diff] [blame] | 546 | |
| 547 | // Check it's now pending |
| 548 | EXPECT_EQ(assocMaps.pending.size(), 1); |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 549 | EXPECT_EQ(assocMaps.pending.begin()->first, defaultEndpoint); |
Matt Spinler | 9c3d285 | 2019-04-08 15:57:19 -0500 | [diff] [blame] | 550 | |
| 551 | // No more assoc owners |
| 552 | EXPECT_TRUE(assocMaps.owners.empty()); |
| 553 | |
| 554 | // Check the association interfaces were removed |
| 555 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 556 | auto assocs = assocMaps.ifaces.find(defaultFwdPath); |
Matt Spinler | 9c3d285 | 2019-04-08 15:57:19 -0500 | [diff] [blame] | 557 | auto& iface = std::get<ifacePos>(assocs->second); |
| 558 | auto& endpoints = std::get<endpointsPos>(assocs->second); |
| 559 | |
| 560 | EXPECT_EQ(iface.get(), nullptr); |
| 561 | EXPECT_TRUE(endpoints.empty()); |
| 562 | } |
| 563 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 564 | auto assocs = assocMaps.ifaces.find(defaultRevPath); |
Matt Spinler | 9c3d285 | 2019-04-08 15:57:19 -0500 | [diff] [blame] | 565 | auto& iface = std::get<ifacePos>(assocs->second); |
| 566 | auto& endpoints = std::get<endpointsPos>(assocs->second); |
| 567 | |
| 568 | EXPECT_EQ(iface.get(), nullptr); |
| 569 | EXPECT_TRUE(endpoints.empty()); |
| 570 | } |
| 571 | } |