blob: cd491a526724b8cf1de2d1d5b6d69ad3f6c19413 [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"};
33 boost::container::flat_set<std::string> assocInterfacesSet = {
Matt Spinler8f876a52019-04-15 13:22:50 -050034 assocDefsInterface};
Andrew Geissler20679262019-02-11 20:20:40 -060035
36 // Build up these objects so that an associated interface will match
37 // with the associated owner being removed
Matt Spinlere2359fb2019-04-05 14:11:33 -050038 AssociationMaps assocMaps;
39 assocMaps.owners = createDefaultOwnerAssociation();
40 assocMaps.ifaces = createDefaultInterfaceAssociation(server);
Brad Bishopa098a372022-05-05 15:19:04 -040041 auto interfaceMap = createInterfaceMap(defaultSourcePath, defaultDbusSvc,
42 assocInterfacesSet);
Andrew Geissler20679262019-02-11 20:20:40 -060043
Brad Bishopa098a372022-05-05 15:19:04 -040044 processNameChangeDelete(nameOwners, defaultDbusSvc, oldOwner, interfaceMap,
45 assocMaps, *server);
Andrew Geissler20679262019-02-11 20:20:40 -060046 EXPECT_EQ(nameOwners.size(), 0);
47
48 // Verify owner association was deleted
Matt Spinlere2359fb2019-04-05 14:11:33 -050049 EXPECT_TRUE(assocMaps.owners.empty());
Andrew Geissler20679262019-02-11 20:20:40 -060050
51 // Verify endpoint was deleted from interface association
52 auto intfEndpoints =
Brad Bishopa098a372022-05-05 15:19:04 -040053 std::get<endpointsPos>(assocMaps.ifaces[defaultFwdPath]);
Andrew Geissler20679262019-02-11 20:20:40 -060054 EXPECT_EQ(intfEndpoints.size(), 0);
Brad Bishopa098a372022-05-05 15:19:04 -040055 intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[defaultRevPath]);
Andrew Geissler20679262019-02-11 20:20:40 -060056 EXPECT_EQ(intfEndpoints.size(), 0);
57
58 // Verify interface map was deleted
59 EXPECT_TRUE(interfaceMap.empty());
60}