Asmitha Karunanithi | eb40f08 | 2021-07-22 06:13:04 -0500 | [diff] [blame] | 1 | #include "mock_hyp_sys_config.hpp" |
| 2 | |
| 3 | #include <net/if.h> |
| 4 | |
| 5 | #include <sdbusplus/bus.hpp> |
| 6 | #include <xyz/openbmc_project/Common/error.hpp> |
| 7 | |
| 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | namespace phosphor |
| 11 | { |
| 12 | namespace network |
| 13 | { |
| 14 | |
| 15 | class TestHypSysConfig : public testing::Test |
| 16 | { |
| 17 | public: |
Patrick Williams | c38b071 | 2022-07-22 19:26:54 -0500 | [diff] [blame^] | 18 | sdbusplus::bus_t bus; |
Asmitha Karunanithi | eb40f08 | 2021-07-22 06:13:04 -0500 | [diff] [blame] | 19 | HypNetworkMgr manager; |
| 20 | MockHypSysConfig sysConfigObj; |
| 21 | sdeventplus::Event event = sdeventplus::Event::get_default(); |
| 22 | TestHypSysConfig() : |
| 23 | bus(sdbusplus::bus::new_default()), |
| 24 | manager(bus, event, "/xyz/openbmc_test/network/hypervisor"), |
| 25 | sysConfigObj(bus, "/xyz/openbmc_test/network/hypervisor/config", |
| 26 | manager) |
| 27 | { |
| 28 | manager.setDefaultHostnameInBIOSTableAttrs(); |
| 29 | } |
| 30 | |
| 31 | ~TestHypSysConfig() = default; |
| 32 | }; |
| 33 | |
| 34 | TEST_F(TestHypSysConfig, setAndGetHostName) |
| 35 | { |
| 36 | std::string newHostName = "hostname1"; |
| 37 | sysConfigObj.setHostname(newHostName); |
| 38 | |
| 39 | biosTableType biosAttrs = manager.getBIOSTableAttrs(); |
| 40 | auto itr = biosAttrs.find("vmi_hostname"); |
| 41 | if (itr != biosAttrs.end()) |
| 42 | { |
| 43 | std::string biosAttrValue = std::get<std::string>(itr->second); |
| 44 | EXPECT_EQ(biosAttrValue, "hostname1"); |
| 45 | } |
| 46 | |
| 47 | std::string updatedHostName = sysConfigObj.getHostname(); |
| 48 | EXPECT_EQ(updatedHostName, newHostName); |
| 49 | } |
| 50 | |
| 51 | } // namespace network |
| 52 | } // namespace phosphor |