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:
18     sdbusplus::bus_t bus;
19     HypNetworkMgr manager;
20     MockHypSysConfig sysConfigObj;
TestHypSysConfig()21     TestHypSysConfig() :
22         bus(sdbusplus::bus::new_default()),
23         manager(bus, "/xyz/openbmc_test/network/hypervisor"),
24         sysConfigObj(bus, "/xyz/openbmc_test/network/hypervisor/config",
25                      manager)
26     {
27         manager.setDefaultHostnameInBIOSTableAttrs();
28     }
29 
30     ~TestHypSysConfig() = default;
31 };
32 
TEST_F(TestHypSysConfig,setAndGetHostName)33 TEST_F(TestHypSysConfig, setAndGetHostName)
34 {
35     std::string newHostName = "hostname1";
36     sysConfigObj.setHostname(newHostName);
37 
38     biosTableType biosAttrs = manager.getBIOSTableAttrs();
39     auto itr = biosAttrs.find("vmi_hostname");
40     if (itr != biosAttrs.end())
41     {
42         std::string biosAttrValue = std::get<std::string>(itr->second);
43         EXPECT_EQ(biosAttrValue, "hostname1");
44     }
45 
46     std::string updatedHostName = sysConfigObj.getHostname();
47     EXPECT_EQ(updatedHostName, newHostName);
48 }
49 
50 } // namespace network
51 } // namespace phosphor
52