2017-11-28 21:44:05 -05:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Configuration Parse
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#define TEST_BACKREST_EXE "pgbackrest"
|
|
|
|
|
2017-12-05 10:09:07 -05:00
|
|
|
#define TEST_COMMAND_ARCHIVE_GET "archive-get"
|
|
|
|
#define TEST_COMMAND_BACKUP "backup"
|
2017-11-28 21:44:05 -05:00
|
|
|
#define TEST_COMMAND_HELP "help"
|
2017-12-05 10:09:07 -05:00
|
|
|
#define TEST_COMMAND_RESTORE "restore"
|
2017-11-28 21:44:05 -05:00
|
|
|
#define TEST_COMMAND_VERSION "version"
|
|
|
|
|
2018-07-20 18:51:42 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Expose log internal data for unit testing/debugging
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
extern LogLevel logLevelStdOut;
|
|
|
|
extern LogLevel logLevelStdErr;
|
|
|
|
extern LogLevel logLevelFile;
|
|
|
|
|
2018-02-03 18:27:38 -05:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Option find test -- this is done a lot in the deprecated tests
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
static void
|
2018-03-02 12:07:12 -05:00
|
|
|
testOptionFind(const char *option, unsigned int value)
|
2018-02-03 18:27:38 -05:00
|
|
|
{
|
|
|
|
// If not testing for a missing option, then add the option offset that is already added to each option in the list
|
|
|
|
if (value != 0)
|
|
|
|
value |= PARSE_OPTION_FLAG;
|
|
|
|
|
|
|
|
TEST_RESULT_INT(optionList[optionFind(strNew(option))].val, value, "check %s", option);
|
|
|
|
}
|
|
|
|
|
2017-11-28 21:44:05 -05:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test run
|
|
|
|
***********************************************************************************************************************************/
|
2018-01-31 18:22:25 -05:00
|
|
|
void
|
2018-08-03 19:19:14 -04:00
|
|
|
testRun(void)
|
2017-11-28 21:44:05 -05:00
|
|
|
{
|
2018-05-18 11:57:32 -04:00
|
|
|
FUNCTION_HARNESS_VOID();
|
|
|
|
|
2018-04-19 11:09:39 -04:00
|
|
|
// config and config-include-path options
|
2018-09-16 14:15:21 -04:00
|
|
|
// *****************************************************************************************************************************
|
2018-04-19 11:09:39 -04:00
|
|
|
if (testBegin("cfgFileLoad()"))
|
|
|
|
{
|
|
|
|
StringList *argList = NULL;
|
|
|
|
String *configFile = strNewFmt("%s/test.config", testPath());
|
|
|
|
|
|
|
|
String *configIncludePath = strNewFmt("%s/conf.d", testPath());
|
|
|
|
mkdir(strPtr(configIncludePath), 0750);
|
|
|
|
|
2018-11-16 08:48:02 -05:00
|
|
|
// Check old config file constants
|
2018-04-19 11:09:39 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_RESULT_STR(PGBACKREST_CONFIG_ORIG_PATH_FILE, "/etc/pgbackrest.conf", "check old config path");
|
2018-11-16 08:48:02 -05:00
|
|
|
TEST_RESULT_STR(strPtr(PGBACKREST_CONFIG_ORIG_PATH_FILE_STR), "/etc/pgbackrest.conf", "check old config path str");
|
2018-04-19 11:09:39 -04:00
|
|
|
|
|
|
|
// Confirm same behavior with multiple config include files
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile)));
|
|
|
|
strLstAdd(argList, strNewFmt("--config-include-path=%s", strPtr(configIncludePath)));
|
|
|
|
strLstAdd(argList, strNew("--no-online"));
|
|
|
|
strLstAdd(argList, strNew("--reset-pg1-host"));
|
|
|
|
strLstAdd(argList, strNew("--reset-backup-standby"));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
|
|
|
|
storagePut(
|
2018-09-26 18:46:52 +01:00
|
|
|
storageNewWriteNP(storageLocalWrite(), configFile),
|
2019-04-20 08:16:17 -04:00
|
|
|
BUFSTRDEF(
|
2018-09-26 18:46:52 +01:00
|
|
|
"[global]\n"
|
|
|
|
"compress-level=3\n"
|
|
|
|
"spool-path=/path/to/spool\n"));
|
2018-04-19 11:09:39 -04:00
|
|
|
|
|
|
|
storagePut(
|
2018-09-26 18:46:52 +01:00
|
|
|
storageNewWriteNP(storageLocalWrite(), strNewFmt("%s/global-backup.conf", strPtr(configIncludePath))),
|
2019-04-20 08:16:17 -04:00
|
|
|
BUFSTRDEF(
|
2018-09-26 18:46:52 +01:00
|
|
|
"[global:backup]\n"
|
|
|
|
"repo1-hardlink=y\n"
|
|
|
|
"bogus=bogus\n"
|
|
|
|
"no-compress=y\n"
|
|
|
|
"reset-compress=y\n"
|
|
|
|
"archive-copy=y\n"
|
|
|
|
"online=y\n"
|
|
|
|
"pg1-path=/not/path/to/db\n"
|
|
|
|
"backup-standby=y\n"
|
|
|
|
"buffer-size=65536\n"));
|
2018-04-19 11:09:39 -04:00
|
|
|
|
|
|
|
storagePut(
|
2018-09-26 18:46:52 +01:00
|
|
|
storageNewWriteNP(storageLocalWrite(), strNewFmt("%s/db-backup.conf", strPtr(configIncludePath))),
|
2019-04-20 08:16:17 -04:00
|
|
|
BUFSTRDEF(
|
2018-09-26 18:46:52 +01:00
|
|
|
"[db:backup]\n"
|
|
|
|
"compress=n\n"
|
|
|
|
"recovery-option=a=b\n"));
|
2018-04-19 11:09:39 -04:00
|
|
|
|
|
|
|
storagePut(
|
2018-09-26 18:46:52 +01:00
|
|
|
storageNewWriteNP(storageLocalWrite(), strNewFmt("%s/stanza.db.conf", strPtr(configIncludePath))),
|
2019-04-20 08:16:17 -04:00
|
|
|
BUFSTRDEF(
|
2018-09-26 18:46:52 +01:00
|
|
|
"[db]\n"
|
|
|
|
"pg1-host=db\n"
|
|
|
|
"pg1-path=/path/to/db\n"
|
|
|
|
"recovery-option=c=d\n"));
|
2018-04-19 11:09:39 -04:00
|
|
|
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_RESULT_VOID(
|
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), TEST_COMMAND_BACKUP " command with config-include");
|
|
|
|
harnessLogResult(
|
2018-04-19 11:09:39 -04:00
|
|
|
strPtr(
|
|
|
|
strNew(
|
2018-07-20 18:51:42 -04:00
|
|
|
"P00 WARN: configuration file contains option 'recovery-option' invalid for section 'db:backup'\n"
|
|
|
|
"P00 WARN: configuration file contains invalid option 'bogus'\n"
|
|
|
|
"P00 WARN: configuration file contains negate option 'no-compress'\n"
|
|
|
|
"P00 WARN: configuration file contains reset option 'reset-compress'\n"
|
|
|
|
"P00 WARN: configuration file contains command-line only option 'online'\n"
|
|
|
|
"P00 WARN: configuration file contains stanza-only option 'pg1-path' in global section 'global:backup'")));
|
2018-04-19 11:09:39 -04:00
|
|
|
|
|
|
|
TEST_RESULT_BOOL(cfgOptionTest(cfgOptPgHost), false, " pg1-host is not set (command line reset override)");
|
|
|
|
TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptPgPath)), "/path/to/db", " pg1-path is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptPgPath), cfgSourceConfig, " pg1-path is source config");
|
|
|
|
TEST_RESULT_BOOL(cfgOptionBool(cfgOptCompress), false, " compress not is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptCompress), cfgSourceConfig, " compress is source config");
|
|
|
|
TEST_RESULT_BOOL(cfgOptionTest(cfgOptArchiveCheck), false, " archive-check is not set");
|
|
|
|
TEST_RESULT_BOOL(cfgOptionTest(cfgOptArchiveCopy), false, " archive-copy is not set");
|
|
|
|
TEST_RESULT_BOOL(cfgOptionBool(cfgOptRepoHardlink), true, " repo-hardlink is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptRepoHardlink), cfgSourceConfig, " repo-hardlink is source config");
|
|
|
|
TEST_RESULT_INT(cfgOptionInt(cfgOptCompressLevel), 3, " compress-level is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptCompressLevel), cfgSourceConfig, " compress-level is source config");
|
|
|
|
TEST_RESULT_BOOL(cfgOptionBool(cfgOptBackupStandby), false, " backup-standby not is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptBackupStandby), cfgSourceDefault, " backup-standby is source default");
|
|
|
|
TEST_RESULT_BOOL(cfgOptionInt64(cfgOptBufferSize), 65536, " buffer-size is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptBufferSize), cfgSourceConfig, " backup-standby is source config");
|
|
|
|
|
|
|
|
// Rename conf files - ensure read of conf extension only is attempted
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
rename(strPtr(strNewFmt("%s/db-backup.conf", strPtr(configIncludePath))),
|
|
|
|
strPtr(strNewFmt("%s/db-backup.conf.save", strPtr(configIncludePath))));
|
|
|
|
rename(strPtr(strNewFmt("%s/global-backup.conf", strPtr(configIncludePath))),
|
|
|
|
strPtr(strNewFmt("%s/global-backup.confsave", strPtr(configIncludePath))));
|
|
|
|
|
|
|
|
// Set up defaults
|
|
|
|
String *backupCmdDefConfigValue = strNew(cfgDefOptionDefault(
|
|
|
|
cfgCommandDefIdFromId(cfgCommandId(TEST_COMMAND_BACKUP)), cfgOptionDefIdFromId(cfgOptConfig)));
|
|
|
|
String *backupCmdDefConfigInclPathValue = strNew(cfgDefOptionDefault(
|
|
|
|
cfgCommandDefIdFromId(cfgCommandId(TEST_COMMAND_BACKUP)), cfgOptionDefIdFromId(cfgOptConfigIncludePath)));
|
|
|
|
String *oldConfigDefault = strNewFmt("%s%s", testPath(), PGBACKREST_CONFIG_ORIG_PATH_FILE);
|
|
|
|
|
|
|
|
// Create the option structure and initialize with 0
|
|
|
|
ParseOption parseOptionList[CFG_OPTION_TOTAL];
|
|
|
|
memset(&parseOptionList, 0, sizeof(parseOptionList));
|
|
|
|
|
|
|
|
parseOptionList[cfgOptConfig].found = true;
|
|
|
|
parseOptionList[cfgOptConfig].source = cfgSourceParam;
|
|
|
|
parseOptionList[cfgOptConfig].valueList = strLstAdd(strLstNew(), configFile);
|
|
|
|
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].found = true;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].source = cfgSourceParam;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].valueList = strLstAdd(strLstNew(), configIncludePath);
|
|
|
|
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, backupCmdDefConfigValue,
|
|
|
|
backupCmdDefConfigInclPathValue, oldConfigDefault)),
|
|
|
|
"[global]\n"
|
|
|
|
"compress-level=3\n"
|
|
|
|
"spool-path=/path/to/spool\n"
|
|
|
|
"\n"
|
|
|
|
"[db]\n"
|
|
|
|
"pg1-host=db\n"
|
|
|
|
"pg1-path=/path/to/db\n"
|
|
|
|
"recovery-option=c=d\n",
|
|
|
|
"config-include-path with .conf files and non-.conf files");
|
|
|
|
|
|
|
|
// Pass invalid values
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
// --config valid, --config-include-path invalid (does not exist)
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].valueList = strLstAddZ(strLstNew(), BOGUS_STR);
|
|
|
|
TEST_ERROR(
|
|
|
|
cfgFileLoad(parseOptionList, backupCmdDefConfigValue,
|
|
|
|
backupCmdDefConfigInclPathValue, oldConfigDefault), PathOpenError,
|
|
|
|
"unable to open path '/BOGUS' for read: [2] No such file or directory");
|
|
|
|
|
|
|
|
// --config-include-path valid, --config invalid (does not exist)
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].valueList = strLstAdd(strLstNew(), configIncludePath);
|
|
|
|
parseOptionList[cfgOptConfig].valueList = strLstAdd(strLstNew(), strNewFmt("%s/%s", testPath(), BOGUS_STR));
|
|
|
|
|
|
|
|
TEST_ERROR(
|
|
|
|
cfgFileLoad(parseOptionList, backupCmdDefConfigValue,
|
2018-09-04 17:47:23 -04:00
|
|
|
backupCmdDefConfigInclPathValue, oldConfigDefault), FileMissingError,
|
2018-04-19 11:09:39 -04:00
|
|
|
strPtr(strNewFmt("unable to open '%s/%s' for read: [2] No such file or directory", testPath(), BOGUS_STR)));
|
|
|
|
|
|
|
|
strLstFree(parseOptionList[cfgOptConfig].valueList);
|
|
|
|
strLstFree(parseOptionList[cfgOptConfigIncludePath].valueList);
|
|
|
|
|
|
|
|
// Neither config nor config-include-path passed as parameter (defaults but none exist)
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
parseOptionList[cfgOptConfig].found = false;
|
|
|
|
parseOptionList[cfgOptConfig].source = cfgSourceDefault;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].found = false;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].source = cfgSourceDefault;
|
|
|
|
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, backupCmdDefConfigValue,
|
|
|
|
backupCmdDefConfigInclPathValue, oldConfigDefault)),
|
|
|
|
NULL,
|
|
|
|
"config default, config-include-path default but nothing to read");
|
|
|
|
|
|
|
|
// Config not passed as parameter - config does not exist. config-include-path passed as parameter - only include read
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
parseOptionList[cfgOptConfig].found = false;
|
|
|
|
parseOptionList[cfgOptConfig].source = cfgSourceDefault;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].found = true;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].source = cfgSourceParam;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].valueList = strLstAdd(strLstNew(), configIncludePath);
|
|
|
|
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, backupCmdDefConfigValue,
|
|
|
|
backupCmdDefConfigInclPathValue, oldConfigDefault)),
|
|
|
|
"[db]\n"
|
|
|
|
"pg1-host=db\n"
|
|
|
|
"pg1-path=/path/to/db\n"
|
|
|
|
"recovery-option=c=d\n",
|
|
|
|
"config default and doesn't exist, config-include-path passed read");
|
|
|
|
|
|
|
|
// config and config-include-path are "default" with files existing. Config file exists in both currrent default and old
|
|
|
|
// default location - old location ignored.
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
parseOptionList[cfgOptConfig].found = false;
|
|
|
|
parseOptionList[cfgOptConfig].source = cfgSourceDefault;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].found = false;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].source = cfgSourceDefault;
|
|
|
|
|
|
|
|
mkdir(strPtr(strPath(oldConfigDefault)), 0750);
|
|
|
|
storagePut(
|
2018-09-26 18:46:52 +01:00
|
|
|
storageNewWriteNP(storageLocalWrite(), oldConfigDefault),
|
2019-04-20 08:16:17 -04:00
|
|
|
BUFSTRDEF(
|
2018-09-26 18:46:52 +01:00
|
|
|
"[global:backup]\n"
|
|
|
|
"buffer-size=65536\n"));
|
2018-04-19 11:09:39 -04:00
|
|
|
|
|
|
|
// Pass actual location of config files as "default" - not setting valueList above, so these are the only possible values
|
|
|
|
// to choose.
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, configFile, configIncludePath,
|
|
|
|
oldConfigDefault)),
|
|
|
|
"[global]\n"
|
|
|
|
"compress-level=3\n"
|
|
|
|
"spool-path=/path/to/spool\n"
|
|
|
|
"\n"
|
|
|
|
"[db]\n"
|
|
|
|
"pg1-host=db\n"
|
|
|
|
"pg1-path=/path/to/db\n"
|
|
|
|
"recovery-option=c=d\n",
|
|
|
|
"config and config-include-path default, files appended, original config not read");
|
|
|
|
|
|
|
|
// Config not passed as parameter - config does not exist in new default but does exist in old default. config-include-path
|
|
|
|
// passed as parameter - both include and old default read
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
parseOptionList[cfgOptConfig].found = false;
|
|
|
|
parseOptionList[cfgOptConfig].source = cfgSourceDefault;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].found = true;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].source = cfgSourceParam;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].valueList = strLstAdd(strLstNew(), configIncludePath);
|
|
|
|
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, backupCmdDefConfigValue,
|
|
|
|
backupCmdDefConfigInclPathValue, oldConfigDefault)),
|
|
|
|
"[global:backup]\n"
|
|
|
|
"buffer-size=65536\n"
|
|
|
|
"\n"
|
|
|
|
"[db]\n"
|
|
|
|
"pg1-host=db\n"
|
|
|
|
"pg1-path=/path/to/db\n"
|
|
|
|
"recovery-option=c=d\n",
|
|
|
|
"config old default read, config-include-path passed read");
|
|
|
|
|
|
|
|
// --no-config and config-include-path passed as parameter (files read only from include path and not current or old config)
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
parseOptionList[cfgOptConfig].found = true;
|
|
|
|
parseOptionList[cfgOptConfig].source = cfgSourceParam;
|
|
|
|
parseOptionList[cfgOptConfig].negate = true;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].found = true;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].source = cfgSourceParam;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].valueList = strLstAdd(strLstNew(), configIncludePath);
|
|
|
|
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, backupCmdDefConfigValue,
|
|
|
|
backupCmdDefConfigInclPathValue, oldConfigDefault)),
|
|
|
|
"[db]\n"
|
|
|
|
"pg1-host=db\n"
|
|
|
|
"pg1-path=/path/to/db\n"
|
|
|
|
"recovery-option=c=d\n",
|
|
|
|
"--no-config, only config-include-path read");
|
|
|
|
|
|
|
|
// --no-config and config-include-path default exists with files - nothing to read
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
parseOptionList[cfgOptConfig].found = true;
|
|
|
|
parseOptionList[cfgOptConfig].source = cfgSourceParam;
|
|
|
|
parseOptionList[cfgOptConfig].negate = true;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].found = false;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].source = cfgSourceDefault;
|
|
|
|
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, backupCmdDefConfigValue,
|
|
|
|
configIncludePath, oldConfigDefault)),
|
|
|
|
NULL,
|
|
|
|
"--no-config, config-include-path default, nothing read");
|
|
|
|
|
|
|
|
// config passed and config-include-path default exists with files - only config read
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
parseOptionList[cfgOptConfig].found = true;
|
|
|
|
parseOptionList[cfgOptConfig].source = cfgSourceParam;
|
|
|
|
parseOptionList[cfgOptConfig].negate = false;
|
|
|
|
parseOptionList[cfgOptConfig].valueList = strLstAdd(strLstNew(), configFile);
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].found = false;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].source = cfgSourceDefault;
|
|
|
|
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, backupCmdDefConfigValue,
|
|
|
|
configIncludePath, oldConfigDefault)),
|
|
|
|
"[global]\n"
|
|
|
|
"compress-level=3\n"
|
|
|
|
"spool-path=/path/to/spool\n",
|
|
|
|
"config param specified, config-include-path default, only config read");
|
|
|
|
|
|
|
|
// config new default and config-include-path passed - both exists with files. config-include-path & new config default read
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
parseOptionList[cfgOptConfig].found = false;
|
|
|
|
parseOptionList[cfgOptConfig].source = cfgSourceDefault;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].found = true;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].source = cfgSourceParam;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].valueList = strLstAdd(strLstNew(), configIncludePath);
|
|
|
|
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, configFile,
|
|
|
|
backupCmdDefConfigInclPathValue, oldConfigDefault)),
|
|
|
|
"[global]\n"
|
|
|
|
"compress-level=3\n"
|
|
|
|
"spool-path=/path/to/spool\n"
|
|
|
|
"\n"
|
|
|
|
"[db]\n"
|
|
|
|
"pg1-host=db\n"
|
|
|
|
"pg1-path=/path/to/db\n"
|
|
|
|
"recovery-option=c=d\n",
|
|
|
|
"config new default exists with files, config-include-path passed, defualt config and config-include-path read");
|
|
|
|
|
|
|
|
// config and config-include-path are "default".
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
parseOptionList[cfgOptConfig].found = false;
|
|
|
|
parseOptionList[cfgOptConfig].source = cfgSourceDefault;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].found = false;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].source = cfgSourceDefault;
|
|
|
|
|
|
|
|
// File exists in old default config location but not in current default.
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, backupCmdDefConfigValue,
|
|
|
|
configIncludePath, oldConfigDefault)),
|
|
|
|
"[global:backup]\n"
|
|
|
|
"buffer-size=65536\n"
|
|
|
|
"\n"
|
|
|
|
"[db]\n"
|
|
|
|
"pg1-host=db\n"
|
|
|
|
"pg1-path=/path/to/db\n"
|
|
|
|
"recovery-option=c=d\n",
|
|
|
|
"config-path override - config-include-path files and old config default read since no config in current path");
|
|
|
|
|
|
|
|
// Pass --config-path
|
|
|
|
parseOptionList[cfgOptConfigPath].found = true;
|
|
|
|
parseOptionList[cfgOptConfigPath].source = cfgSourceParam;
|
|
|
|
parseOptionList[cfgOptConfigPath].valueList = strLstAddZ(strLstNew(), testPath());
|
|
|
|
|
|
|
|
// Override default paths for config and config-include-path - but no pgbackrest.conf file in override path only in old
|
|
|
|
// default so ignored
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, backupCmdDefConfigValue,
|
|
|
|
backupCmdDefConfigInclPathValue, oldConfigDefault)),
|
|
|
|
"[db]\n"
|
|
|
|
"pg1-host=db\n"
|
|
|
|
"pg1-path=/path/to/db\n"
|
|
|
|
"recovery-option=c=d\n",
|
|
|
|
"config-path override: config-include-path files read but config not read - does not exist");
|
|
|
|
|
|
|
|
// Pass --config
|
|
|
|
parseOptionList[cfgOptConfig].found = true;
|
|
|
|
parseOptionList[cfgOptConfig].source = cfgSourceParam;
|
|
|
|
parseOptionList[cfgOptConfig].negate = false;
|
|
|
|
parseOptionList[cfgOptConfig].valueList = strLstAdd(strLstNew(), configFile);
|
|
|
|
|
|
|
|
// Passing --config and --config-path - default config-include-path overwritten and config is required and is loaded and
|
|
|
|
// config-include-path files will attempt to be loaded but not required
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, backupCmdDefConfigValue,
|
|
|
|
backupCmdDefConfigInclPathValue, oldConfigDefault)),
|
|
|
|
"[global]\n"
|
|
|
|
"compress-level=3\n"
|
|
|
|
"spool-path=/path/to/spool\n"
|
|
|
|
"\n"
|
|
|
|
"[db]\n"
|
|
|
|
"pg1-host=db\n"
|
|
|
|
"pg1-path=/path/to/db\n"
|
|
|
|
"recovery-option=c=d\n",
|
|
|
|
"config-path changed config-include-path default - files exist, config and config includes read");
|
|
|
|
|
|
|
|
parseOptionList[cfgOptConfigPath].valueList = strLstAddZ(strLstNew(), BOGUS_STR);
|
|
|
|
|
|
|
|
// Passing --config and bogus --config-path - default config-include-path overwritten, config is required and is loaded and
|
|
|
|
// config-include-path files will attempt to be loaded but doesn't exist - no error since not required
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, backupCmdDefConfigValue,
|
|
|
|
backupCmdDefConfigInclPathValue, oldConfigDefault)),
|
|
|
|
"[global]\n"
|
|
|
|
"compress-level=3\n"
|
|
|
|
"spool-path=/path/to/spool\n",
|
|
|
|
"config-path changed config-include-path default but directory does not exist - only config read");
|
|
|
|
|
|
|
|
// Copy the configFile to pgbackrest.conf (default is /etc/pgbackrest/pgbackrest.conf and new value is testPath so copy the
|
|
|
|
// config file (that was not read in the previous test) to pgbackrest.conf so it will be read by the override
|
|
|
|
TEST_RESULT_INT(
|
|
|
|
system(
|
|
|
|
strPtr(strNewFmt("cp %s %s", strPtr(configFile), strPtr(strNewFmt("%s/pgbackrest.conf", testPath()))))), 0,
|
|
|
|
"copy configFile to pgbackrest.conf");
|
|
|
|
|
|
|
|
parseOptionList[cfgOptConfig].found = false;
|
|
|
|
parseOptionList[cfgOptConfig].source = cfgSourceDefault;
|
|
|
|
parseOptionList[cfgOptConfig].negate = false;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].found = false;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].source = cfgSourceDefault;
|
|
|
|
|
|
|
|
parseOptionList[cfgOptConfigPath].valueList = strLstAddZ(strLstNew(), testPath());
|
|
|
|
|
|
|
|
// Override default paths for config and config-include-path with --config-path
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, backupCmdDefConfigValue,
|
|
|
|
backupCmdDefConfigInclPathValue, oldConfigDefault)),
|
|
|
|
"[global]\n"
|
|
|
|
"compress-level=3\n"
|
|
|
|
"spool-path=/path/to/spool\n"
|
|
|
|
"\n"
|
|
|
|
"[db]\n"
|
|
|
|
"pg1-host=db\n"
|
|
|
|
"pg1-path=/path/to/db\n"
|
|
|
|
"recovery-option=c=d\n",
|
|
|
|
"config-path override: config-include-path and config file read");
|
|
|
|
|
|
|
|
// Clear config-path
|
|
|
|
parseOptionList[cfgOptConfigPath].found = false;
|
|
|
|
parseOptionList[cfgOptConfigPath].source = cfgSourceDefault;
|
|
|
|
|
|
|
|
// config default and config-include-path passed - but no config files in the include path - only in the default path
|
2018-07-28 08:13:30 -04:00
|
|
|
// rm command is split below because code counter is confused by what looks like a comment.
|
2018-04-19 11:09:39 -04:00
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
2018-07-28 08:13:30 -04:00
|
|
|
TEST_RESULT_INT(system(strPtr(strNewFmt("sudo rm -rf %s/" "*", strPtr(configIncludePath)))), 0, "remove all include files");
|
2018-04-19 11:09:39 -04:00
|
|
|
|
|
|
|
parseOptionList[cfgOptConfig].found = false;
|
|
|
|
parseOptionList[cfgOptConfig].source = cfgSourceDefault;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].found = true;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].source = cfgSourceParam;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].valueList = strLstAdd(strLstNew(), configIncludePath);
|
|
|
|
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, configFile,
|
|
|
|
backupCmdDefConfigInclPathValue, oldConfigDefault)),
|
|
|
|
"[global]\n"
|
|
|
|
"compress-level=3\n"
|
|
|
|
"spool-path=/path/to/spool\n",
|
|
|
|
"config default exists with files but config-include-path path passed is empty - only config read");
|
|
|
|
|
|
|
|
// config default and config-include-path passed - only empty file in the include path and nothing in either config defaults
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_RESULT_INT(system(strPtr(strNewFmt("touch %s", strPtr(strNewFmt("%s/empty.conf", strPtr(configIncludePath)))))), 0,
|
|
|
|
"add empty conf file to include directory");
|
|
|
|
|
|
|
|
parseOptionList[cfgOptConfig].found = false;
|
|
|
|
parseOptionList[cfgOptConfig].source = cfgSourceDefault;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].found = true;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].source = cfgSourceParam;
|
|
|
|
parseOptionList[cfgOptConfigIncludePath].valueList = strLstAdd(strLstNew(), configIncludePath);
|
|
|
|
|
|
|
|
TEST_RESULT_STR(strPtr(cfgFileLoad(parseOptionList, backupCmdDefConfigValue,
|
|
|
|
backupCmdDefConfigInclPathValue, backupCmdDefConfigValue)),
|
|
|
|
NULL,
|
|
|
|
"config default does not exist, config-include-path passed but only empty conf file - nothing read");
|
|
|
|
}
|
|
|
|
|
2018-09-16 14:15:21 -04:00
|
|
|
// *****************************************************************************************************************************
|
2018-04-25 15:46:05 -04:00
|
|
|
if (testBegin("convertToByte()"))
|
|
|
|
{
|
|
|
|
double valueDbl = 0;
|
|
|
|
String *value = strNew("10.0");
|
|
|
|
|
|
|
|
TEST_ERROR(convertToByte(&value, &valueDbl), FormatError, "value '10.0' is not valid");
|
|
|
|
strTrunc(value, strChr(value, '.'));
|
|
|
|
strCat(value, "K2");
|
|
|
|
TEST_ERROR(convertToByte(&value, &valueDbl), FormatError, "value '10K2' is not valid");
|
|
|
|
strTrunc(value, strChr(value, '1'));
|
|
|
|
strCat(value, "ab");
|
|
|
|
TEST_ERROR(convertToByte(&value, &valueDbl), FormatError, "value 'ab' is not valid");
|
|
|
|
|
|
|
|
strTrunc(value, strChr(value, 'a'));
|
|
|
|
strCat(value, "10");
|
|
|
|
convertToByte(&value, &valueDbl);
|
|
|
|
TEST_RESULT_DOUBLE(valueDbl, 10, "valueDbl no character identifier - straight to bytes");
|
|
|
|
TEST_RESULT_STR(strPtr(value), "10", "value no character identifier - straight to bytes");
|
|
|
|
|
|
|
|
strCat(value, "B");
|
|
|
|
convertToByte(&value, &valueDbl);
|
|
|
|
TEST_RESULT_DOUBLE(valueDbl, 10, "valueDbl B to bytes");
|
|
|
|
TEST_RESULT_STR(strPtr(value), "10", "value B to bytes");
|
|
|
|
|
|
|
|
strCat(value, "Kb");
|
|
|
|
convertToByte(&value, &valueDbl);
|
|
|
|
TEST_RESULT_DOUBLE(valueDbl, 10240, "valueDbl KB to bytes");
|
|
|
|
TEST_RESULT_STR(strPtr(value), "10240", "value KB to bytes");
|
|
|
|
|
|
|
|
strTrunc(value, strChr(value, '2'));
|
|
|
|
strCat(value, "k");
|
|
|
|
convertToByte(&value, &valueDbl);
|
|
|
|
TEST_RESULT_DOUBLE(valueDbl, 10240, "valueDbl k to bytes");
|
|
|
|
TEST_RESULT_STR(strPtr(value), "10240", "value k to bytes");
|
|
|
|
|
|
|
|
strCat(value, "pB");
|
|
|
|
convertToByte(&value, &valueDbl);
|
|
|
|
TEST_RESULT_DOUBLE(valueDbl, 11529215046068469760U, "valueDbl Pb to bytes");
|
|
|
|
TEST_RESULT_STR(strPtr(value), "11529215046068469760", "value Pb to bytes");
|
|
|
|
|
|
|
|
strTrunc(value, strChr(value, '5'));
|
|
|
|
strCat(value, "GB");
|
|
|
|
convertToByte(&value, &valueDbl);
|
|
|
|
TEST_RESULT_DOUBLE(valueDbl, 11811160064U, "valueDbl GB to bytes");
|
|
|
|
TEST_RESULT_STR(strPtr(value), "11811160064", "value GB to bytes");
|
|
|
|
|
|
|
|
strTrunc(value, strChr(value, '8'));
|
|
|
|
strCat(value, "g");
|
|
|
|
convertToByte(&value, &valueDbl);
|
|
|
|
TEST_RESULT_DOUBLE(valueDbl, 11811160064U, "valueDbl g to bytes");
|
|
|
|
TEST_RESULT_STR(strPtr(value), "11811160064", "value g to bytes");
|
|
|
|
|
|
|
|
strTrunc(value, strChr(value, '8'));
|
|
|
|
strCat(value, "T");
|
|
|
|
convertToByte(&value, &valueDbl);
|
|
|
|
TEST_RESULT_DOUBLE(valueDbl, 12094627905536U, "valueDbl T to bytes");
|
|
|
|
TEST_RESULT_STR(strPtr(value), "12094627905536", "value T to bytes");
|
|
|
|
|
|
|
|
strTrunc(value, strChr(value, '0'));
|
|
|
|
strCat(value, "tb");
|
|
|
|
convertToByte(&value, &valueDbl);
|
|
|
|
TEST_RESULT_DOUBLE(valueDbl, 13194139533312U, "valueDbl tb to bytes");
|
|
|
|
TEST_RESULT_STR(strPtr(value), "13194139533312", "value tb to bytes");
|
|
|
|
|
|
|
|
strTrunc(value, strChr(value, '3'));
|
|
|
|
strCat(value, "0m");
|
|
|
|
convertToByte(&value, &valueDbl);
|
|
|
|
TEST_RESULT_DOUBLE(valueDbl, 10485760, "valueDbl m to bytes");
|
|
|
|
TEST_RESULT_STR(strPtr(value), "10485760", "value m to bytes");
|
|
|
|
|
|
|
|
strCat(value, "mb");
|
|
|
|
convertToByte(&value, &valueDbl);
|
|
|
|
TEST_RESULT_DOUBLE(valueDbl, 10995116277760U, "valueDbl mb to bytes");
|
|
|
|
TEST_RESULT_STR(strPtr(value), "10995116277760", "value mb to bytes");
|
|
|
|
|
|
|
|
strTrunc(value, strChr(value, '0'));
|
|
|
|
strCat(value, "99999999999999999999p");
|
|
|
|
convertToByte(&value, &valueDbl);
|
|
|
|
TEST_RESULT_STR(strPtr(value), "225179981368524800000000000000000000", "value really large to bytes");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-16 14:15:21 -04:00
|
|
|
// *****************************************************************************************************************************
|
2017-12-22 23:27:49 -05:00
|
|
|
if (testBegin("configParse()"))
|
2017-11-28 21:44:05 -05:00
|
|
|
{
|
2017-12-22 23:27:49 -05:00
|
|
|
StringList *argList = NULL;
|
|
|
|
String *configFile = strNewFmt("%s/test.config", testPath());
|
|
|
|
|
2018-08-11 12:55:33 -04:00
|
|
|
TEST_RESULT_INT(
|
|
|
|
sizeof(optionResolveOrder) / sizeof(ConfigOption), CFG_OPTION_TOTAL,
|
|
|
|
"check that the option resolve list contains an entry for every option");
|
|
|
|
|
2017-12-22 23:27:49 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew(BOGUS_STR));
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_ERROR(configParse(strLstSize(argList), strLstPtr(argList), false), CommandInvalidError, "invalid command 'BOGUS'");
|
2017-12-22 23:27:49 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--" BOGUS_STR));
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_ERROR(configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError, "invalid option '--BOGUS'");
|
2017-12-22 23:27:49 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-host"));
|
2017-12-22 23:27:49 -05:00
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
|
|
|
"option '--pg1-host' requires argument");
|
2017-12-22 23:27:49 -05:00
|
|
|
|
2019-03-09 11:03:47 +02:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("backup"));
|
|
|
|
strLstAdd(argList, strNew("param1"));
|
|
|
|
TEST_ERROR(
|
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), ParamInvalidError, "command does not allow parameters");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("help"));
|
|
|
|
strLstAdd(argList, strNew("backup"));
|
|
|
|
strLstAdd(argList, strNew("param1"));
|
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), "ignore params when help command");
|
|
|
|
|
2017-12-22 23:27:49 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--no-online"));
|
|
|
|
strLstAdd(argList, strNew("--no-online"));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
|
|
|
"option 'online' is negated multiple times");
|
2017-12-05 10:09:07 -05:00
|
|
|
|
2018-02-06 11:26:06 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--reset-pg1-host"));
|
|
|
|
strLstAdd(argList, strNew("--reset-pg1-host"));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
|
|
|
"option 'pg1-host' is reset multiple times");
|
2018-02-06 11:26:06 -05:00
|
|
|
|
2017-12-22 23:27:49 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
2017-11-28 21:44:05 -05:00
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--no-config"));
|
2018-03-21 13:46:08 -04:00
|
|
|
strLstAdd(argList, strNew("--config=/etc/config"));
|
2017-12-22 23:27:49 -05:00
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
|
|
|
"option 'config' cannot be set and negated");
|
2017-12-05 10:09:07 -05:00
|
|
|
|
2018-02-06 11:26:06 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--reset-log-path"));
|
2018-03-21 13:46:08 -04:00
|
|
|
strLstAdd(argList, strNew("--log-path=/var/log"));
|
2018-02-06 11:26:06 -05:00
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
|
|
|
"option 'log-path' cannot be set and reset");
|
2018-02-06 11:26:06 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--no-compress"));
|
|
|
|
strLstAdd(argList, strNew("--reset-compress"));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
2018-02-06 11:26:06 -05:00
|
|
|
"option 'compress' cannot be negated and reset");
|
|
|
|
|
2018-03-21 13:46:08 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--reset-compress"));
|
|
|
|
strLstAdd(argList, strNew("--no-compress"));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
2018-03-21 13:46:08 -04:00
|
|
|
"option 'compress' cannot be negated and reset");
|
|
|
|
|
2018-08-22 16:45:25 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--compress"));
|
|
|
|
strLstAdd(argList, strNew("--compress"));
|
|
|
|
TEST_ERROR(
|
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
|
|
|
"option 'compress' cannot be set multiple times");
|
|
|
|
|
2017-12-05 10:09:07 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2017-12-22 23:27:49 -05:00
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-03-08 14:15:05 -05:00
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
2018-08-11 09:47:07 -04:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--compress-level=3"));
|
|
|
|
strLstAdd(argList, strNew("--compress-level=3"));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
2018-09-27 17:48:40 +01:00
|
|
|
"option 'compress-level' cannot be set multiple times");
|
2017-12-22 23:27:49 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2017-12-05 10:09:07 -05:00
|
|
|
strLstAdd(argList, strNew("--online"));
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_ERROR(configParse(strLstSize(argList), strLstPtr(argList), false), CommandRequiredError, "no command found");
|
2017-11-28 21:44:05 -05:00
|
|
|
|
2018-04-25 15:46:05 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
2018-08-11 09:47:07 -04:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
2018-04-25 15:46:05 -04:00
|
|
|
strLstAdd(argList, strNew("--manifest-save-threshold=123Q"));
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_ERROR(configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
2018-04-25 15:46:05 -04:00
|
|
|
"'123Q' is not valid for 'manifest-save-threshold' option");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
2018-08-11 09:47:07 -04:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
2018-04-25 15:46:05 -04:00
|
|
|
strLstAdd(argList, strNew("--manifest-save-threshold=199999999999999999999p"));
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_ERROR(configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
2018-04-25 15:46:05 -04:00
|
|
|
"'225179981368524800000000000000000000' is out of range for 'manifest-save-threshold' option");
|
|
|
|
|
2019-03-14 13:48:33 +04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--pg1-path="));
|
|
|
|
TEST_ERROR(configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
|
|
|
"'' must be >= 1 character for 'pg1-path' option");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--pg1-path=bogus"));
|
|
|
|
TEST_ERROR(configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
|
|
|
"'bogus' must begin with / for 'pg1-path' option");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path1//path2"));
|
|
|
|
TEST_ERROR(configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
|
|
|
"'/path1//path2' cannot contain // for 'pg1-path' option");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path1/path2//"));
|
|
|
|
TEST_ERROR(configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
|
|
|
"'/path1/path2//' cannot contain // for 'pg1-path' option");
|
|
|
|
|
2018-04-25 15:46:05 -04:00
|
|
|
// Local and remove commands should not modify log levels during parsing
|
2018-03-21 13:46:08 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew("pgbackrest"));
|
|
|
|
strLstAdd(argList, strNew("--host-id=1"));
|
|
|
|
strLstAdd(argList, strNew("--process=1"));
|
|
|
|
strLstAdd(argList, strNew("--command=backup"));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--type=backup"));
|
|
|
|
strLstAdd(argList, strNew("--log-level-stderr=info"));
|
|
|
|
strLstAdd(argList, strNew("local"));
|
|
|
|
|
|
|
|
logLevelStdOut = logLevelError;
|
|
|
|
logLevelStdErr = logLevelError;
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), "load local config");
|
2018-03-21 13:46:08 -04:00
|
|
|
TEST_RESULT_INT(logLevelStdOut, logLevelError, "console logging is error");
|
|
|
|
TEST_RESULT_INT(logLevelStdErr, logLevelError, "stderr logging is error");
|
|
|
|
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew("pgbackrest"));
|
|
|
|
strLstAdd(argList, strNew("--process=1"));
|
|
|
|
strLstAdd(argList, strNew("--command=backup"));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--type=backup"));
|
|
|
|
strLstAdd(argList, strNew("--log-level-stderr=info"));
|
|
|
|
strLstAdd(argList, strNew("remote"));
|
|
|
|
|
|
|
|
logLevelStdOut = logLevelError;
|
|
|
|
logLevelStdErr = logLevelError;
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), "load remote config");
|
2018-03-21 13:46:08 -04:00
|
|
|
TEST_RESULT_INT(logLevelStdOut, logLevelError, "console logging is error");
|
|
|
|
TEST_RESULT_INT(logLevelStdErr, logLevelError, "stderr logging is error");
|
2018-08-15 10:52:53 -04:00
|
|
|
harnessLogLevelReset();
|
2018-03-21 13:46:08 -04:00
|
|
|
|
2017-11-28 21:44:05 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2017-12-22 23:27:49 -05:00
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-08-11 09:47:07 -04:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionRequiredError,
|
2018-02-03 18:27:38 -05:00
|
|
|
"backup command requires option: pg1-path\nHINT: does this stanza exist?");
|
2017-11-28 21:44:05 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2017-12-22 23:27:49 -05:00
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionRequiredError,
|
2017-12-22 23:27:49 -05:00
|
|
|
"backup command requires option: stanza");
|
2017-11-28 21:44:05 -05:00
|
|
|
|
2018-03-15 12:02:09 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--repo1-type=s3"));
|
|
|
|
strLstAdd(argList, strNew("--repo1-s3-key=xxx"));
|
2018-08-11 12:55:33 -04:00
|
|
|
strLstAdd(argList, strNew("--repo1-s3-bucket=xxx"));
|
|
|
|
strLstAdd(argList, strNew("--repo1-s3-endpoint=xxx"));
|
2018-03-15 12:02:09 -04:00
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
2018-03-15 12:02:09 -04:00
|
|
|
"option 'repo1-s3-key' is not allowed on the command-line\n"
|
|
|
|
"HINT: this option could expose secrets in the process list.\n"
|
2018-08-30 18:44:40 -04:00
|
|
|
"HINT: specify the option in a configuration file or an environment variable instead.");
|
2018-03-15 12:02:09 -04:00
|
|
|
|
2017-11-28 21:44:05 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2017-12-22 23:27:49 -05:00
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--no-config"));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
2018-08-30 18:44:40 -04:00
|
|
|
strLstAdd(argList, strNew("--repo1-s3-host=xxx"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
2018-03-15 11:09:46 -04:00
|
|
|
"option 'repo1-s3-host' not valid without option 'repo1-type' = 's3'");
|
2017-11-28 21:44:05 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2017-12-22 23:27:49 -05:00
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
|
|
|
strLstAdd(argList, strNew("--repo1-host-user=xxx"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
2018-02-05 11:50:09 -05:00
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
2017-12-22 23:27:49 -05:00
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
2018-02-03 18:27:38 -05:00
|
|
|
"option 'repo1-host-user' not valid without option 'repo1-host'");
|
2017-11-28 21:44:05 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--force"));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
2017-12-22 23:27:49 -05:00
|
|
|
"option 'force' not valid without option 'no-online'");
|
2017-11-28 21:44:05 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--test-delay=1"));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
2017-12-22 23:27:49 -05:00
|
|
|
"option 'test-delay' not valid without option 'test'");
|
2017-12-05 10:09:07 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--recovery-option=a=b"));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
2017-12-05 10:09:07 -05:00
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
2017-12-22 23:27:49 -05:00
|
|
|
"option 'recovery-option' not valid for command 'backup'");
|
2017-12-05 10:09:07 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--target-exclusive"));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
2017-12-05 10:09:07 -05:00
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
2017-12-22 23:27:49 -05:00
|
|
|
"option 'target-exclusive' not valid without option 'type' in ('time', 'xid')");
|
2017-12-05 10:09:07 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--type=bogus"));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
2017-12-05 10:09:07 -05:00
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
2018-04-25 15:46:05 -04:00
|
|
|
"'bogus' is not allowed for 'type' option");
|
2017-12-05 10:09:07 -05:00
|
|
|
|
2018-03-21 13:46:08 -04:00
|
|
|
// Lower and upper bounds for integer ranges
|
2017-12-05 10:09:07 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--process-max=0"));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
2017-12-05 10:09:07 -05:00
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
2018-04-25 15:46:05 -04:00
|
|
|
"'0' is out of range for 'process-max' option");
|
2017-12-22 23:27:49 -05:00
|
|
|
|
2018-03-21 13:46:08 -04:00
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--process-max=65536"));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
2018-04-25 15:46:05 -04:00
|
|
|
"'65536' is out of range for 'process-max' option");
|
2018-03-21 13:46:08 -04:00
|
|
|
|
2017-12-22 23:27:49 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--process-max=bogus"));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
2017-12-22 23:27:49 -05:00
|
|
|
"'bogus' is not valid for 'process-max' option");
|
2017-12-05 10:09:07 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--protocol-timeout=.01"));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
2018-04-25 15:46:05 -04:00
|
|
|
"'.01' is out of range for 'protocol-timeout' option");
|
2017-12-22 23:27:49 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew("--protocol-timeout=bogus"));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
2017-12-22 23:27:49 -05:00
|
|
|
"'bogus' is not valid for 'protocol-timeout' option");
|
|
|
|
|
2018-08-15 10:52:53 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
setenv("PGBACKREST_PROTOCOL_TIMEOUT", "", true);
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
|
|
|
TEST_ERROR(
|
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
|
|
|
"environment variable 'protocol-timeout' must have a value");
|
|
|
|
|
|
|
|
unsetenv("PGBACKREST_PROTOCOL_TIMEOUT");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
setenv("PGBACKREST_DELTA", "x", true);
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
|
|
|
TEST_ERROR(
|
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
|
|
|
"environment boolean option 'delta' must be 'y' or 'n'");
|
|
|
|
|
|
|
|
unsetenv("PGBACKREST_DELTA");
|
|
|
|
|
2017-12-22 23:27:49 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile)));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
|
2018-09-26 18:46:52 +01:00
|
|
|
storagePutNP(
|
|
|
|
storageNewWriteNP(storageLocalWrite(), configFile),
|
2019-04-20 08:16:17 -04:00
|
|
|
BUFSTRDEF(
|
2018-09-26 18:46:52 +01:00
|
|
|
"[global]\n"
|
|
|
|
"compress=bogus\n"));
|
2017-12-22 23:27:49 -05:00
|
|
|
|
|
|
|
TEST_ERROR(configParse(
|
2018-08-15 10:32:18 -04:00
|
|
|
strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
|
|
|
"boolean option 'compress' must be 'y' or 'n'");
|
2017-12-22 23:27:49 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile)));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
|
2018-09-26 18:46:52 +01:00
|
|
|
storagePutNP(
|
|
|
|
storageNewWriteNP(storageLocalWrite(), configFile),
|
2019-04-20 08:16:17 -04:00
|
|
|
BUFSTRDEF(
|
2018-09-26 18:46:52 +01:00
|
|
|
"[global]\n"
|
|
|
|
"compress=\n"));
|
2017-12-22 23:27:49 -05:00
|
|
|
|
|
|
|
TEST_ERROR(configParse(
|
2018-07-20 18:51:42 -04:00
|
|
|
strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError,
|
2017-12-22 23:27:49 -05:00
|
|
|
"section 'global', key 'compress' must have a value");
|
|
|
|
|
2018-02-05 15:48:26 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile)));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
|
2018-09-26 18:46:52 +01:00
|
|
|
storagePutNP(
|
|
|
|
storageNewWriteNP(storageLocalWrite(), configFile),
|
2019-04-20 08:16:17 -04:00
|
|
|
BUFSTRDEF(
|
2018-09-26 18:46:52 +01:00
|
|
|
"[db]\n"
|
|
|
|
"pg1-path=/path/to/db\n"
|
|
|
|
"db-path=/also/path/to/db\n"));
|
2018-02-05 15:48:26 -05:00
|
|
|
|
|
|
|
TEST_ERROR(configParse(
|
2018-07-20 18:51:42 -04:00
|
|
|
strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
2018-04-19 11:09:39 -04:00
|
|
|
strPtr(strNew("configuration file contains duplicate options ('db-path', 'pg1-path') in section '[db]'")));
|
2018-02-05 15:48:26 -05:00
|
|
|
|
2018-03-08 14:15:05 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile)));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
|
2018-09-26 18:46:52 +01:00
|
|
|
storagePutNP(
|
|
|
|
storageNewWriteNP(storageLocalWrite(), configFile),
|
2019-04-20 08:16:17 -04:00
|
|
|
BUFSTRDEF(
|
2018-09-26 18:46:52 +01:00
|
|
|
"[db]\n"
|
|
|
|
"pg1-path=/path/to/db\n"
|
|
|
|
"pg1-path=/also/path/to/db\n"));
|
2018-03-08 14:15:05 -05:00
|
|
|
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_ERROR(configParse(strLstSize(argList), strLstPtr(argList), false),
|
2018-03-08 14:15:05 -05:00
|
|
|
OptionInvalidError,
|
2018-09-27 17:48:40 +01:00
|
|
|
"option 'pg1-path' cannot be set multiple times");
|
|
|
|
|
|
|
|
// Also test with a boolean option since this gets converted immediately and will blow up if it is multi
|
|
|
|
storagePutNP(
|
|
|
|
storageNewWriteNP(storageLocalWrite(), configFile),
|
2019-04-20 08:16:17 -04:00
|
|
|
BUFSTRDEF(
|
2018-09-27 17:48:40 +01:00
|
|
|
"[db]\n"
|
|
|
|
"start-fast=y\n"
|
|
|
|
"start-fast=n\n"));
|
|
|
|
|
|
|
|
TEST_ERROR(configParse(strLstSize(argList), strLstPtr(argList), false),
|
|
|
|
OptionInvalidError,
|
|
|
|
"option 'start-fast' cannot be set multiple times");
|
2018-03-08 14:15:05 -05:00
|
|
|
|
2018-07-20 18:51:42 -04:00
|
|
|
// Test that log levels are set correctly when reset is enabled, then set them back to harness defaults
|
2017-12-22 23:27:49 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
|
2018-07-20 18:51:42 -04:00
|
|
|
logLevelStdOut = logLevelOff;
|
|
|
|
logLevelStdErr = logLevelOff;
|
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), true), "no command");
|
2017-12-22 23:27:49 -05:00
|
|
|
TEST_RESULT_BOOL(cfgCommandHelp(), true, " help is set");
|
|
|
|
TEST_RESULT_INT(cfgCommand(), cfgCmdNone, " command is none");
|
2018-03-21 13:46:08 -04:00
|
|
|
TEST_RESULT_INT(logLevelStdOut, logLevelWarn, "console logging is warn");
|
|
|
|
TEST_RESULT_INT(logLevelStdErr, logLevelWarn, "stderr logging is warn");
|
2018-07-20 19:03:46 -04:00
|
|
|
harnessLogLevelReset();
|
2017-12-22 23:27:49 -05:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("help"));
|
|
|
|
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), "help command");
|
2017-12-22 23:27:49 -05:00
|
|
|
TEST_RESULT_BOOL(cfgCommandHelp(), true, " help is set");
|
|
|
|
TEST_RESULT_INT(cfgCommand(), cfgCmdHelp, " command is help");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("help"));
|
|
|
|
strLstAdd(argList, strNew("version"));
|
|
|
|
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), "help for version command");
|
2017-12-22 23:27:49 -05:00
|
|
|
TEST_RESULT_BOOL(cfgCommandHelp(), true, " help is set");
|
|
|
|
TEST_RESULT_INT(cfgCommand(), cfgCmdVersion, " command is version");
|
|
|
|
|
2018-03-21 13:46:08 -04:00
|
|
|
// Help should not fail on missing options
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("help"));
|
|
|
|
strLstAdd(argList, strNew("backup"));
|
|
|
|
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), "help for backup command");
|
2018-03-21 13:46:08 -04:00
|
|
|
TEST_RESULT_BOOL(cfgCommandHelp(), true, " help is set");
|
|
|
|
TEST_RESULT_INT(cfgCommand(), cfgCmdBackup, " command is backup");
|
|
|
|
TEST_RESULT_BOOL(cfgOptionValid(cfgOptPgPath), true, " pg1-path is valid");
|
|
|
|
TEST_RESULT_PTR(cfgOption(cfgOptPgPath), NULL, " pg1-path is not set");
|
|
|
|
|
2017-12-22 23:27:49 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
2017-12-05 10:09:07 -05:00
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_ARCHIVE_GET));
|
|
|
|
strLstAdd(argList, strNew("000000010000000200000003"));
|
|
|
|
strLstAdd(argList, strNew("/path/to/wal/RECOVERYWAL"));
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), "command arguments");
|
2017-12-05 10:09:07 -05:00
|
|
|
TEST_RESULT_STR(
|
2017-12-22 23:27:49 -05:00
|
|
|
strPtr(strLstJoin(cfgCommandParam(), "|")), "000000010000000200000003|/path/to/wal/RECOVERYWAL",
|
2017-12-05 10:09:07 -05:00
|
|
|
" check command arguments");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
2019-03-14 13:48:33 +04:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db/"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--no-online"));
|
2018-02-06 11:26:06 -05:00
|
|
|
strLstAdd(argList, strNew("--no-config"));
|
2018-08-30 18:44:40 -04:00
|
|
|
strLstAdd(argList, strNew("--repo1-type=s3"));
|
|
|
|
strLstAdd(argList, strNew("--repo1-s3-bucket=test"));
|
|
|
|
strLstAdd(argList, strNew("--repo1-s3-endpoint=test"));
|
|
|
|
strLstAdd(argList, strNew("--repo1-s3-region=test"));
|
2017-12-05 10:09:07 -05:00
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
2018-08-30 18:44:40 -04:00
|
|
|
setenv("PGBACKREST_REPO1_S3_KEY", "xxx", true);
|
|
|
|
setenv("PGBACKREST_REPO1_S3_KEY_SECRET", "xxx", true);
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), TEST_COMMAND_BACKUP " command");
|
2017-12-22 23:27:49 -05:00
|
|
|
TEST_RESULT_INT(cfgCommand(), cfgCmdBackup, " command is " TEST_COMMAND_BACKUP);
|
|
|
|
|
|
|
|
TEST_RESULT_STR(strPtr(cfgExe()), TEST_BACKREST_EXE, " exe is set");
|
|
|
|
|
2018-03-05 18:51:48 -05:00
|
|
|
TEST_RESULT_BOOL(cfgOptionTest(cfgOptConfig), false, " config is not set");
|
2018-02-06 11:26:06 -05:00
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptConfig), cfgSourceParam, " config is source param");
|
|
|
|
TEST_RESULT_BOOL(cfgOptionNegate(cfgOptConfig), true, " config is negated");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptStanza), cfgSourceParam, " stanza is source param");
|
2017-12-22 23:27:49 -05:00
|
|
|
TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptStanza)), "db", " stanza is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptStanza), cfgSourceParam, " stanza is source param");
|
2018-02-03 18:27:38 -05:00
|
|
|
TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptPgPath)), "/path/to/db", " pg1-path is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptPgPath), cfgSourceParam, " pg1-path is source param");
|
2018-08-30 18:44:40 -04:00
|
|
|
TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptRepoS3KeySecret)), "xxx", " repo1-s3-secret is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptRepoS3KeySecret), cfgSourceConfig, " repo1-s3-secret is source env");
|
2017-12-22 23:27:49 -05:00
|
|
|
TEST_RESULT_BOOL(cfgOptionBool(cfgOptOnline), false, " online is not set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptOnline), cfgSourceParam, " online is source default");
|
|
|
|
TEST_RESULT_BOOL(cfgOptionBool(cfgOptCompress), true, " compress is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptCompress), cfgSourceDefault, " compress is source default");
|
2018-01-16 13:52:20 -05:00
|
|
|
TEST_RESULT_INT(cfgOptionInt(cfgOptBufferSize), 4194304, " buffer-size is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptBufferSize), cfgSourceDefault, " buffer-size is source default");
|
2017-12-22 23:27:49 -05:00
|
|
|
|
2018-08-30 18:44:40 -04:00
|
|
|
unsetenv("PGBACKREST_REPO1_S3_KEY");
|
|
|
|
unsetenv("PGBACKREST_REPO1_S3_KEY_SECRET");
|
|
|
|
|
2017-12-22 23:27:49 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile)));
|
|
|
|
strLstAdd(argList, strNew("--no-online"));
|
2018-02-06 11:26:06 -05:00
|
|
|
strLstAdd(argList, strNew("--reset-pg1-host"));
|
2018-02-13 15:58:14 -05:00
|
|
|
strLstAdd(argList, strNew("--reset-backup-standby"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
|
|
|
|
2018-08-15 10:52:53 -04:00
|
|
|
setenv("PGBACKRESTXXX_NOTHING", "xxx", true);
|
|
|
|
setenv("PGBACKREST_BOGUS", "xxx", true);
|
|
|
|
setenv("PGBACKREST_NO_COMPRESS", "xxx", true);
|
|
|
|
setenv("PGBACKREST_RESET_REPO1_HOST", "", true);
|
|
|
|
setenv("PGBACKREST_TARGET", "xxx", true);
|
|
|
|
setenv("PGBACKREST_ONLINE", "y", true);
|
|
|
|
setenv("PGBACKREST_START_FAST", "n", true);
|
|
|
|
setenv("PGBACKREST_PG1_SOCKET_PATH", "/path/to/socket", true);
|
|
|
|
|
2018-09-26 18:46:52 +01:00
|
|
|
storagePutNP(
|
|
|
|
storageNewWriteNP(storageLocalWrite(), configFile),
|
2019-04-20 08:16:17 -04:00
|
|
|
BUFSTRDEF(
|
2018-09-26 18:46:52 +01:00
|
|
|
"[global]\n"
|
|
|
|
"compress-level=3\n"
|
|
|
|
"spool-path=/path/to/spool\n"
|
|
|
|
"\n"
|
|
|
|
"[global:backup]\n"
|
|
|
|
"repo1-hardlink=y\n"
|
|
|
|
"bogus=bogus\n"
|
|
|
|
"no-compress=y\n"
|
|
|
|
"reset-compress=y\n"
|
|
|
|
"archive-copy=y\n"
|
|
|
|
"start-fast=y\n"
|
|
|
|
"online=y\n"
|
|
|
|
"pg1-path=/not/path/to/db\n"
|
|
|
|
"backup-standby=y\n"
|
|
|
|
"buffer-size=65536\n"
|
|
|
|
"\n"
|
|
|
|
"[db:backup]\n"
|
|
|
|
"compress=n\n"
|
|
|
|
"recovery-option=a=b\n"
|
|
|
|
"\n"
|
|
|
|
"[db]\n"
|
|
|
|
"pg1-host=db\n"
|
|
|
|
"pg1-path=/path/to/db\n"
|
|
|
|
"recovery-option=c=d\n"));
|
2017-12-22 23:27:49 -05:00
|
|
|
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), TEST_COMMAND_BACKUP " command");
|
|
|
|
harnessLogResult(
|
2018-01-28 21:37:09 -05:00
|
|
|
strPtr(
|
2018-04-19 11:09:39 -04:00
|
|
|
strNew(
|
2018-08-15 10:52:53 -04:00
|
|
|
"P00 WARN: environment contains invalid option 'bogus'\n"
|
|
|
|
"P00 WARN: environment contains invalid negate option 'no-compress'\n"
|
|
|
|
"P00 WARN: environment contains invalid reset option 'reset-repo1-host'\n"
|
2018-07-20 18:51:42 -04:00
|
|
|
"P00 WARN: configuration file contains option 'recovery-option' invalid for section 'db:backup'\n"
|
|
|
|
"P00 WARN: configuration file contains invalid option 'bogus'\n"
|
|
|
|
"P00 WARN: configuration file contains negate option 'no-compress'\n"
|
|
|
|
"P00 WARN: configuration file contains reset option 'reset-compress'\n"
|
|
|
|
"P00 WARN: configuration file contains command-line only option 'online'\n"
|
|
|
|
"P00 WARN: configuration file contains stanza-only option 'pg1-path' in global section 'global:backup'")));
|
2017-12-22 23:27:49 -05:00
|
|
|
|
2018-03-08 14:15:05 -05:00
|
|
|
TEST_RESULT_BOOL(cfgOptionTest(cfgOptPgHost), false, " pg1-host is not set (command line reset override)");
|
2018-02-03 18:27:38 -05:00
|
|
|
TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptPgPath)), "/path/to/db", " pg1-path is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptPgPath), cfgSourceConfig, " pg1-path is source config");
|
2018-08-15 10:52:53 -04:00
|
|
|
TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptPgSocketPath)), "/path/to/socket", " pg1-socket-path is set");
|
2018-08-30 18:44:40 -04:00
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptPgSocketPath), cfgSourceConfig, " pg1-socket-path is config param");
|
2018-08-15 10:52:53 -04:00
|
|
|
TEST_RESULT_BOOL(cfgOptionBool(cfgOptOnline), false, " online not is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptOnline), cfgSourceParam, " online is source param");
|
|
|
|
TEST_RESULT_BOOL(cfgOptionBool(cfgOptStartFast), false, " start-fast not is set");
|
2018-08-30 18:44:40 -04:00
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptStartFast), cfgSourceConfig, " start-fast is config param");
|
2017-12-22 23:27:49 -05:00
|
|
|
TEST_RESULT_BOOL(cfgOptionBool(cfgOptCompress), false, " compress not is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptCompress), cfgSourceConfig, " compress is source config");
|
2018-03-05 18:51:48 -05:00
|
|
|
TEST_RESULT_BOOL(cfgOptionTest(cfgOptArchiveCheck), false, " archive-check is not set");
|
|
|
|
TEST_RESULT_BOOL(cfgOptionTest(cfgOptArchiveCopy), false, " archive-copy is not set");
|
2018-02-03 18:27:38 -05:00
|
|
|
TEST_RESULT_BOOL(cfgOptionBool(cfgOptRepoHardlink), true, " repo-hardlink is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptRepoHardlink), cfgSourceConfig, " repo-hardlink is source config");
|
2017-12-22 23:27:49 -05:00
|
|
|
TEST_RESULT_INT(cfgOptionInt(cfgOptCompressLevel), 3, " compress-level is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptCompressLevel), cfgSourceConfig, " compress-level is source config");
|
2018-02-13 15:58:14 -05:00
|
|
|
TEST_RESULT_BOOL(cfgOptionBool(cfgOptBackupStandby), false, " backup-standby not is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptBackupStandby), cfgSourceDefault, " backup-standby is source default");
|
2018-03-21 13:46:08 -04:00
|
|
|
TEST_RESULT_BOOL(cfgOptionInt64(cfgOptBufferSize), 65536, " buffer-size is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptBufferSize), cfgSourceConfig, " backup-standby is source config");
|
2017-12-05 10:09:07 -05:00
|
|
|
|
2018-08-15 10:52:53 -04:00
|
|
|
unsetenv("PGBACKREST_BOGUS");
|
|
|
|
unsetenv("PGBACKREST_NO_COMPRESS");
|
|
|
|
unsetenv("PGBACKREST_RESET_REPO1_HOST");
|
|
|
|
unsetenv("PGBACKREST_TARGET");
|
|
|
|
unsetenv("PGBACKREST_ONLINE");
|
|
|
|
unsetenv("PGBACKREST_START_FAST");
|
|
|
|
unsetenv("PGBACKREST_PG1_SOCKET_PATH");
|
|
|
|
|
2018-02-09 13:54:33 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-03-21 13:46:08 -04:00
|
|
|
strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile)));
|
2018-02-09 13:54:33 -05:00
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
2018-04-18 19:37:35 -04:00
|
|
|
strLstAdd(argList, strNew("--archive-push-queue-max=4503599627370496"));
|
2018-04-25 15:46:05 -04:00
|
|
|
strLstAdd(argList, strNew("--buffer-size=2MB"));
|
2018-02-09 13:54:33 -05:00
|
|
|
strLstAdd(argList, strNew("archive-push"));
|
|
|
|
|
2018-09-26 18:46:52 +01:00
|
|
|
storagePutNP(
|
|
|
|
storageNewWriteNP(storageLocalWrite(), configFile),
|
2019-04-20 08:16:17 -04:00
|
|
|
BUFSTRDEF(
|
2018-09-26 18:46:52 +01:00
|
|
|
"[global]\n"
|
|
|
|
"spool-path=/path/to/spool\n"));
|
2018-03-21 13:46:08 -04:00
|
|
|
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), "archive-push command");
|
2018-02-09 13:54:33 -05:00
|
|
|
|
2018-04-18 19:37:35 -04:00
|
|
|
TEST_RESULT_INT(cfgOptionInt64(cfgOptArchivePushQueueMax), 4503599627370496, "archive-push-queue-max is set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptArchivePushQueueMax), cfgSourceParam, " archive-push-queue-max is source config");
|
2018-04-25 15:46:05 -04:00
|
|
|
TEST_RESULT_INT(cfgOptionInt64(cfgOptBufferSize), 2097152, "buffer-size is set to bytes from MB");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptBufferSize), cfgSourceParam, " buffer-size is source config");
|
2018-03-21 13:46:08 -04:00
|
|
|
TEST_RESULT_PTR(cfgOption(cfgOptSpoolPath), NULL, " spool-path is not set");
|
|
|
|
TEST_RESULT_INT(cfgOptionSource(cfgOptSpoolPath), cfgSourceDefault, " spool-path is source default");
|
2018-02-09 13:54:33 -05:00
|
|
|
|
2017-12-05 10:09:07 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--recovery-option=a"));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
2017-12-05 10:09:07 -05:00
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
2017-12-22 23:27:49 -05:00
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
2017-12-22 23:27:49 -05:00
|
|
|
"key/value 'a' not valid for 'recovery-option' option");
|
2017-12-05 10:09:07 -05:00
|
|
|
|
2017-12-22 23:27:49 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
2017-12-05 10:09:07 -05:00
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--recovery-option=a"));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
|
|
|
TEST_ERROR(
|
2018-07-20 18:51:42 -04:00
|
|
|
configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError,
|
2017-12-22 23:27:49 -05:00
|
|
|
"key/value 'a' not valid for 'recovery-option' option");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--db-include=abc"));
|
|
|
|
strLstAdd(argList, strNew("--db-include=def"));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), TEST_COMMAND_RESTORE " command");
|
2017-12-22 23:27:49 -05:00
|
|
|
|
|
|
|
const VariantList *includeList = NULL;
|
|
|
|
TEST_ASSIGN(includeList, cfgOptionLst(cfgOptDbInclude), "get db include options");
|
|
|
|
TEST_RESULT_STR(strPtr(varStr(varLstGet(includeList, 0))), "abc", "check db include option");
|
|
|
|
TEST_RESULT_STR(strPtr(varStr(varLstGet(includeList, 1))), "def", "check db include option");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
2018-02-03 18:27:38 -05:00
|
|
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
2017-12-22 23:27:49 -05:00
|
|
|
strLstAdd(argList, strNew("--recovery-option=a=b"));
|
|
|
|
strLstAdd(argList, strNew("--recovery-option=c=de=fg hi"));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), TEST_COMMAND_RESTORE " command");
|
2017-12-22 23:27:49 -05:00
|
|
|
|
|
|
|
const KeyValue *recoveryKv = NULL;
|
|
|
|
TEST_ASSIGN(recoveryKv, cfgOptionKv(cfgOptRecoveryOption), "get recovery options");
|
|
|
|
TEST_RESULT_STR(strPtr(varStr(kvGet(recoveryKv, varNewStr(strNew("a"))))), "b", "check recovery option");
|
|
|
|
TEST_RESULT_STR(strPtr(varStr(kvGet(recoveryKv, varNewStr(strNew("c"))))), "de=fg hi", "check recovery option");
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile)));
|
|
|
|
strLstAdd(argList, strNew("--stanza=db"));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
|
|
|
|
2018-09-26 18:46:52 +01:00
|
|
|
storagePutNP(
|
|
|
|
storageNewWriteNP(storageLocalWrite(), configFile),
|
2019-04-20 08:16:17 -04:00
|
|
|
BUFSTRDEF(
|
2018-09-26 18:46:52 +01:00
|
|
|
"[global:restore]\n"
|
|
|
|
"recovery-option=f=g\n"
|
|
|
|
"recovery-option=hijk=l\n"
|
|
|
|
"\n"
|
|
|
|
"[db]\n"
|
|
|
|
"pg1-path=/path/to/db\n"));
|
2017-12-22 23:27:49 -05:00
|
|
|
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), TEST_COMMAND_RESTORE " command");
|
2017-12-22 23:27:49 -05:00
|
|
|
|
|
|
|
TEST_ASSIGN(recoveryKv, cfgOptionKv(cfgOptRecoveryOption), "get recovery options");
|
|
|
|
TEST_RESULT_STR(strPtr(varStr(kvGet(recoveryKv, varNewStr(strNew("f"))))), "g", "check recovery option");
|
|
|
|
TEST_RESULT_STR(strPtr(varStr(kvGet(recoveryKv, varNewStr(strNew("hijk"))))), "l", "check recovery option");
|
2018-03-21 13:46:08 -04:00
|
|
|
|
2018-08-15 10:52:53 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNew(TEST_COMMAND_RESTORE));
|
|
|
|
|
|
|
|
setenv("PGBACKREST_STANZA", "db", true);
|
|
|
|
setenv("PGBACKREST_PG1_PATH", "/path/to/db", true);
|
|
|
|
setenv("PGBACKREST_RECOVERY_OPTION", "f=g:hijk=l", true);
|
|
|
|
setenv("PGBACKREST_DB_INCLUDE", "77", true);
|
|
|
|
|
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), TEST_COMMAND_RESTORE " command");
|
|
|
|
|
|
|
|
TEST_ASSIGN(recoveryKv, cfgOptionKv(cfgOptRecoveryOption), "get recovery options");
|
|
|
|
TEST_RESULT_STR(strPtr(varStr(kvGet(recoveryKv, varNewStr(strNew("f"))))), "g", "check recovery option");
|
|
|
|
TEST_RESULT_STR(strPtr(varStr(kvGet(recoveryKv, varNewStr(strNew("hijk"))))), "l", "check recovery option");
|
|
|
|
TEST_RESULT_STR(strPtr(varStr(varLstGet(cfgOptionLst(cfgOptDbInclude), 0))), "77", "check db include option");
|
|
|
|
TEST_RESULT_UINT(varLstSize(cfgOptionLst(cfgOptDbInclude)), 1, "check db include option size");
|
|
|
|
|
|
|
|
unsetenv("PGBACKREST_STANZA");
|
|
|
|
unsetenv("PGBACKREST_PG1_PATH");
|
|
|
|
unsetenv("PGBACKREST_RECOVERY_OPTION");
|
|
|
|
unsetenv("PGBACKREST_DB_INCLUDE");
|
|
|
|
|
2018-03-21 13:46:08 -04:00
|
|
|
// Stanza options should not be loaded for commands that don't take a stanza
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
argList = strLstNew();
|
|
|
|
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
|
|
|
strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile)));
|
|
|
|
strLstAdd(argList, strNew("info"));
|
|
|
|
|
2018-09-26 18:46:52 +01:00
|
|
|
storagePutNP(
|
|
|
|
storageNewWriteNP(storageLocalWrite(), configFile),
|
2019-04-20 08:16:17 -04:00
|
|
|
BUFSTRDEF(
|
2018-09-26 18:46:52 +01:00
|
|
|
"[global]\n"
|
|
|
|
"repo1-path=/path/to/repo\n"
|
|
|
|
"\n"
|
|
|
|
"[db]\n"
|
|
|
|
"repo1-path=/not/the/path\n"));
|
2018-03-21 13:46:08 -04:00
|
|
|
|
2018-07-20 18:51:42 -04:00
|
|
|
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), "info command");
|
2018-03-21 13:46:08 -04:00
|
|
|
TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptRepoPath)), "/path/to/repo", "check repo1-path option");
|
2017-11-28 21:44:05 -05:00
|
|
|
}
|
2018-02-03 18:27:38 -05:00
|
|
|
|
2018-09-16 14:15:21 -04:00
|
|
|
// *****************************************************************************************************************************
|
2018-02-03 18:27:38 -05:00
|
|
|
if (testBegin("deprecated option names"))
|
|
|
|
{
|
|
|
|
// Repository options
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
testOptionFind("hardlink", PARSE_DEPRECATE_FLAG | cfgOptRepoHardlink);
|
|
|
|
testOptionFind("no-hardlink", PARSE_DEPRECATE_FLAG | PARSE_NEGATE_FLAG | cfgOptRepoHardlink);
|
|
|
|
|
2018-04-18 19:37:35 -04:00
|
|
|
testOptionFind("archive-queue-max", PARSE_DEPRECATE_FLAG | cfgOptArchivePushQueueMax);
|
|
|
|
testOptionFind("reset-archive-queue-max", PARSE_DEPRECATE_FLAG | PARSE_RESET_FLAG | cfgOptArchivePushQueueMax);
|
|
|
|
|
2018-02-03 18:27:38 -05:00
|
|
|
testOptionFind("backup-cmd", PARSE_DEPRECATE_FLAG | cfgOptRepoHostCmd);
|
|
|
|
testOptionFind("backup-config", PARSE_DEPRECATE_FLAG | cfgOptRepoHostConfig);
|
|
|
|
testOptionFind("backup-host", PARSE_DEPRECATE_FLAG | cfgOptRepoHost);
|
|
|
|
testOptionFind("backup-ssh-port", PARSE_DEPRECATE_FLAG | cfgOptRepoHostPort);
|
|
|
|
testOptionFind("backup-user", PARSE_DEPRECATE_FLAG | cfgOptRepoHostUser);
|
|
|
|
|
|
|
|
testOptionFind("repo-cipher-pass", PARSE_DEPRECATE_FLAG | cfgOptRepoCipherPass);
|
|
|
|
testOptionFind("repo-cipher-type", PARSE_DEPRECATE_FLAG | cfgOptRepoCipherType);
|
|
|
|
testOptionFind("repo-path", PARSE_DEPRECATE_FLAG | cfgOptRepoPath);
|
|
|
|
testOptionFind("repo-type", PARSE_DEPRECATE_FLAG | cfgOptRepoType);
|
|
|
|
|
|
|
|
testOptionFind("repo-s3-bucket", PARSE_DEPRECATE_FLAG | cfgOptRepoS3Bucket);
|
|
|
|
testOptionFind("repo-s3-ca-file", PARSE_DEPRECATE_FLAG | cfgOptRepoS3CaFile);
|
|
|
|
testOptionFind("repo-s3-ca-path", PARSE_DEPRECATE_FLAG | cfgOptRepoS3CaPath);
|
|
|
|
testOptionFind("repo-s3-endpoint", PARSE_DEPRECATE_FLAG | cfgOptRepoS3Endpoint);
|
|
|
|
testOptionFind("repo-s3-host", PARSE_DEPRECATE_FLAG | cfgOptRepoS3Host);
|
|
|
|
testOptionFind("repo-s3-key", PARSE_DEPRECATE_FLAG | cfgOptRepoS3Key);
|
|
|
|
testOptionFind("repo-s3-key-secret", PARSE_DEPRECATE_FLAG | cfgOptRepoS3KeySecret);
|
|
|
|
testOptionFind("repo-s3-region", PARSE_DEPRECATE_FLAG | cfgOptRepoS3Region);
|
|
|
|
testOptionFind("repo-s3-verify-ssl", PARSE_DEPRECATE_FLAG | cfgOptRepoS3VerifySsl);
|
|
|
|
testOptionFind("no-repo-s3-verify-ssl", PARSE_DEPRECATE_FLAG | PARSE_NEGATE_FLAG | cfgOptRepoS3VerifySsl);
|
|
|
|
|
|
|
|
// PostreSQL options
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
testOptionFind("db-cmd", PARSE_DEPRECATE_FLAG | cfgOptPgHostCmd);
|
|
|
|
testOptionFind("db-config", PARSE_DEPRECATE_FLAG | cfgOptPgHostConfig);
|
|
|
|
testOptionFind("db-host", PARSE_DEPRECATE_FLAG | cfgOptPgHost);
|
|
|
|
testOptionFind("db-path", PARSE_DEPRECATE_FLAG | cfgOptPgPath);
|
|
|
|
testOptionFind("db-port", PARSE_DEPRECATE_FLAG | cfgOptPgPort);
|
|
|
|
testOptionFind("db-socket-path", PARSE_DEPRECATE_FLAG | cfgOptPgSocketPath);
|
|
|
|
testOptionFind("db-ssh-port", PARSE_DEPRECATE_FLAG | cfgOptPgHostPort);
|
|
|
|
testOptionFind("db-user", PARSE_DEPRECATE_FLAG | cfgOptPgHostUser);
|
|
|
|
|
|
|
|
testOptionFind("no-db-user", 0);
|
|
|
|
|
2018-03-02 12:07:12 -05:00
|
|
|
for (unsigned int optionIdx = 0; optionIdx < cfgDefOptionIndexTotal(cfgDefOptPgPath); optionIdx++)
|
2018-02-03 18:27:38 -05:00
|
|
|
{
|
|
|
|
testOptionFind(strPtr(strNewFmt("db%u-cmd", optionIdx + 1)), PARSE_DEPRECATE_FLAG | (cfgOptPgHostCmd + optionIdx));
|
|
|
|
testOptionFind(
|
|
|
|
strPtr(strNewFmt("db%u-config", optionIdx + 1)), PARSE_DEPRECATE_FLAG | (cfgOptPgHostConfig + optionIdx));
|
|
|
|
testOptionFind(strPtr(strNewFmt("db%u-host", optionIdx + 1)), PARSE_DEPRECATE_FLAG | (cfgOptPgHost + optionIdx));
|
|
|
|
testOptionFind(strPtr(strNewFmt("db%u-path", optionIdx + 1)), PARSE_DEPRECATE_FLAG | (cfgOptPgPath + optionIdx));
|
|
|
|
testOptionFind(strPtr(strNewFmt("db%u-port", optionIdx + 1)), PARSE_DEPRECATE_FLAG | (cfgOptPgPort + optionIdx));
|
|
|
|
testOptionFind(
|
|
|
|
strPtr(strNewFmt("db%u-socket-path", optionIdx + 1)), PARSE_DEPRECATE_FLAG | (cfgOptPgSocketPath + optionIdx));
|
|
|
|
testOptionFind(
|
|
|
|
strPtr(strNewFmt("db%u-ssh-port", optionIdx + 1)), PARSE_DEPRECATE_FLAG | (cfgOptPgHostPort + optionIdx));
|
|
|
|
testOptionFind(strPtr(strNewFmt("db%u-user", optionIdx + 1)), PARSE_DEPRECATE_FLAG | (cfgOptPgHostUser + optionIdx));
|
|
|
|
}
|
|
|
|
}
|
2018-05-18 11:57:32 -04:00
|
|
|
|
|
|
|
FUNCTION_HARNESS_RESULT_VOID();
|
2017-11-28 21:44:05 -05:00
|
|
|
}
|