ci: stop adding capabilities before running unit tests
This ensures that all tests pass (or are automatically skipped)
when run as an unprivileged user.
Change-Id: If8b66fd6555de455648576565b1c6cbd02695d1b
Refs: #3418
diff --git a/tests/daemon/mgmt/face-manager-process-config.t.cpp b/tests/daemon/mgmt/face-manager-process-config.t.cpp
index 16996b8..0ccc75c 100644
--- a/tests/daemon/mgmt/face-manager-process-config.t.cpp
+++ b/tests/daemon/mgmt/face-manager-process-config.t.cpp
@@ -58,7 +58,6 @@
ConfigFile m_config;
};
-
BOOST_FIXTURE_TEST_SUITE(ProcessConfig, FaceManagerProcessConfigFixture)
#ifdef HAVE_UNIX_SOCKETS
@@ -120,7 +119,6 @@
" listen hello\n"
" }\n"
"}\n";
-
BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
}
@@ -312,9 +310,8 @@
auto factory = dynamic_pointer_cast<UdpFactory>(m_manager.m_factories.find("udp")->second);
BOOST_REQUIRE(factory != nullptr);
- if (factory->getMulticastFaces().size() == 0) {
- BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
- "no UDP multicast faces are available");
+ if (factory->getMulticastFaces().empty()) {
+ BOOST_WARN_MESSAGE(false, "skipping assertions that require at least one UDP multicast face");
return;
}
@@ -335,6 +332,7 @@
BOOST_AUTO_TEST_CASE(ProcessSectionEther)
{
+ SKIP_IF_NOT_SUPERUSER();
const std::string CONFIG =
"face_system\n"
@@ -345,7 +343,6 @@
" mcast_group 01:00:5E:00:17:AA\n"
" }\n"
"}\n";
-
BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
}
@@ -395,6 +392,8 @@
BOOST_AUTO_TEST_CASE(ProcessSectionEtherMulticastReinit)
{
+ SKIP_IF_NOT_SUPERUSER();
+
const std::string CONFIG_WITH_MCAST =
"face_system\n"
"{\n"
@@ -409,9 +408,8 @@
auto factory = dynamic_pointer_cast<EthernetFactory>(m_manager.m_factories.find("ether")->second);
BOOST_REQUIRE(factory != nullptr);
- if (factory->getMulticastFaces().size() == 0) {
- BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
- "no Ethernet multicast faces are available");
+ if (factory->getMulticastFaces().empty()) {
+ BOOST_WARN_MESSAGE(false, "skipping assertions that require at least one Ethernet multicast face");
return;
}
diff --git a/tests/daemon/mgmt/general-config-section.t.cpp b/tests/daemon/mgmt/general-config-section.t.cpp
index d3af366..26e87ea 100644
--- a/tests/daemon/mgmt/general-config-section.t.cpp
+++ b/tests/daemon/mgmt/general-config-section.t.cpp
@@ -28,6 +28,8 @@
#include "tests/test-common.hpp"
+#include <cstring>
+
namespace nfd {
namespace general {
namespace tests {
@@ -37,17 +39,18 @@
class GeneralConfigSectionFixture : public BaseFixture
{
public:
+#ifdef HAVE_PRIVILEGE_DROP_AND_ELEVATE
~GeneralConfigSectionFixture()
{
-#ifdef HAVE_PRIVILEGE_DROP_AND_ELEVATE
// revert changes to s_normalUid/s_normalGid, if any
PrivilegeHelper::s_normalUid = ::geteuid();
PrivilegeHelper::s_normalGid = ::getegid();
-#endif // HAVE_PRIVILEGE_DROP_AND_ELEVATE
}
+#endif // HAVE_PRIVILEGE_DROP_AND_ELEVATE
};
-BOOST_FIXTURE_TEST_SUITE(MgmtGeneralConfigSection, GeneralConfigSectionFixture)
+BOOST_AUTO_TEST_SUITE(Mgmt)
+BOOST_FIXTURE_TEST_SUITE(TestGeneralConfigSection, GeneralConfigSectionFixture)
BOOST_AUTO_TEST_CASE(DefaultConfig)
{
@@ -113,12 +116,6 @@
#endif // HAVE_PRIVILEGE_DROP_AND_ELEVATE
-static bool
-checkExceptionMessage(const ConfigFile::Error& error, const std::string& expected)
-{
- return error.what() == expected;
-}
-
BOOST_AUTO_TEST_CASE(InvalidUserConfig)
{
const std::string CONFIG =
@@ -130,10 +127,12 @@
ConfigFile configFile;
general::setConfigFile(configFile);
- const std::string expected = "Invalid value for \"user\" in \"general\" section";
- BOOST_REQUIRE_EXCEPTION(configFile.parse(CONFIG, true, "test-general-config-section"),
- ConfigFile::Error,
- bind(&checkExceptionMessage, _1, expected));
+ BOOST_CHECK_EXCEPTION(configFile.parse(CONFIG, true, "test-general-config-section"),
+ ConfigFile::Error,
+ [] (const ConfigFile::Error& e) {
+ return std::strcmp(e.what(),
+ "Invalid value for \"user\" in \"general\" section") == 0;
+ });
}
BOOST_AUTO_TEST_CASE(InvalidGroupConfig)
@@ -147,13 +146,16 @@
ConfigFile configFile;
general::setConfigFile(configFile);
- const std::string expected = "Invalid value for \"group\" in \"general\" section";
- BOOST_REQUIRE_EXCEPTION(configFile.parse(CONFIG, true, "test-general-config-section"),
- ConfigFile::Error,
- bind(&checkExceptionMessage, _1, expected));
+ BOOST_CHECK_EXCEPTION(configFile.parse(CONFIG, true, "test-general-config-section"),
+ ConfigFile::Error,
+ [] (const ConfigFile::Error& e) {
+ return std::strcmp(e.what(),
+ "Invalid value for \"group\" in \"general\" section") == 0;
+ });
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestGeneralConfigSection
+BOOST_AUTO_TEST_SUITE_END() // Mgmt
} // namespace tests
} // namespace general