diff options
Diffstat (limited to 'test/test_dns_updater.cpp')
-rw-r--r-- | test/test_dns_updater.cpp | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/test/test_dns_updater.cpp b/test/test_dns_updater.cpp index 8697d4c..2a425c0 100644 --- a/test/test_dns_updater.cpp +++ b/test/test_dns_updater.cpp @@ -1,13 +1,14 @@ #include "dns_updater.hpp" -#include <gtest/gtest.h> - -#include <fstream> #include <experimental/filesystem> +#include <fstream> + +#include <gtest/gtest.h> static constexpr auto IN_FILE = "/tmp/" __BASE_FILE__ "netif_state"; static constexpr auto OUT_FILE = "/tmp/" __BASE_FILE__ "resolv.conf"; -static constexpr auto COMPARE_FILE = "/tmp/" __BASE_FILE__ "resolv_compare.conf"; +static constexpr auto COMPARE_FILE = + "/tmp/" __BASE_FILE__ "resolv_compare.conf"; static constexpr auto DNS_ENTRY_1 = "DNS=1.2.3.4\n"; static constexpr auto DNS_ENTRY_2 = "DNS=5.6.7.8\n"; @@ -15,38 +16,38 @@ namespace fs = std::experimental::filesystem; class DnsUpdateTest : public ::testing::Test { - public: - // Gets called as part of each TEST_F construction - DnsUpdateTest() - { - // Create a file containing DNS entries like in netif/state - std::ofstream file(IN_FILE); - file << DNS_ENTRY_1; - file << DNS_ENTRY_2; + public: + // Gets called as part of each TEST_F construction + DnsUpdateTest() + { + // Create a file containing DNS entries like in netif/state + std::ofstream file(IN_FILE); + file << DNS_ENTRY_1; + file << DNS_ENTRY_2; - // Create a file to compare the results against - std::ofstream compare(COMPARE_FILE); - compare << "### Generated by phosphor-networkd ###\n"; - compare << "nameserver 1.2.3.4\n"; - compare << "nameserver 5.6.7.8\n"; - } + // Create a file to compare the results against + std::ofstream compare(COMPARE_FILE); + compare << "### Generated by phosphor-networkd ###\n"; + compare << "nameserver 1.2.3.4\n"; + compare << "nameserver 5.6.7.8\n"; + } - // Gets called as part of each TEST_F destruction - ~DnsUpdateTest() + // Gets called as part of each TEST_F destruction + ~DnsUpdateTest() + { + if (fs::exists(IN_FILE)) + { + fs::remove(IN_FILE); + } + if (fs::exists(OUT_FILE)) + { + fs::remove(OUT_FILE); + } + if (fs::exists(COMPARE_FILE)) { - if (fs::exists(IN_FILE)) - { - fs::remove(IN_FILE); - } - if (fs::exists(OUT_FILE)) - { - fs::remove(OUT_FILE); - } - if (fs::exists(COMPARE_FILE)) - { - fs::remove(COMPARE_FILE); - } + fs::remove(COMPARE_FILE); } + } }; /** @brief Makes outfile is updated with right contents |