test treewide: apply test names best practices
1. test suite names are usually related to the function under tests, not
the whole source or header file
2. test case names should be verbose and describe the high level
behavior
This commits also splits test cases when they are for different
functions, and merges test cases when they are very similar.
Reference:
1. https://github.com/google/googletest/tree/main/googletest/samples
2. https://testing.googleblog.com/2007/02/tott-naming-unit-tests-responsibly.html
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: I498cb2076bbaa9f0829f50bca45a2e38a6f4ab7d
diff --git a/redfish-core/ut/configfile_test.cpp b/redfish-core/ut/configfile_test.cpp
index 7e9c785..2c68c0b 100644
--- a/redfish-core/ut/configfile_test.cpp
+++ b/redfish-core/ut/configfile_test.cpp
@@ -10,61 +10,42 @@
namespace ibm_mc
{
-TEST(ConfigFileTest, FileNameValidChar)
+TEST(IsValidConfigFileName, FileNameValidCharReturnsTrue)
{
crow::Response res;
- const std::string fileName = "GoodConfigFile";
- EXPECT_TRUE(isValidConfigFileName(fileName, res));
+ EXPECT_TRUE(isValidConfigFileName("GoodConfigFile", res));
}
-TEST(ConfigFileTest, FileNameInvalidChar)
+TEST(IsValidConfigFileName, FileNameInvalidCharReturnsFalse)
{
crow::Response res;
- const std::string fileName = "Bad@file";
- EXPECT_FALSE(isValidConfigFileName(fileName, res));
+ EXPECT_FALSE(isValidConfigFileName("Bad@file", res));
}
-TEST(ConfigFileTest, FileNameInvalidPath1)
+TEST(IsValidConfigFileName, FileNameInvalidPathReturnsFalse)
{
crow::Response res;
- const std::string fileName = "/../../../../../etc/badpath";
- EXPECT_FALSE(isValidConfigFileName(fileName, res));
+ EXPECT_FALSE(isValidConfigFileName("/../../../../../etc/badpath", res));
+ EXPECT_FALSE(isValidConfigFileName("/../../etc/badpath", res));
+ EXPECT_FALSE(isValidConfigFileName("/mydir/configFile", res));
}
-TEST(ConfigFileTest, FileNameInvalidPath2)
+
+TEST(IsValidConfigFileName, EmptyFileNameReturnsFalse)
{
crow::Response res;
-
- const std::string fileName = "/../../etc/badpath";
- EXPECT_FALSE(isValidConfigFileName(fileName, res));
+ EXPECT_FALSE(isValidConfigFileName("", res));
}
-TEST(ConfigFileTest, FileNameInvalidPath3)
+
+TEST(IsValidConfigFileName, SlashFileNameReturnsFalse)
{
crow::Response res;
-
- const std::string fileName = "/mydir/configFile";
- EXPECT_FALSE(isValidConfigFileName(fileName, res));
+ EXPECT_FALSE(isValidConfigFileName("/", res));
}
-TEST(ConfigFileTest, FileNameNull)
+TEST(IsValidConfigFileName, FileNameMoreThan20CharReturnsFalse)
{
crow::Response res;
-
- const std::string fileName;
- EXPECT_FALSE(isValidConfigFileName(fileName, res));
-}
-TEST(ConfigFileTest, FileNameSlash)
-{
- crow::Response res;
-
- const std::string fileName = "/";
- EXPECT_FALSE(isValidConfigFileName(fileName, res));
-}
-TEST(ConfigFileTest, FileNameMorethan20Char)
-{
- crow::Response res;
-
- const std::string fileName = "BadfileBadfileBadfile";
- EXPECT_FALSE(isValidConfigFileName(fileName, res));
+ EXPECT_FALSE(isValidConfigFileName("BadfileBadfileBadfile", res));
}
} // namespace ibm_mc