Test: Add test cases for static DNS processing
Fixes openbmc/openbmc#2107
Change-Id: Id6810be3527e4861430077364a5af4dc00e52f3b
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/test/test_ethernet_interface.cpp b/test/test_ethernet_interface.cpp
index edc12fb..27fbb67 100644
--- a/test/test_ethernet_interface.cpp
+++ b/test/test_ethernet_interface.cpp
@@ -104,6 +104,27 @@
}
+ // Validates if the DNS entries have been correctly processed
+ void validateResolvFile(ServerList values)
+ {
+ // Check whether the entries has been written to resolv.conf
+ fs::path resolvFile = confDir;
+ resolvFile /= "resolv.conf";
+
+ // Passed in "value" is what is read from the config file
+ interface.writeDNSEntries(values, resolvFile);
+ std::string expectedServers = "### Generated manually via dbus settings ###";
+ expectedServers +=
+ "nameserver 9.1.1.1nameserver 9.2.2.2nameserver 9.3.3.3";
+
+ std::string actualServers{};
+ std::fstream stream(resolvFile.string().c_str(), std::fstream::in);
+ for (std::string line; std::getline(stream, line);)
+ {
+ actualServers += line;
+ }
+ EXPECT_EQ(expectedServers , actualServers);
+ }
};
TEST_F(TestEthernetInterface, NoIPaddress)
@@ -169,6 +190,19 @@
gateway));
}
+TEST_F(TestEthernetInterface, addNameServers)
+{
+ ServerList servers = {"9.1.1.1","9.2.2.2","9.3.3.3"};
+ interface.nameservers(servers);
+ fs::path filePath = confDir;
+ filePath /= "00-bmc-test0.network";
+ config::Parser parser(filePath.string());
+ auto values = parser.getValues("Network", "DNS");
+ EXPECT_EQ(servers , values);
+
+ validateResolvFile(values);
+}
+
TEST_F(TestEthernetInterface, addNTPServers)
{
ServerList servers = {"10.1.1.1","10.2.2.2","10.3.3.3"};