pgbackrest.git / summary / log / commit / refs
commit 1e5ab69cada2862cbc458ae322bdc166c244f0f8
Author: David Steele <david@pgmasters.net>
Date: Mon May 13 23:10:24 2019 +0000
Improve coverage in config/config module.
doc/xml/release.xml | 2 +-
src/config/config.c | 99 +++++++++++++++++++++----------------
test/src/module/config/configTest.c | 6 ++-
3 files changed, 62 insertions(+), 45 deletions(-)
diff --git a/doc/xml/release.xml b/doc/xml/release.xml
index 74afbbd3a..d958be93d 100644
--- a/doc/xml/release.xml
+++ b/doc/xml/release.xml
@@ -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>
diff --git a/src/config/config.c b/src/config/config.c
index 150fc8556..17b5001e4 100644
--- a/src/config/config.c
+++ b/src/config/config.c
@@ -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);
}
diff --git a/test/src/module/config/configTest.c b/test/src/module/config/configTest.c
index 1eae2d6f2..07e7a5cfe 100644
--- a/test/src/module/config/configTest.c
+++ b/test/src/module/config/configTest.c
@@ -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");
[parent: 57281d479296]