blob: 860a387e0f6215f572389350b66a3d15daa789d3 [file] [log] [blame]
Andrew Geissler20679262019-02-11 20:20:40 -06001#include "src/processing.hpp"
2#include "src/test/util/asio_server_class.hpp"
3#include "src/test/util/association_objects.hpp"
4
5#include <gtest/gtest.h>
6
7class TestNameChange : public AsioServerClassTest
Brad Bishop23520882022-05-26 21:39:53 -04008{};
Andrew Geissler20679262019-02-11 20:20:40 -06009sdbusplus::asio::object_server* TestNameChange::AsioServerClassTest::server =
10 nullptr;
11
12// Verify unique name is removed from nameOwners
13TEST_F(TestNameChange, UniqueNameNoInterfaces)
14{
15 boost::container::flat_map<std::string, std::string> nameOwners = {
16 {":1.99", "test-name"}};
17 std::string wellKnown = {"test-name"};
18 std::string oldOwner = {":1.99"};
Brad Bishopa098a372022-05-05 15:19:04 -040019 InterfaceMapType interfaceMap;
Matt Spinlere2359fb2019-04-05 14:11:33 -050020 AssociationMaps assocMaps;
Andrew Geissler20679262019-02-11 20:20:40 -060021
22 processNameChangeDelete(nameOwners, wellKnown, oldOwner, interfaceMap,
Matt Spinlere2359fb2019-04-05 14:11:33 -050023 assocMaps, *server);
Andrew Geissler20679262019-02-11 20:20:40 -060024 EXPECT_EQ(nameOwners.size(), 0);
25}
26
27// Verify path removed from interface map and association objects
28TEST_F(TestNameChange, UniqueNameAssociationsAndInterface)
29{
30 boost::container::flat_map<std::string, std::string> nameOwners = {
Brad Bishopa098a372022-05-05 15:19:04 -040031 {":1.99", defaultDbusSvc}};
Andrew Geissler20679262019-02-11 20:20:40 -060032 std::string oldOwner = {":1.99"};
Ed Tanous964681c2022-07-08 12:47:24 -070033 InterfaceNames assocInterfacesSet = {assocDefsInterface};
Andrew Geissler20679262019-02-11 20:20:40 -060034
35 // Build up these objects so that an associated interface will match
36 // with the associated owner being removed
Matt Spinlere2359fb2019-04-05 14:11:33 -050037 AssociationMaps assocMaps;
38 assocMaps.owners = createDefaultOwnerAssociation();
39 assocMaps.ifaces = createDefaultInterfaceAssociation(server);
Brad Bishopa098a372022-05-05 15:19:04 -040040 auto interfaceMap = createInterfaceMap(defaultSourcePath, defaultDbusSvc,
41 assocInterfacesSet);
Andrew Geissler20679262019-02-11 20:20:40 -060042
Brad Bishopa098a372022-05-05 15:19:04 -040043 processNameChangeDelete(nameOwners, defaultDbusSvc, oldOwner, interfaceMap,
44 assocMaps, *server);
Andrew Geissler20679262019-02-11 20:20:40 -060045 EXPECT_EQ(nameOwners.size(), 0);
46
47 // Verify owner association was deleted
Matt Spinlere2359fb2019-04-05 14:11:33 -050048 EXPECT_TRUE(assocMaps.owners.empty());
Andrew Geissler20679262019-02-11 20:20:40 -060049
50 // Verify endpoint was deleted from interface association
51 auto intfEndpoints =
Brad Bishopa098a372022-05-05 15:19:04 -040052 std::get<endpointsPos>(assocMaps.ifaces[defaultFwdPath]);
Andrew Geissler20679262019-02-11 20:20:40 -060053 EXPECT_EQ(intfEndpoints.size(), 0);
Brad Bishopa098a372022-05-05 15:19:04 -040054 intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[defaultRevPath]);
Andrew Geissler20679262019-02-11 20:20:40 -060055 EXPECT_EQ(intfEndpoints.size(), 0);
56
57 // Verify interface map was deleted
58 EXPECT_TRUE(interfaceMap.empty());
59}