1 #include "hyp_network_manager.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 TestHypNetworkManager : public testing::Test
16 {
17   public:
18     sdbusplus::bus_t bus;
19     HypNetworkMgr manager;
20     sdeventplus::Event event = sdeventplus::Event::get_default();
21     TestHypNetworkManager() :
22         bus(sdbusplus::bus::new_default()),
23         manager(bus, event, "/xyz/openbmc_test/network/hypervisor")
24     {
25         // TODO: Once the support for ipv6 has been added, the below
26         // method call to set default values in the local copy
27         // of the bios attributes should be called for ipv6 as well
28 
29         manager.setDefaultBIOSTableAttrsOnIntf("if0");
30         manager.setDefaultBIOSTableAttrsOnIntf("if1");
31         manager.setDefaultHostnameInBIOSTableAttrs();
32     }
33 
34     ~TestHypNetworkManager() = default;
35 };
36 
37 TEST_F(TestHypNetworkManager, getDefaultBiosTableAttr)
38 {
39     biosTableType biosAttrs = manager.getBIOSTableAttrs();
40     auto itr = biosAttrs.find("vmi_if0_ipv4_method");
41     if (itr != biosAttrs.end())
42     {
43         std::string biosAttrValue = std::get<std::string>(itr->second);
44         EXPECT_EQ(biosAttrValue, "IPv4Static");
45     }
46 }
47 
48 TEST_F(TestHypNetworkManager, setHostnameInBiosTableAndGet)
49 {
50     std::string attribute = "vmi_hostname";
51     std::string value = "testHostname";
52     manager.setBIOSTableAttr(attribute, value, "String");
53     biosTableType biosAttrs = manager.getBIOSTableAttrs();
54     auto itr = biosAttrs.find("vmi_hostname");
55     if (itr != biosAttrs.end())
56     {
57         std::string biosAttrValue = std::get<std::string>(itr->second);
58         EXPECT_EQ(biosAttrValue, value);
59     }
60 }
61 
62 } // namespace network
63 } // namespace phosphor
64