Get ignored interfaces from environment
Add several functions to get a comma separated string from environment,
and parse the string into a set.
Tested: Verify the unit tests passes.
Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I0dd7270d9882cf6fa3ce73d8eac516ae42c61fc0
diff --git a/test/test_util.cpp b/test/test_util.cpp
index 9b61c64..a63e205 100644
--- a/test/test_util.cpp
+++ b/test/test_util.cpp
@@ -10,6 +10,7 @@
#include <string_view>
#include <xyz/openbmc_project/Common/error.hpp>
+#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace phosphor
@@ -329,6 +330,27 @@
EXPECT_FALSE(isUnicast(fromString("ff:ff:ff:ff:ff:ff")));
}
+TEST(IgnoredInterfaces, Empty)
+{
+ auto ret = internal::parseInterfaces({});
+ EXPECT_TRUE(ret.empty());
+
+ ret = internal::parseInterfaces(" , ,, ");
+ EXPECT_TRUE(ret.empty());
+}
+
+TEST(IgnoredInterfaces, NotEmpty)
+{
+ using ::testing::ContainerEq;
+ std::set<std::string> expected = {"eth0"};
+ auto ret = internal::parseInterfaces("eth0");
+ EXPECT_THAT(ret, ContainerEq(expected));
+
+ expected = {"eth0", "eth1", "bond1", "usb0"};
+ ret = internal::parseInterfaces(" ,eth0, eth1 ,bond1, usb0,,");
+ EXPECT_THAT(ret, ContainerEq(expected));
+}
+
} // namespace mac_address
} // namespace network
} // namespace phosphor