RemoveStringFromCSV: add unit test
Tested: only added a unit test and it passed.
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: If68e47545f184b9fa22d701e78fb15b2b1b7949f
diff --git a/test/user_mgr_test.cpp b/test/user_mgr_test.cpp
index 22a8837..ee45482 100644
--- a/test/user_mgr_test.cpp
+++ b/test/user_mgr_test.cpp
@@ -160,5 +160,28 @@
"123,456");
}
+TEST(RemoveStringFromCSV, WithoutDeleteStringReturnsFalse)
+{
+ std::string expected = "whatever,https";
+ std::string str = expected;
+ EXPECT_FALSE(removeStringFromCSV(str, "ssh"));
+ EXPECT_EQ(str, expected);
+
+ std::string empty;
+ EXPECT_FALSE(removeStringFromCSV(empty, "ssh"));
+}
+
+TEST(RemoveStringFromCSV, WithDeleteStringReturnsTrue)
+{
+ std::string expected = "whatever";
+ std::string str = "whatever,https";
+ EXPECT_TRUE(removeStringFromCSV(str, "https"));
+ EXPECT_EQ(str, expected);
+
+ str = "https";
+ EXPECT_TRUE(removeStringFromCSV(str, "https"));
+ EXPECT_EQ(str, "");
+}
+
} // namespace user
} // namespace phosphor
diff --git a/user_mgr.cpp b/user_mgr.cpp
index 7ee424d..b2047b2 100644
--- a/user_mgr.cpp
+++ b/user_mgr.cpp
@@ -148,7 +148,7 @@
});
}
-static bool removeStringFromCSV(std::string& csvStr, const std::string& delStr)
+bool removeStringFromCSV(std::string& csvStr, const std::string& delStr)
{
std::string::size_type delStrPos = csvStr.find(delStr);
if (delStrPos != std::string::npos)
diff --git a/user_mgr.hpp b/user_mgr.hpp
index 5c1553b..4a82950 100644
--- a/user_mgr.hpp
+++ b/user_mgr.hpp
@@ -64,6 +64,8 @@
std::string getCSVFromVector(std::span<const std::string> vec);
+bool removeStringFromCSV(std::string& csvStr, const std::string& delStr);
+
/** @class UserMgr
* @brief Responsible for managing user accounts over the D-Bus interface.
*/