[fdbmonitor] Ctests for envvars key-value extraction (#11562)

This commit is contained in:
Syed Paymaan Raza 2024-08-07 22:05:14 -07:00 committed by GitHub
parent 46e985acf3
commit bc17127e36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 2 deletions

View File

@ -128,7 +128,17 @@ void testPathOps() {
} }
void testEnvVarUtils() { void testEnvVarUtils() {
// Ensure validation passes for good inputs // Ensure key-value extraction works
const std::pair<std::string, std::string> keyValuePair1{ "FOO", "BAR" };
assert(keyValuePair1 == EnvVarUtils::extractKeyAndValue("FOO=BAR"));
const std::pair<std::string, std::string> keyValuePair2{ "x", "y" };
assert(keyValuePair2 == EnvVarUtils::extractKeyAndValue("x=y"));
const std::pair<std::string, std::string> keyValuePair3{ "MALLOC_CONF",
"prof:true,lg_prof_interval:30,prof_prefix:jeprof.out" };
assert(keyValuePair3 ==
EnvVarUtils::extractKeyAndValue("MALLOC_CONF=prof:true,lg_prof_interval:30,prof_prefix:jeprof.out"));
// Ensure key-value validation passes for good inputs
assert(EnvVarUtils::keyValueValid("FOO=BAR", "FOO=BAR")); assert(EnvVarUtils::keyValueValid("FOO=BAR", "FOO=BAR"));
assert(EnvVarUtils::keyValueValid("x=y", "FOO=BAR x=y")); assert(EnvVarUtils::keyValueValid("x=y", "FOO=BAR x=y"));
assert(EnvVarUtils::keyValueValid("MALLOC_CONF=prof:true,lg_prof_interval:30,prof_prefix:jeprof.out", assert(EnvVarUtils::keyValueValid("MALLOC_CONF=prof:true,lg_prof_interval:30,prof_prefix:jeprof.out",
@ -136,7 +146,7 @@ void testEnvVarUtils() {
assert(EnvVarUtils::keyValueValid("MALLOC_CONF=prof:true,lg_prof_interval:30,prof_prefix:jeprof.out", assert(EnvVarUtils::keyValueValid("MALLOC_CONF=prof:true,lg_prof_interval:30,prof_prefix:jeprof.out",
"MALLOC_CONF=prof:true,lg_prof_interval:30,prof_prefix:jeprof.out FOO=BAR")); "MALLOC_CONF=prof:true,lg_prof_interval:30,prof_prefix:jeprof.out FOO=BAR"));
// Ensure validation fails for bad inputs // Ensure key-value validation fails for bad inputs
assert_msg(!EnvVarUtils::keyValueValid("", "FOO=BAR ="), "Key-Value can not be empty"); assert_msg(!EnvVarUtils::keyValueValid("", "FOO=BAR ="), "Key-Value can not be empty");
assert_msg(!EnvVarUtils::keyValueValid("FOO==BAR", "FOO==BAR"), "Only one equal sign allowed"); assert_msg(!EnvVarUtils::keyValueValid("FOO==BAR", "FOO==BAR"), "Only one equal sign allowed");
assert_msg(!EnvVarUtils::keyValueValid("BAZ=", "FOO=BAR BAZ="), "Value must be non-empty"); assert_msg(!EnvVarUtils::keyValueValid("BAZ=", "FOO=BAR BAZ="), "Value must be non-empty");