1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-06-16 23:47:38 +02:00

Add config/parse tests for options and option args with spaces.

If an option name has a space at the beginning then it will be considered an invalid command, but a space at the end is an invalid option. Add tests for these conditions.

Spaces in option arguments should be preserved, so add a test to be sure this is true.
This commit is contained in:
David Steele
2021-05-13 17:01:21 -04:00
parent 2b8d2daca1
commit 34dd6636b8

View File

@ -610,6 +610,23 @@ testRun(void)
TEST_ERROR( TEST_ERROR(
configParse(storageTest, strLstSize(argList), strLstPtr(argList), false), OptionInvalidError, "invalid option '--c'"); configParse(storageTest, strLstSize(argList), strLstPtr(argList), false), OptionInvalidError, "invalid option '--c'");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("error on spaces in option name");
argList = strLstNew();
strLstAddZ(argList, TEST_BACKREST_EXE);
strLstAddZ(argList, " --config=/path/to");
TEST_ERROR(
configParse(storageTest, strLstSize(argList), strLstPtr(argList), false), CommandInvalidError,
"invalid command ' --config=/path/to'");
argList = strLstNew();
strLstAddZ(argList, TEST_BACKREST_EXE);
strLstAddZ(argList, "--config =/path/to");
TEST_ERROR(
configParse(storageTest, strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
"invalid option '--config =/path/to'");
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew(); argList = strLstNew();
strLstAdd(argList, strNew(TEST_BACKREST_EXE)); strLstAdd(argList, strNew(TEST_BACKREST_EXE));
@ -1215,6 +1232,7 @@ testRun(void)
TEST_RESULT_STR_Z(cfgOptionIdxStr(cfgOptPgPath, 0), "/path/to/db", " pg1-path is set"); TEST_RESULT_STR_Z(cfgOptionIdxStr(cfgOptPgPath, 0), "/path/to/db", " pg1-path is set");
TEST_RESULT_INT(cfgOptionSource(cfgOptPgPath), cfgSourceParam, " pg1-path is source param"); TEST_RESULT_INT(cfgOptionSource(cfgOptPgPath), cfgSourceParam, " pg1-path is source param");
TEST_RESULT_UINT(cfgOptionIdxStrId(cfgOptRepoType, 0), strIdFromZ(stringIdBit6, "s3"), " repo-type is set"); TEST_RESULT_UINT(cfgOptionIdxStrId(cfgOptRepoType, 0), strIdFromZ(stringIdBit6, "s3"), " repo-type is set");
TEST_RESULT_STR_Z(cfgOptionStr(cfgOptRepoS3Bucket), " test ", " repo1-s3-bucket is set and preserves spaces");
TEST_RESULT_STR_Z(cfgOptionStr(cfgOptRepoS3KeySecret), "xxx", " repo1-s3-secret is set"); TEST_RESULT_STR_Z(cfgOptionStr(cfgOptRepoS3KeySecret), "xxx", " repo1-s3-secret is set");
TEST_RESULT_INT(cfgOptionSource(cfgOptRepoS3KeySecret), cfgSourceConfig, " repo1-s3-secret is source env"); TEST_RESULT_INT(cfgOptionSource(cfgOptRepoS3KeySecret), cfgSourceConfig, " repo1-s3-secret is source env");
TEST_RESULT_BOOL(cfgOptionBool(cfgOptOnline), false, " online is not set"); TEST_RESULT_BOOL(cfgOptionBool(cfgOptOnline), false, " online is not set");