blob: 2730c67bf3ec7fa9b1a06a7e7915991bad377b7a [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
Kallas, Pawel5b4357d2022-10-12 15:36:37 +02008{
9 public:
10 boost::asio::io_context io;
11 virtual void SetUp()
12 {
13 io.run();
14 }
15};
Andrew Geissler20679262019-02-11 20:20:40 -060016sdbusplus::asio::object_server* TestNameChange::AsioServerClassTest::server =
17 nullptr;
18
19// Verify unique name is removed from nameOwners
20TEST_F(TestNameChange, UniqueNameNoInterfaces)
21{
22 boost::container::flat_map<std::string, std::string> nameOwners = {
23 {":1.99", "test-name"}};
24 std::string wellKnown = {"test-name"};
25 std::string oldOwner = {":1.99"};
Brad Bishopa098a372022-05-05 15:19:04 -040026 InterfaceMapType interfaceMap;
Matt Spinlere2359fb2019-04-05 14:11:33 -050027 AssociationMaps assocMaps;
Andrew Geissler20679262019-02-11 20:20:40 -060028
Kallas, Pawel5b4357d2022-10-12 15:36:37 +020029 processNameChangeDelete(io, nameOwners, wellKnown, oldOwner, interfaceMap,
Matt Spinlere2359fb2019-04-05 14:11:33 -050030 assocMaps, *server);
Andrew Geissler20679262019-02-11 20:20:40 -060031 EXPECT_EQ(nameOwners.size(), 0);
32}
33
34// Verify path removed from interface map and association objects
35TEST_F(TestNameChange, UniqueNameAssociationsAndInterface)
36{
37 boost::container::flat_map<std::string, std::string> nameOwners = {
Brad Bishopa098a372022-05-05 15:19:04 -040038 {":1.99", defaultDbusSvc}};
Andrew Geissler20679262019-02-11 20:20:40 -060039 std::string oldOwner = {":1.99"};
Ed Tanous964681c2022-07-08 12:47:24 -070040 InterfaceNames assocInterfacesSet = {assocDefsInterface};
Andrew Geissler20679262019-02-11 20:20:40 -060041
42 // Build up these objects so that an associated interface will match
43 // with the associated owner being removed
Matt Spinlere2359fb2019-04-05 14:11:33 -050044 AssociationMaps assocMaps;
45 assocMaps.owners = createDefaultOwnerAssociation();
46 assocMaps.ifaces = createDefaultInterfaceAssociation(server);
Brad Bishopa098a372022-05-05 15:19:04 -040047 auto interfaceMap = createInterfaceMap(defaultSourcePath, defaultDbusSvc,
48 assocInterfacesSet);
Andrew Geissler20679262019-02-11 20:20:40 -060049
Kallas, Pawel5b4357d2022-10-12 15:36:37 +020050 processNameChangeDelete(io, nameOwners, defaultDbusSvc, oldOwner,
51 interfaceMap, assocMaps, *server);
Andrew Geissler20679262019-02-11 20:20:40 -060052 EXPECT_EQ(nameOwners.size(), 0);
53
54 // Verify owner association was deleted
Matt Spinlere2359fb2019-04-05 14:11:33 -050055 EXPECT_TRUE(assocMaps.owners.empty());
Andrew Geissler20679262019-02-11 20:20:40 -060056
57 // Verify endpoint was deleted from interface association
58 auto intfEndpoints =
Brad Bishopa098a372022-05-05 15:19:04 -040059 std::get<endpointsPos>(assocMaps.ifaces[defaultFwdPath]);
Andrew Geissler20679262019-02-11 20:20:40 -060060 EXPECT_EQ(intfEndpoints.size(), 0);
Brad Bishopa098a372022-05-05 15:19:04 -040061 intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[defaultRevPath]);
Andrew Geissler20679262019-02-11 20:20:40 -060062 EXPECT_EQ(intfEndpoints.size(), 0);
63
64 // Verify interface map was deleted
65 EXPECT_TRUE(interfaceMap.empty());
66}