]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
test-misc_hh: Add test for getCarbonHostname 9368/head
authorAki Tuomi <cmouse@cmouse.fi>
Tue, 21 Jul 2020 19:04:56 +0000 (22:04 +0300)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 31 Jul 2020 08:25:52 +0000 (10:25 +0200)
(cherry picked from commit f19c0ed44619382b41119c8fb3136a3eb11790b8)

pdns/test-misc_hh.cc

index 081661afc3c752b419cb2dc3abcf0324a88b6a1a..1742e109b7cadc04771ec5f81617103441f5e362 100644 (file)
@@ -176,5 +176,24 @@ BOOST_AUTO_TEST_CASE(test_SimpleMatch) {
   BOOST_CHECK_EQUAL(SimpleMatch("abc*").match(std::string("abc")), true);
 }
 
+BOOST_AUTO_TEST_CASE(test_getCarbonHostName)
+{
+  char buffer[4096];
+
+  BOOST_CHECK_EQUAL(gethostname(buffer, sizeof buffer), 0);
+  std::string my_hostname(buffer);
+  auto pos = my_hostname.find(".");
+  if (pos != std::string::npos) {
+    my_hostname.resize(pos);
+  }
+
+  boost::replace_all(my_hostname, ".", "_");
+
+  std::string hostname = getCarbonHostName();
+  // ensure it matches what we get
+  BOOST_CHECK_EQUAL(my_hostname, hostname);
+  BOOST_CHECK_EQUAL(my_hostname.size(), hostname.size());
+}
+
 BOOST_AUTO_TEST_SUITE_END()