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:
parent
a50b1eb5be
commit
45ffe37e4f
@ -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>
|
||||
|
||||
|
@ -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?
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -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
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
|
@ -478,7 +478,6 @@ my $oTestDef =
|
||||
&TESTDEF_NAME => 'load',
|
||||
&TESTDEF_TOTAL => 1,
|
||||
&TESTDEF_C => true,
|
||||
&TESTDEF_CDEF => '-DNO_ERROR -DNO_LOG',
|
||||
|
||||
&TESTDEF_COVERAGE =>
|
||||
{
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user