1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-03 14:52:21 +02:00

Improve coverage in config/config module.

This commit is contained in:
David Steele 2019-05-13 19:10:24 -04:00
parent 57281d4792
commit 1e5ab69cad
3 changed files with 62 additions and 45 deletions

View File

@ -160,7 +160,7 @@
</release-item>
<release-item>
<p>Improve coverage in <file>perl/exec</file> module.</p>
<p>Improve coverage in <file>perl/exec</file> and <file>config/config</file> modules.</p>
</release-item>
<release-item>

View File

@ -455,7 +455,55 @@ cfgOptionDefIdFromId(ConfigOption optionId)
/***********************************************************************************************************************************
Get/set option default
Option defaults are generally not set in advance because the vast majority of them are never used. It is more efficient to generate
them when they are requested.
Some defaults are (e.g. the exe path) are set at runtime.
***********************************************************************************************************************************/
static Variant *
cfgOptionDefaultValue(ConfigDefineOption optionDefId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_END();
Variant *result;
Variant *defaultValue = varNewStrZ(cfgDefOptionDefault(cfgCommandDefIdFromId(cfgCommand()), optionDefId));
switch (cfgDefOptionType(optionDefId))
{
case cfgDefOptTypeBoolean:
{
result = varNewBool(varBoolForce(defaultValue));
break;
}
case cfgDefOptTypeFloat:
{
result = varNewDbl(varDblForce(defaultValue));
break;
}
case cfgDefOptTypeInteger:
case cfgDefOptTypeSize:
{
result = varNewInt64(varInt64Force(defaultValue));
break;
}
case cfgDefOptTypePath:
case cfgDefOptTypeString:
result = varDup(defaultValue);
break;
default:
THROW_FMT(AssertError, "default value not available for option type %d", cfgDefOptionType(optionDefId));
}
FUNCTION_TEST_RETURN(result);
}
const Variant *
cfgOptionDefault(ConfigOption optionId)
{
@ -471,46 +519,11 @@ cfgOptionDefault(ConfigOption optionId)
if (cfgDefOptionDefault(cfgCommandDefIdFromId(cfgCommand()), optionDefId) != NULL)
{
MEM_CONTEXT_TEMP_BEGIN()
MEM_CONTEXT_BEGIN(configMemContext)
{
Variant *defaultValue = varNewStrZ(cfgDefOptionDefault(cfgCommandDefIdFromId(cfgCommand()), optionDefId));
MEM_CONTEXT_BEGIN(configMemContext)
{
switch (cfgDefOptionType(optionDefId))
{
case cfgDefOptTypeBoolean:
{
configOptionValue[optionId].defaultValue = varNewBool(varBoolForce(defaultValue));
break;
}
case cfgDefOptTypeFloat:
{
configOptionValue[optionId].defaultValue = varNewDbl(varDblForce(defaultValue));
break;
}
case cfgDefOptTypeInteger:
case cfgDefOptTypeSize:
{
configOptionValue[optionId].defaultValue = varNewInt64(varInt64Force(defaultValue));
break;
}
case cfgDefOptTypePath:
case cfgDefOptTypeString:
configOptionValue[optionId].defaultValue = varDup(defaultValue);
break;
default: // {uncoverable - other types do not have defaults yet}
THROW_FMT( // {+uncoverable}
AssertError, "type for option '%s' does not support defaults", cfgOptionName(optionId));
}
}
MEM_CONTEXT_END();
configOptionValue[optionId].defaultValue = cfgOptionDefaultValue(optionDefId);
}
MEM_CONTEXT_TEMP_END();
MEM_CONTEXT_END();
}
}
@ -681,19 +694,21 @@ cfgOptionIdFromDefId(ConfigDefineOption optionDefId, unsigned int index)
FUNCTION_TEST_PARAM(UINT, index);
FUNCTION_TEST_END();
ASSERT(optionDefId < cfgDefOptionTotal());
ASSERT(index < cfgDefOptionIndexTotal(optionDefId));
// Search for the option
ConfigOption optionId;
for (optionId = 0; optionId < CFG_OPTION_TOTAL; optionId++) // {uncoverable - only a bug in code gen lets this loop end}
for (optionId = 0; optionId < CFG_OPTION_TOTAL; optionId++)
{
if (configOptionData[optionId].defineId == optionDefId)
break;
}
// If the mapping is not found then there is a bug in the code generator
ASSERT(optionId != CFG_OPTION_TOTAL);
// Make sure the index is valid
ASSERT(index < cfgDefOptionIndexTotal(optionDefId));
// Return with original index
FUNCTION_TEST_RETURN(optionId + index);
}

View File

@ -31,8 +31,8 @@ testRun(void)
TEST_RESULT_INT(cfgOptionId(BOGUS_STR), -1, "option id from invalid option name");
TEST_ERROR(
cfgOptionIdFromDefId(cfgDefOptionTotal(), 6), AssertError,
"assertion 'optionDefId < cfgDefOptionTotal()' failed");
cfgOptionIdFromDefId(999999, 6), AssertError,
"assertion 'optionId != CFG_OPTION_TOTAL' failed");
TEST_ERROR(
cfgOptionIdFromDefId(0, 999999), AssertError,
"assertion 'index < cfgDefOptionIndexTotal(optionDefId)' failed");
@ -237,6 +237,8 @@ testRun(void)
TEST_RESULT_VOID(cfgInit(), "config init");
TEST_RESULT_VOID(cfgCommandSet(cfgCmdBackup), "backup command");
TEST_ERROR(
strPtr(varStr(cfgOptionDefaultValue(cfgOptDbInclude))), AssertError, "default value not available for option type 4");
TEST_RESULT_STR(strPtr(varStr(cfgOptionDefault(cfgOptType))), "incr", "backup type default");
TEST_RESULT_BOOL(varBool(cfgOptionDefault(cfgOptCompress)), "true", "backup compress default");
TEST_RESULT_DOUBLE(varDbl(cfgOptionDefault(cfgOptProtocolTimeout)), 1830, "backup protocol-timeout default");