1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-11-09 14:40:55 +03:00

Full branch coverage for config module.

This commit is contained in:
David Steele
2018-05-04 12:49:25 -04:00
parent 6c3b40152f
commit 90aadc6534
11 changed files with 274 additions and 270 deletions

View File

@@ -339,7 +339,7 @@ helpRender()
strCat(result, ": ");
for (int nameAltIdx = 0; nameAltIdx < cfgDefOptionHelpNameAltValueTotal(optionDefId); nameAltIdx++)
for (uint nameAltIdx = 0; nameAltIdx < cfgDefOptionHelpNameAltValueTotal(optionDefId); nameAltIdx++)
{
if (nameAltIdx != 0)
strCat(result, ", "); // {uncovered - no option has more than one alt name}

View File

@@ -33,7 +33,7 @@ DEBUG_UNIT_EXTERN int logHandleFile = -1;
static bool logFileBanner = false;
// Is the timestamp printed in the log?
static bool logTimestamp = false;
DEBUG_UNIT_EXTERN bool logTimestamp = false;
/***********************************************************************************************************************************
Debug Asserts

View File

@@ -33,6 +33,8 @@ Expose internal data for unit testing/debugging
extern int logHandleStdOut;
extern int logHandleStdErr;
extern int logHandleFile;
extern bool logTimestamp;
#endif
/***********************************************************************************************************************************

View File

@@ -5,6 +5,7 @@ Command and Option Configuration Definition
#include <stdint.h>
#include <string.h>
#include "common/assert.h"
#include "common/error.h"
#include "config/define.h"
@@ -177,7 +178,7 @@ Find optional data for a command and option.
static void
cfgDefDataFind(
ConfigDefineDataType typeFind, ConfigDefineCommand commandDefId, const void **dataList, bool *dataDefFound, int *dataDef,
const void ***dataDefList, int *dataDefListSize)
const void ***dataDefList, unsigned int *dataDefListSize)
{
*dataDefFound = false;
@@ -185,8 +186,8 @@ cfgDefDataFind(
if (dataList != NULL)
{
ConfigDefineDataType type;
int offset = 0;
int size;
unsigned int offset = 0;
unsigned int size;
int data;
unsigned int commandCurrent = UINT_MAX;
@@ -231,7 +232,7 @@ cfgDefDataFind(
#define CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, type) \
bool dataDefFound = false; \
int dataDef = 0; \
int dataDefListSize = 0; \
unsigned int dataDefListSize = 0; \
const void **dataDefList = NULL; \
\
cfgDefDataFind( \
@@ -310,19 +311,19 @@ cfgDefOptionAllowList(ConfigDefineCommand commandDefId, ConfigDefineOption optio
}
const char *
cfgDefOptionAllowListValue(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, int valueId)
cfgDefOptionAllowListValue(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, unsigned int valueId)
{
cfgDefCommandOptionCheck(commandDefId, optionDefId);
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeAllowList);
if (valueId < 0 || valueId >= dataDefListSize)
THROW_FMT(AssertError, "value id %d invalid - must be >= 0 and < %d", valueId, dataDefListSize);
if (valueId >= dataDefListSize)
THROW_FMT(AssertError, "value id %u invalid - must be >= 0 and < %u", valueId, dataDefListSize);
return (char *)dataDefList[valueId];
}
int
unsigned int
cfgDefOptionAllowListValueTotal(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId)
{
cfgDefCommandOptionCheck(commandDefId, optionDefId);
@@ -336,12 +337,11 @@ cfgDefOptionAllowListValueTotal(ConfigDefineCommand commandDefId, ConfigDefineOp
bool
cfgDefOptionAllowListValueValid(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, const char *value)
{
if (value != NULL)
{
for (int valueIdx = 0; valueIdx < cfgDefOptionAllowListValueTotal(commandDefId, optionDefId); valueIdx++)
if (strcmp(value, cfgDefOptionAllowListValue(commandDefId, optionDefId, valueIdx)) == 0)
return true;
}
ASSERT_DEBUG(value != NULL);
for (unsigned int valueIdx = 0; valueIdx < cfgDefOptionAllowListValueTotal(commandDefId, optionDefId); valueIdx++)
if (strcmp(value, cfgDefOptionAllowListValue(commandDefId, optionDefId, valueIdx)) == 0)
return true;
return false;
}
@@ -419,19 +419,19 @@ cfgDefOptionDependOption(ConfigDefineCommand commandDefId, ConfigDefineOption op
}
const char *
cfgDefOptionDependValue(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, int valueId)
cfgDefOptionDependValue(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, unsigned int valueId)
{
cfgDefCommandOptionCheck(commandDefId, optionDefId);
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeDepend);
if (valueId < 0 || valueId >= dataDefListSize)
THROW_FMT(AssertError, "value id %d invalid - must be >= 0 and < %d", valueId, dataDefListSize);
if (valueId >= dataDefListSize)
THROW_FMT(AssertError, "value id %u invalid - must be >= 0 and < %u", valueId, dataDefListSize);
return (char *)dataDefList[valueId];
}
int
unsigned int
cfgDefOptionDependValueTotal(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId)
{
cfgDefCommandOptionCheck(commandDefId, optionDefId);
@@ -445,12 +445,11 @@ cfgDefOptionDependValueTotal(ConfigDefineCommand commandDefId, ConfigDefineOptio
bool
cfgDefOptionDependValueValid(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, const char *value)
{
if (value != NULL)
{
for (int valueIdx = 0; valueIdx < cfgDefOptionDependValueTotal(commandDefId, optionDefId); valueIdx++)
if (strcmp(value, cfgDefOptionDependValue(commandDefId, optionDefId, valueIdx)) == 0)
return true;
}
ASSERT_DEBUG(value != NULL);
for (unsigned int valueIdx = 0; valueIdx < cfgDefOptionDependValueTotal(commandDefId, optionDefId); valueIdx++)
if (strcmp(value, cfgDefOptionDependValue(commandDefId, optionDefId, valueIdx)) == 0)
return true;
return false;
}
@@ -485,19 +484,19 @@ cfgDefOptionHelpNameAlt(ConfigDefineOption optionDefId)
}
const char *
cfgDefOptionHelpNameAltValue(ConfigDefineOption optionDefId, int valueId)
cfgDefOptionHelpNameAltValue(ConfigDefineOption optionDefId, unsigned int valueId)
{
cfgDefOptionCheck(optionDefId);
CONFIG_DEFINE_DATA_FIND(-1, optionDefId, configDefDataTypeHelpNameAlt);
if (valueId < 0 || valueId >= dataDefListSize)
THROW_FMT(AssertError, "value id %d invalid - must be >= 0 and < %d", valueId, dataDefListSize);
if (valueId >= dataDefListSize)
THROW_FMT(AssertError, "value id %u invalid - must be >= 0 and < %u", valueId, dataDefListSize);
return (char *)dataDefList[valueId];
}
int
unsigned int
cfgDefOptionHelpNameAltValueTotal(ConfigDefineOption optionDefId)
{
cfgDefOptionCheck(optionDefId);

View File

@@ -4,6 +4,8 @@ Command and Option Configuration Definition
#ifndef CONFIG_DEFINE_H
#define CONFIG_DEFINE_H
#include <sys/types.h>
/***********************************************************************************************************************************
Section enum - defines which sections of the config an option can appear in
***********************************************************************************************************************************/
@@ -30,9 +32,9 @@ const char *cfgDefCommandHelpDescription(ConfigDefineCommand commandDefId);
const char *cfgDefCommandHelpSummary(ConfigDefineCommand commandDefId);
bool cfgDefOptionAllowList(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);
int cfgDefOptionAllowListValueTotal(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);
unsigned int cfgDefOptionAllowListValueTotal(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);
bool cfgDefOptionAllowListValueValid(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, const char *value);
const char *cfgDefOptionAllowListValue(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, int valueId);
const char *cfgDefOptionAllowListValue(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, unsigned int valueId);
bool cfgDefOptionAllowRange(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);
double cfgDefOptionAllowRangeMax(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);
double cfgDefOptionAllowRangeMin(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);
@@ -40,13 +42,13 @@ void cfgDefOptionCheck(ConfigDefineOption optionDefId);
const char *cfgDefOptionDefault(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);
bool cfgDefOptionDepend(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);
ConfigDefineOption cfgDefOptionDependOption(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);
int cfgDefOptionDependValueTotal(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);
unsigned int cfgDefOptionDependValueTotal(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);
bool cfgDefOptionDependValueValid(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, const char *value);
const char *cfgDefOptionDependValue(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, int valueId);
const char *cfgDefOptionDependValue(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, unsigned int valueId);
const char *cfgDefOptionHelpDescription(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);
bool cfgDefOptionHelpNameAlt(ConfigDefineOption optionDefId);
const char *cfgDefOptionHelpNameAltValue(ConfigDefineOption optionDefId, int valueId);
int cfgDefOptionHelpNameAltValueTotal(ConfigDefineOption optionDefId);
const char *cfgDefOptionHelpNameAltValue(ConfigDefineOption optionDefId, unsigned int valueId);
unsigned int cfgDefOptionHelpNameAltValueTotal(ConfigDefineOption optionDefId);
const char *cfgDefOptionHelpSection(ConfigDefineOption optionDefId);
const char *cfgDefOptionHelpSummary(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId);
int cfgDefOptionId(const char *optionName);

View File

@@ -52,11 +52,8 @@ void
cfgLoadUpdateOption()
{
// Set default for repo-host-cmd
if (cfgOptionValid(cfgOptRepoHost) && cfgOptionTest(cfgOptRepoHost) &&
cfgOptionSource(cfgOptRepoHostCmd) == cfgSourceDefault)
{
if (cfgOptionTest(cfgOptRepoHost) && cfgOptionSource(cfgOptRepoHostCmd) == cfgSourceDefault)
cfgOptionDefaultSet(cfgOptRepoHostCmd, varNewStr(cfgExe()));
}
// Set default for pg-host-cmd
if (cfgOptionValid(cfgOptPgHostCmd))
@@ -78,10 +75,10 @@ cfgLoadUpdateOption()
else
{
THROW_FMT(OptionInvalidValueError,
"'%f' is not valid for '%s' option\nHINT '%s' option (%f) should be greater than '%s' option (%f).",
cfgOptionDbl(cfgOptProtocolTimeout), cfgOptionName(cfgOptProtocolTimeout),
cfgOptionName(cfgOptProtocolTimeout), cfgOptionDbl(cfgOptProtocolTimeout), cfgOptionName(cfgOptDbTimeout),
cfgOptionDbl(cfgOptDbTimeout));
"'%s' is not valid for '%s' option\nHINT '%s' option (%s) should be greater than '%s' option (%s).",
strPtr(varStrForce(cfgOption(cfgOptProtocolTimeout))), cfgOptionName(cfgOptProtocolTimeout),
cfgOptionName(cfgOptProtocolTimeout), strPtr(varStrForce(cfgOption(cfgOptProtocolTimeout))),
cfgOptionName(cfgOptDbTimeout), strPtr(varStrForce(cfgOption(cfgOptDbTimeout))));
}
}
@@ -138,7 +135,6 @@ cfgLoadUpdateOption()
cfgOptionName(cfgOptRepoRetentionArchiveType), strPtr(archiveRetentionType));
// If the archive retention is not explicitly set then determine what it should be defaulted to
// to.
if (!cfgOptionTest(cfgOptRepoRetentionArchive + optionIdx))
{
// If repo-retention-archive-type is default, then if repo-retention-full is set, set the repo-retention-archive

View File

@@ -4,6 +4,8 @@ Configuration Load
#ifndef CONFIG_LOAD_H
#define CONFIG_LOAD_H
#include <sys/types.h>
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/

View File

@@ -784,7 +784,8 @@ configParse(unsigned int argListSize, const char *argList[])
// Build the list of possible depend values
StringList *dependValueList = strLstNew();
for (int listIdx = 0; listIdx < cfgDefOptionDependValueTotal(commandDefId, optionDefId); listIdx++)
for (unsigned int listIdx = 0;
listIdx < cfgDefOptionDependValueTotal(commandDefId, optionDefId); listIdx++)
{
const char *dependValue = cfgDefOptionDependValue(commandDefId, optionDefId, listIdx);

View File

@@ -348,7 +348,7 @@ unit:
# ----------------------------------------------------------------------------------------------------------------------------
- name: load
total: 1
total: 3
coverage:
config/load: full

View File

@@ -35,6 +35,8 @@ testRun()
TEST_RESULT_BOOL(cfgDefOptionAllowList(cfgDefCmdBackup, cfgDefOptPgHost), false, "allow list not valid");
TEST_RESULT_BOOL(cfgDefOptionAllowList(cfgDefCmdBackup, cfgDefOptType), true, "command allow list valid");
TEST_RESULT_INT(cfgDefOptionAllowListValueTotal(cfgDefCmdBackup, cfgDefOptChecksumPage), 0, "allow list total = 0");
TEST_RESULT_INT(cfgDefOptionAllowListValueTotal(cfgDefCmdBackup, cfgDefOptType), 3, "allow list total");
TEST_RESULT_STR(cfgDefOptionAllowListValue(cfgDefCmdBackup, cfgDefOptType, 0), "full", "allow list value 0");

View File

@@ -4,6 +4,8 @@ Test Configuration Load
#include "common/log.h"
#include "version.h"
#include "common/harnessConfig.h"
/***********************************************************************************************************************************
Test run
***********************************************************************************************************************************/
@@ -11,89 +13,228 @@ void
testRun()
{
// *****************************************************************************************************************************
if (testBegin("cfgLoad()"))
if (testBegin("cfgLoadLogSetting()"))
{
cfgInit();
TEST_RESULT_VOID(cfgLoadLogSetting(), "load log settings all defaults");
TEST_RESULT_INT(logLevelStdOut, logLevelOff, "console logging is off");
TEST_RESULT_INT(logLevelStdErr, logLevelOff, "stderr logging is off");
TEST_RESULT_INT(logLevelFile, logLevelOff, "file logging is off");
TEST_RESULT_BOOL(logTimestamp, true, "timestamp logging is on");
// -------------------------------------------------------------------------------------------------------------------------
cfgInit();
cfgCommandSet(cfgCmdLocal);
cfgOptionValidSet(cfgOptLogLevelConsole, true);
cfgOptionSet(cfgOptLogLevelConsole, cfgSourceParam, varNewStrZ("info"));
cfgOptionValidSet(cfgOptLogLevelStderr, true);
cfgOptionSet(cfgOptLogLevelStderr, cfgSourceParam, varNewStrZ("error"));
cfgOptionValidSet(cfgOptLogLevelFile, true);
cfgOptionSet(cfgOptLogLevelFile, cfgSourceParam, varNewStrZ("debug"));
cfgOptionValidSet(cfgOptLogTimestamp, true);
cfgOptionSet(cfgOptLogTimestamp, cfgSourceParam, varNewBool(false));
TEST_RESULT_VOID(cfgLoadLogSetting(), "load log settings no defaults");
TEST_RESULT_INT(logLevelStdOut, logLevelInfo, "console logging is info");
TEST_RESULT_INT(logLevelStdErr, logLevelError, "stderr logging is error");
TEST_RESULT_INT(logLevelFile, logLevelDebug, "file logging is debugging");
TEST_RESULT_BOOL(logTimestamp, false, "timestamp logging is off");
// -------------------------------------------------------------------------------------------------------------------------
cfgInit();
cfgCommandSet(cfgCmdLocal);
cfgOptionValidSet(cfgOptLogLevelStderr, true);
cfgOptionSet(cfgOptLogLevelStderr, cfgSourceParam, varNewStrZ("info"));
TEST_RESULT_VOID(cfgLoadLogSetting(), "load log settings reset stderr");
TEST_RESULT_INT(logLevelStdErr, logLevelError, "stderr logging is error");
}
// *****************************************************************************************************************************
if (testBegin("cfgLoadUpdateOption()"))
{
String *exe = strNew("/path/to/pgbackrest");
String *exeOther = strNew("/other/path/to/pgbackrest");
cfgInit();
cfgCommandSet(cfgCmdBackup);
cfgExeSet(exe);
cfgOptionValidSet(cfgOptRepoHost, true);
cfgOptionValidSet(cfgOptPgHost, true);
TEST_RESULT_VOID(cfgLoadUpdateOption(), "hosts are not set so don't update commands");
cfgOptionSet(cfgOptRepoHost, cfgSourceParam, varNewStrZ("repo-host"));
TEST_RESULT_VOID(cfgLoadUpdateOption(), "repo remote command is updated");
TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptRepoHostCmd)), strPtr(exe), " check repo1-host-cmd");
cfgOptionSet(cfgOptRepoHostCmd, cfgSourceParam, varNewStr(exeOther));
TEST_RESULT_VOID(cfgLoadUpdateOption(), "repo remote command was already set");
TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptRepoHostCmd)), strPtr(exeOther), " check repo1-host-cmd");
cfgOptionSet(cfgOptRepoHost, cfgSourceParam, NULL);
// -------------------------------------------------------------------------------------------------------------------------
cfgOptionValidSet(cfgOptPgHostCmd, true);
cfgOptionSet(cfgOptPgHost, cfgSourceParam, varNewStrZ("pg1-host"));
cfgOptionValidSet(cfgOptPgHost + 1, true);
cfgOptionSet(cfgOptPgHost + 1, cfgSourceParam, varNewStrZ("pg2-host"));
cfgOptionValidSet(cfgOptPgHostCmd + 1, true);
cfgOptionSet(cfgOptPgHostCmd + 1, cfgSourceParam, varNewStr(exeOther));
cfgOptionValidSet(cfgOptPgHost + cfgOptionIndexTotal(cfgOptPgHost) - 1, true);
cfgOptionSet(cfgOptPgHost + cfgOptionIndexTotal(cfgOptPgHost) - 1, cfgSourceParam, varNewStrZ("pgX-host"));
TEST_RESULT_VOID(cfgLoadUpdateOption(), "pg remote command is updated");
TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptPgHostCmd)), strPtr(exe), " check pg1-host-cmd");
TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptPgHostCmd + 1)), strPtr(exeOther), " check pg2-host-cmd is already set");
TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptPgHostCmd + 2)), NULL, " check pg3-host-cmd is not set");
TEST_RESULT_STR(
strPtr(cfgOptionStr(cfgOptPgHostCmd + cfgOptionIndexTotal(cfgOptPgHost) - 1)), strPtr(exe), " check pgX-host-cmd");
// -------------------------------------------------------------------------------------------------------------------------
cfgInit();
cfgOptionValidSet(cfgOptDbTimeout, true);
cfgOptionSet(cfgOptDbTimeout, cfgSourceParam, varNewDbl(100));
TEST_RESULT_VOID(cfgLoadUpdateOption(), "pg timeout set but not protocol timeout");
cfgOptionValidSet(cfgOptProtocolTimeout, true);
cfgOptionSet(cfgOptProtocolTimeout, cfgSourceDefault, varNewDbl(101));
TEST_RESULT_VOID(cfgLoadUpdateOption(), "protocol timeout > pg timeout");
cfgOptionSet(cfgOptDbTimeout, cfgSourceParam, varNewDbl(100000));
TEST_RESULT_VOID(cfgLoadUpdateOption(), "protocol timeout set automatically");
TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptProtocolTimeout), 100030, " check protocol timeout");
cfgOptionValidSet(cfgOptProtocolTimeout, true);
cfgOptionSet(cfgOptProtocolTimeout, cfgSourceParam, varNewDbl(50.5));
TEST_ERROR(
cfgLoadUpdateOption(), OptionInvalidValueError,
"'50.5' is not valid for 'protocol-timeout' option\n"
"HINT 'protocol-timeout' option (50.5) should be greater than 'db-timeout' option (100000).");
// -------------------------------------------------------------------------------------------------------------------------
cfgInit();
cfgCommandSet(cfgCmdBackup);
cfgExeSet(exe);
cfgOptionValidSet(cfgOptPgHost, true);
TEST_RESULT_VOID(cfgLoadUpdateOption(), "only repo-host is valid");
cfgOptionValidSet(cfgOptRepoHost, true);
cfgOptionSet(cfgOptRepoHost, cfgSourceParam, varNewStrZ("repo-host"));
cfgOptionValidSet(cfgOptPgHost + 4, true);
cfgOptionSet(cfgOptPgHost + 4, cfgSourceParam, varNewStrZ("pg5-host"));
TEST_ERROR(cfgLoadUpdateOption(), ConfigError, "pg and repo hosts cannot both be configured as remote");
// -------------------------------------------------------------------------------------------------------------------------
StringList *argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
strLstAdd(argList, strNew("archive-get"));
TEST_ERROR(
cfgLoad(strLstSize(argList), strLstPtr(argList)), OptionRequiredError,
"archive-get command requires option: stanza");
TEST_RESULT_INT(logLevelStdOut, logLevelWarn, "console logging is error");
TEST_RESULT_INT(logLevelStdErr, logLevelWarn, "stderr logging is error");
// -------------------------------------------------------------------------------------------------------------------------
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"));
strLstAdd(argList, strNew("--log-level-console=info"));
strLstAdd(argList, strNew("--log-level-stderr=off"));
strLstAdd(argList, strNew("--no-log-timestamp"));
strLstAdd(argList, strNew("expire"));
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load local config");
TEST_RESULT_VOID(harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for retention warning");
testLogResult(
"P00 WARN: option repo1-retention-full is not set, the repository may run out of space\n"
" HINT: to retain full backups indefinitely (without warning), set option"
" 'repo1-retention-full' to the maximum.");
TEST_RESULT_BOOL(cfgOptionTest(cfgOptRepoRetentionArchive), false, " repo1-retention-archive not set");
TEST_RESULT_STR(strPtr(cfgExe()), "pgbackrest", "check exe");
TEST_RESULT_INT(logLevelStdOut, logLevelOff, "console logging is off");
TEST_RESULT_INT(logLevelStdErr, logLevelError, "stderr logging is error");
TEST_RESULT_INT(logLevelFile, logLevelOff, "file logging is off");
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
strLstAdd(argList, strNew("--stanza=db"));
strLstAdd(argList, strNew("archive-push"));
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load archive-push config");
TEST_RESULT_PTR(cfgOptionDefault(cfgOptRepoHostCmd), NULL, " command archive-push, option repo1-host-cmd default");
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
strLstAdd(argList, strNew("--stanza=db"));
strLstAdd(argList, strNew("--repo1-host=backup"));
strLstAdd(argList, strNew("archive-push"));
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load archive-push config");
TEST_RESULT_STR(
strPtr(varStr(cfgOptionDefault(cfgOptRepoHostCmd))), strPtr(cfgExe()),
" command archive-push, option repo1-host-cmd default");
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
strLstAdd(argList, strNew("--repo1-retention-full=1"));
strLstAdd(argList, strNew("--stanza=db"));
strLstAdd(argList, strNew("backup"));
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load backup config");
TEST_RESULT_PTR(cfgOptionDefault(cfgOptPgHostCmd), NULL, " command backup, option pg1-host-cmd default");
TEST_RESULT_BOOL(lockRelease(true), true, "release backup lock");
TEST_RESULT_VOID(harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), "load config no retention warning");
TEST_RESULT_INT(cfgOptionInt(cfgOptRepoRetentionArchive), 1, " repo1-retention-archive set");
// Munge repo-type for coverage. This will go away when there are multiple repos.
cfgOptionSet(cfgOptRepoType, cfgSourceParam, NULL);
TEST_RESULT_VOID(cfgLoadUpdateOption(), "load config no repo-type");
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
strLstAdd(argList, strNew("--pg1-host=db"));
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
strLstAdd(argList, strNew("--pg3-host=db"));
strLstAdd(argList, strNew("--pg3-path=/path/to/db"));
strLstAdd(argList, strNew("--repo1-retention-full=1"));
strLstAdd(argList, strNew("--stanza=db"));
strLstAdd(argList, strNew("backup"));
strLstAdd(argList, strNew("--log-level-console=info"));
strLstAdd(argList, strNew("--log-level-stderr=off"));
strLstAdd(argList, strNew("--no-log-timestamp"));
strLstAdd(argList, strNew("--repo1-retention-archive-type=incr"));
strLstAdd(argList, strNew("expire"));
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load backup config");
TEST_RESULT_STR(
strPtr(varStr(cfgOptionDefault(cfgOptPgHostCmd))), strPtr(cfgExe()), " command backup, option pg1-host-cmd default");
TEST_RESULT_PTR(cfgOptionDefault(cfgOptPgHostCmd + 1), NULL, " command backup, option pg2-host-cmd default");
TEST_RESULT_STR(
strPtr(varStr(cfgOptionDefault(cfgOptPgHostCmd + 2))), strPtr(cfgExe()),
" command backup, option pg3-host-cmd default");
TEST_RESULT_BOOL(lockRelease(true), true, "release backup lock");
TEST_RESULT_VOID(harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for retention warning");
testLogResult(
"P00 WARN: option repo1-retention-full is not set, the repository may run out of space\n"
" HINT: to retain full backups indefinitely (without warning), set option 'repo1-retention-full'"
" to the maximum.\n"
"P00 WARN: WAL segments will not be expired: option 'repo1-retention-archive-type=incr' but option"
" 'repo1-retention-archive' is not set");
TEST_RESULT_BOOL(cfgOptionTest(cfgOptRepoRetentionArchive), false, " repo1-retention-archive not set");
argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
strLstAdd(argList, strNew("--stanza=db"));
strLstAdd(argList, strNew("--log-level-console=info"));
strLstAdd(argList, strNew("--log-level-stderr=off"));
strLstAdd(argList, strNew("--no-log-timestamp"));
strLstAdd(argList, strNew("--repo1-retention-archive-type=diff"));
strLstAdd(argList, strNew("expire"));
TEST_RESULT_VOID(harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for retention warning");
testLogResult(
"P00 WARN: option repo1-retention-full is not set, the repository may run out of space\n"
" HINT: to retain full backups indefinitely (without warning), set option"
" 'repo1-retention-full' to the maximum.\n"
"P00 WARN: WAL segments will not be expired: option 'repo1-retention-archive-type=diff' but neither option"
" 'repo1-retention-archive' nor option 'repo1-retention-diff' is set");
TEST_RESULT_BOOL(cfgOptionTest(cfgOptRepoRetentionArchive), false, " repo1-retention-archive not set");
strLstAdd(argList, strNew("--repo1-retention-diff=2"));
TEST_RESULT_VOID(harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for retention warning");
testLogResult(
"P00 WARN: option repo1-retention-full is not set, the repository may run out of space\n"
" HINT: to retain full backups indefinitely (without warning), set option"
" 'repo1-retention-full' to the maximum.");
TEST_RESULT_INT(cfgOptionInt(cfgOptRepoRetentionArchive), 2, " repo1-retention-archive set to retention-diff");
argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
strLstAdd(argList, strNew("--stanza=db"));
strLstAdd(argList, strNew("--log-level-console=info"));
strLstAdd(argList, strNew("--log-level-stderr=off"));
strLstAdd(argList, strNew("--no-log-timestamp"));
strLstAdd(argList, strNew("--repo1-retention-archive-type=diff"));
strLstAdd(argList, strNew("--repo1-retention-archive=3"));
strLstAdd(argList, strNew("--repo1-retention-full=1"));
strLstAdd(argList, strNew("expire"));
TEST_RESULT_VOID(harnessCfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for retention warning");
testLogResult(
"P00 WARN: option 'repo1-retention-diff' is not set for 'repo1-retention-archive-type=diff'\n"
" HINT: to retain differential backups indefinitely (without warning), set option 'repo1-retention-diff'"
" to the maximum.");
}
// *****************************************************************************************************************************
if (testBegin("cfgLoad()"))
{
// Command does not have umask
// -------------------------------------------------------------------------------------------------------------------------
StringList *argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
strLstAdd(argList, strNew("info"));
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config and don't set umask");
// Set a distinct umask value and test that the umask is reset by configLoad since default for neutral-umask=y
// -------------------------------------------------------------------------------------------------------------------------
@@ -118,164 +259,23 @@ testRun()
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for no-neutral-umask");
TEST_RESULT_INT(umask(0), 0111, " umask was not reset");
// db-timeout / protocol-timeout tests
// No command
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "no command");
// Command takes lock and opens log file
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
strLstAdd(argList, strNew("--stanza=db"));
strLstAdd(argList, strNew("--db-timeout=1830"));
strLstAdd(argList, strNew("archive-get"));
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for protocol-timeout reset");
TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptDbTimeout), 1830, " db-timeout set");
TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptProtocolTimeout), 1860, " protocol-timeout set greater than db-timeout");
// Set the protocol-timeout so the source is the command line and not the default
strLstAdd(argList, strNew("--protocol-timeout=1820"));
TEST_ERROR(
cfgLoad(strLstSize(argList), strLstPtr(argList)), OptionInvalidValueError,
strPtr(strNewFmt("'%f' is not valid for '%s' option\n"
"HINT '%s' option (%f) should be greater than '%s' option (%f).",
cfgOptionDbl(cfgOptProtocolTimeout), cfgOptionName(cfgOptProtocolTimeout),
cfgOptionName(cfgOptProtocolTimeout), cfgOptionDbl(cfgOptProtocolTimeout), cfgOptionName(cfgOptDbTimeout),
cfgOptionDbl(cfgOptDbTimeout))));
// pg-host and repo-host tests
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
strLstAdd(argList, strNew("--stanza=db"));
strLstAdd(argList, strNew("--pg2-host=pg2"));
strLstAdd(argList, strNew("archive-get"));
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for pg and repo host test");
strLstAdd(argList, strNew("--repo1-host=repo1"));
TEST_ERROR(
cfgLoad(strLstSize(argList), strLstPtr(argList)), ConfigError,
"pg and repo hosts cannot both be configured as remote");
// retention
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
strLstAdd(argList, strNew("--stanza=db"));
strLstAdd(argList, strNew("--log-level-console=info"));
strLstAdd(argList, strNew("--log-level-stderr=off"));
strLstAdd(argList, strNew("--no-log-timestamp"));
strLstAdd(argList, strNew("expire"));
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for retention warning");
testLogResult(
"P00 WARN: unable to open log file '/var/log/pgbackrest/db-expire.log': No such file or directory\n"
" NOTE: process will continue without log file.\n"
"P00 INFO: expire command begin " PGBACKREST_VERSION ": --log-level-console=info --log-level-stderr=off"
" --no-log-timestamp --stanza=db\n"
"P00 WARN: option repo1-retention-full is not set, the repository may run out of space\n"
" HINT: to retain full backups indefinitely (without warning), set option"
" 'repo1-retention-full' to the maximum.");
TEST_RESULT_BOOL(cfgOptionTest(cfgOptRepoRetentionArchive), false, " repo1-retention-archive not set");
TEST_RESULT_BOOL(lockRelease(true), true, "release expire lock");
strLstAdd(argList, strNew("--pg1-path=/path"));
strLstAdd(argList, strNew("--repo1-retention-full=1"));
strLstAdd(argList, strNewFmt("--log-path=%s", testPath()));
strLstAdd(argList, strNew("backup"));
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config no retention warning");
testLogResult(
"P00 WARN: unable to open log file '/var/log/pgbackrest/db-expire.log': No such file or directory\n"
" NOTE: process will continue without log file.\n"
"P00 INFO: expire command begin " PGBACKREST_VERSION ": --log-level-console=info --log-level-stderr=off"
" --no-log-timestamp --repo1-retention-full=1 --stanza=db");
TEST_RESULT_INT(cfgOptionInt(cfgOptRepoRetentionArchive), 1, " repo1-retention-archive set");
TEST_RESULT_BOOL(lockRelease(true), true, "release expire lock");
argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
strLstAdd(argList, strNew("--stanza=db"));
strLstAdd(argList, strNew("--log-level-console=info"));
strLstAdd(argList, strNew("--log-level-stderr=off"));
strLstAdd(argList, strNew("--no-log-timestamp"));
strLstAdd(argList, strNew("--repo1-retention-archive-type=incr"));
strLstAdd(argList, strNew("expire"));
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for retention warning");
testLogResult(
"P00 WARN: unable to open log file '/var/log/pgbackrest/db-expire.log': No such file or directory\n"
" NOTE: process will continue without log file.\n"
"P00 INFO: expire command begin " PGBACKREST_VERSION ": --log-level-console=info --log-level-stderr=off"
" --no-log-timestamp --repo1-retention-archive-type=incr --stanza=db\n"
"P00 WARN: option repo1-retention-full is not set, the repository may run out of space\n"
" HINT: to retain full backups indefinitely (without warning), set option 'repo1-retention-full'"
" to the maximum.\n"
"P00 WARN: WAL segments will not be expired: option 'repo1-retention-archive-type=incr' but option"
" 'repo1-retention-archive' is not set");
TEST_RESULT_BOOL(cfgOptionTest(cfgOptRepoRetentionArchive), false, " repo1-retention-archive not set");
TEST_RESULT_BOOL(lockRelease(true), true, "release expire lock");
argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
strLstAdd(argList, strNew("--stanza=db"));
strLstAdd(argList, strNew("--log-level-console=info"));
strLstAdd(argList, strNew("--log-level-stderr=off"));
strLstAdd(argList, strNew("--no-log-timestamp"));
strLstAdd(argList, strNew("--repo1-retention-archive-type=diff"));
strLstAdd(argList, strNew("expire"));
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for retention warning");
testLogResult(
"P00 WARN: unable to open log file '/var/log/pgbackrest/db-expire.log': No such file or directory\n"
" NOTE: process will continue without log file.\n"
"P00 INFO: expire command begin " PGBACKREST_VERSION ": --log-level-console=info --log-level-stderr=off"
" --no-log-timestamp --repo1-retention-archive-type=diff --stanza=db\n"
"P00 WARN: option repo1-retention-full is not set, the repository may run out of space\n"
" HINT: to retain full backups indefinitely (without warning), set option"
" 'repo1-retention-full' to the maximum.\n"
"P00 WARN: WAL segments will not be expired: option 'repo1-retention-archive-type=diff' but neither option"
" 'repo1-retention-archive' nor option 'repo1-retention-diff' is set");
TEST_RESULT_BOOL(cfgOptionTest(cfgOptRepoRetentionArchive), false, " repo1-retention-archive not set");
TEST_RESULT_BOOL(lockRelease(true), true, "release expire lock");
strLstAdd(argList, strNew("--repo1-retention-diff=2"));
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for retention warning");
testLogResult(
"P00 WARN: unable to open log file '/var/log/pgbackrest/db-expire.log': No such file or directory\n"
" NOTE: process will continue without log file.\n"
"P00 INFO: expire command begin " PGBACKREST_VERSION ": --log-level-console=info --log-level-stderr=off"
" --no-log-timestamp --repo1-retention-archive-type=diff --repo1-retention-diff=2 --stanza=db\n"
"P00 WARN: option repo1-retention-full is not set, the repository may run out of space\n"
" HINT: to retain full backups indefinitely (without warning), set option"
" 'repo1-retention-full' to the maximum.");
TEST_RESULT_INT(cfgOptionInt(cfgOptRepoRetentionArchive), 2, " repo1-retention-archive set to retention-diff");
TEST_RESULT_BOOL(lockRelease(true), true, "release expire lock");
argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
strLstAdd(argList, strNew("--stanza=db"));
strLstAdd(argList, strNew("--log-level-console=info"));
strLstAdd(argList, strNew("--log-level-stderr=off"));
strLstAdd(argList, strNew("--no-log-timestamp"));
strLstAdd(argList, strNew("--repo1-retention-archive-type=diff"));
strLstAdd(argList, strNew("--repo1-retention-archive=3"));
strLstAdd(argList, strNew("--repo1-retention-full=1"));
strLstAdd(argList, strNew("expire"));
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for retention warning");
testLogResult(
"P00 WARN: unable to open log file '/var/log/pgbackrest/db-expire.log': No such file or directory\n"
" NOTE: process will continue without log file.\n"
"P00 INFO: expire command begin " PGBACKREST_VERSION ": --log-level-console=info --log-level-stderr=off"
" --no-log-timestamp --repo1-retention-archive=3 --repo1-retention-archive-type=diff --repo1-retention-full=1"
" --stanza=db\n"
"P00 WARN: option 'repo1-retention-diff' is not set for 'repo1-retention-archive-type=diff'\n"
" HINT: to retain differential backups indefinitely (without warning), set option 'repo1-retention-diff'"
" to the maximum.");
TEST_RESULT_BOOL(lockRelease(true), true, "release expire lock");
testLogErrResult(
"WARN: unable to open log file '/var/log/pgbackrest/db-backup.log': No such file or directory\n"
"NOTE: process will continue without log file.\n"
"WARN: unable to open log file '/var/log/pgbackrest/db-backup.log': No such file or directory\n"
"NOTE: process will continue without log file.");
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "lock and open log file");
}
}