1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Add cfgOptionTest().

Update cfgOption() calls that are better implemented as cfgOptionTest().

Contributed by Cynthia Shang.
This commit is contained in:
Cynthia Shang 2018-03-05 18:51:48 -05:00 committed by David Steele
parent a50b1eb5be
commit 45ffe37e4f
8 changed files with 32 additions and 10 deletions

View File

@ -40,6 +40,14 @@
<release-item>
<p>Improve code documentation in <code>config</code> module.</p>
</release-item>
<release-item>
<release-item-contributor-list>
<release-item-contributor id="shang.cynthia"/>
</release-item-contributor-list>
<p>Add <code>cfgOptionTest()</code> and update <code>cfgOption()</code> calls that are better implemented as <code>cfgOptionTest()</code>.</p>
</release-item>
</release-development-list>
</release-core-list>

View File

@ -656,6 +656,16 @@ cfgOptionSource(ConfigOption optionId)
return configOptionValue[optionId].source;
}
/***********************************************************************************************************************************
Is the option set?
***********************************************************************************************************************************/
bool
cfgOptionTest(ConfigOption optionId)
{
cfgOptionCheck(optionId);
return cfgOptionValid(optionId) && configOptionValue[optionId].value != NULL;
}
/***********************************************************************************************************************************
Is the option valid for this command?
***********************************************************************************************************************************/

View File

@ -42,6 +42,7 @@ unsigned int cfgOptionIndexTotal(ConfigOption optionDefId);
const char *cfgOptionName(ConfigOption optionId);
bool cfgOptionValid(ConfigOption optionId);
bool cfgOptionTest(ConfigOption optionId);
/***********************************************************************************************************************************
Option Source Enum

View File

@ -50,7 +50,7 @@ cfgLoadParam(unsigned int argListSize, const char *argList[], String *exe)
cfgExeSet(exe);
// Set default for repo-host-cmd
if (cfgOptionValid(cfgOptRepoHost) && cfgOption(cfgOptRepoHost) != NULL &&
if (cfgOptionValid(cfgOptRepoHost) && cfgOptionTest(cfgOptRepoHost) &&
cfgOptionSource(cfgOptRepoHostCmd) == cfgSourceDefault)
{
cfgOptionDefaultSet(cfgOptRepoHostCmd, varNewStr(cfgExe()));
@ -59,9 +59,9 @@ cfgLoadParam(unsigned int argListSize, const char *argList[], String *exe)
// Set default for pg-host-cmd
if (cfgOptionValid(cfgOptPgHostCmd))
{
for (unsigned int optionIdx = 0; optionIdx <= cfgOptionIndexTotal(cfgOptPgHost); optionIdx++)
for (unsigned int optionIdx = 0; optionIdx < cfgOptionIndexTotal(cfgOptPgHost); optionIdx++)
{
if (cfgOption(cfgOptPgHost + optionIdx) != NULL && cfgOptionSource(cfgOptPgHostCmd + optionIdx) == cfgSourceDefault)
if (cfgOptionTest(cfgOptPgHost + optionIdx) && cfgOptionSource(cfgOptPgHostCmd + optionIdx) == cfgSourceDefault)
cfgOptionDefaultSet(cfgOptPgHostCmd + optionIdx, varNewStr(cfgExe()));
}
}

View File

@ -39,7 +39,7 @@ perlOptionJson()
strCat(result, "\"");
// Add a comma if another define will be added
if (cfgOption(optionId) != NULL)
if (cfgOptionTest(optionId))
strCat(result, ",");
}
@ -53,7 +53,7 @@ perlOptionJson()
strCatFmt(result, "\"reset\":%s", strPtr(varStrForce(varNewBool(true))));
// If has a value
if (cfgOption(optionId) != NULL)
if (cfgOptionTest(optionId))
{
// If option is reset, then add a comma separator before setting the value
if (cfgOptionReset(optionId))

View File

@ -478,7 +478,6 @@ my $oTestDef =
&TESTDEF_NAME => 'load',
&TESTDEF_TOTAL => 1,
&TESTDEF_C => true,
&TESTDEF_CDEF => '-DNO_ERROR -DNO_LOG',
&TESTDEF_COVERAGE =>
{

View File

@ -106,8 +106,12 @@ testRun()
// -------------------------------------------------------------------------------------------------------------------------
TEST_RESULT_BOOL(cfgOptionValid(cfgOptConfig), false, "valid defaults to false");
TEST_RESULT_BOOL(cfgOptionTest(cfgOptConfig), false, "option not valid for the command");
TEST_RESULT_VOID(cfgOptionValidSet(cfgOptConfig, true), "set valid");
TEST_RESULT_BOOL(cfgOptionValid(cfgOptConfig), true, "valid is set");
TEST_RESULT_BOOL(cfgOptionTest(cfgOptConfig), false, "option valid but value is null");
TEST_RESULT_VOID(cfgOptionSet(cfgOptConfig, cfgSourceParam, varNewStrZ("cfg")), "set option config");
TEST_RESULT_BOOL(cfgOptionTest(cfgOptConfig), true, "option valid and value not null");
// -------------------------------------------------------------------------------------------------------------------------
TEST_RESULT_PTR(cfgOption(cfgOptOnline), NULL, "online is null");

View File

@ -348,7 +348,7 @@ testRun()
TEST_RESULT_STR(strPtr(cfgExe()), TEST_BACKREST_EXE, " exe is set");
TEST_RESULT_PTR(cfgOption(cfgOptConfig), NULL, " config is not set");
TEST_RESULT_BOOL(cfgOptionTest(cfgOptConfig), false, " config is not set");
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");
@ -410,13 +410,13 @@ testRun()
strPtr(configFile), strPtr(configFile), strPtr(configFile), strPtr(configFile), strPtr(configFile),
strPtr(configFile))));
TEST_RESULT_PTR(cfgOption(cfgOptPgHost), NULL, " pg1-path is not defined");
TEST_RESULT_BOOL(cfgOptionTest(cfgOptPgHost), false, " pg1-path is not set");
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_PTR(cfgOption(cfgOptArchiveCheck), NULL, " archive-check is not set");
TEST_RESULT_PTR(cfgOption(cfgOptArchiveCopy), NULL, " archive-copy is not set");
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");