@@ -319,6 +319,8 @@ TEST_F(ConfigTest, optionalNodeId) {
319319TEST_F (ConfigTest, readConfigEnvVarTest) {
320320 const std::string kEnvVarName = " PRESTO_READ_CONFIG_TEST_VAR" ;
321321 const std::string kEmptyEnvVarName = " PRESTO_READ_CONFIG_TEST_EMPTY_VAR" ;
322+ const std::string kNonExistEnvVarName =
323+ " PRESTO_READ_CONFIG_TEST_NON_EXIST_VAR" ;
322324
323325 const std::string kPlainTextKey = " plain-text" ;
324326 const std::string kPlainTextValue = " plain-text-value" ;
@@ -337,22 +339,42 @@ TEST_F(ConfigTest, readConfigEnvVarTest) {
337339 fmt::format (" {}=${{{}}}\n " , kEnvVarKey , kEnvVarName ) +
338340 fmt::format (" {}=${{{}\n " , kEnvVarKey2 , kEnvVarName ) +
339341 fmt::format (" {}={}}}\n " , kEnvVarKey3 , kEnvVarName ) +
340- fmt::format (" {}=${{}}\n " , kNoEnvVarKey ) +
341- fmt::format (" {}=${{{}}}\n " , kEmptyEnvVarKey , kEmptyEnvVarName ));
342+ fmt::format (" {}=${{}}\n " , kNoEnvVarKey ));
342343
343344 setenv (kEnvVarName .c_str (), kEnvVarValue .c_str (), 1 );
344- setenv (kEmptyEnvVarName .c_str (), " " , 1 );
345345
346346 auto properties = presto::util::readConfig (configFilePath_);
347347 std::unordered_map<std::string, std::string> expected{
348348 {kPlainTextKey , kPlainTextValue },
349349 {kEnvVarKey , kEnvVarValue },
350350 {kEnvVarKey2 , " ${PRESTO_READ_CONFIG_TEST_VAR" },
351351 {kEnvVarKey3 , " PRESTO_READ_CONFIG_TEST_VAR}" },
352- {kNoEnvVarKey , " ${}" },
353- {kEmptyEnvVarKey , " " }};
352+ {kNoEnvVarKey , " ${}" }};
354353 ASSERT_EQ (properties, expected);
355354
355+ // Empty env var
356+ auto testInvalidEnvVar = [this ](
357+ const std::string& fileContent,
358+ const std::string& expectedErrorMsg) {
359+ cleanupConfigFilePath ();
360+ setUpConfigFilePath ();
361+ writeConfigFile (fileContent);
362+ VELOX_ASSERT_THROW (
363+ presto::util::readConfig (configFilePath_), expectedErrorMsg);
364+ };
365+
366+ setenv (kEmptyEnvVarName .c_str (), " " , 1 );
367+ testInvalidEnvVar (
368+ fmt::format (" {}=${{{}}}\n " , kEmptyEnvVarKey , kEmptyEnvVarName ),
369+ fmt::format (
370+ " Config environment variable {} doesn't exist or is empty" ,
371+ kEmptyEnvVarName ));
372+ testInvalidEnvVar (
373+ fmt::format (" {}=${{{}}}\n " , kEmptyEnvVarKey , kNonExistEnvVarName ),
374+ fmt::format (
375+ " Config environment variable {} doesn't exist or is empty" ,
376+ kNonExistEnvVarName ));
377+
356378 unsetenv (kEnvVarName .c_str ());
357379 unsetenv (kEmptyEnvVarName .c_str ());
358380}
0 commit comments