mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-30 05:39:12 +02:00
Use harnessCfgLoad() in config/load unit tests.
The tests were originally written by loading values directly into the configuration before the parser was available. Update to use harnessCfgLoad() to simplify the tests and make them compatible with upcoming config changes.
This commit is contained in:
parent
d91e6014bd
commit
d25e965c47
@ -19,7 +19,7 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("cfgLoadLogSetting()"))
|
||||
{
|
||||
cfgInit();
|
||||
harnessCfgLoad(cfgCmdVersion, strLstNew());
|
||||
|
||||
TEST_RESULT_VOID(cfgLoadLogSetting(), "load log settings all defaults");
|
||||
|
||||
@ -32,102 +32,129 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("cfgLoadUpdateOption()"))
|
||||
{
|
||||
String *exe = strNew("/path/to/pgbackrest");
|
||||
String *exeOther = strNew("/other/path/to/pgbackrest");
|
||||
TEST_TITLE("repo-host-cmd is defaulted when null");
|
||||
|
||||
cfgInit();
|
||||
cfgCommandSet(cfgCmdBackup, cfgCmdRoleDefault);
|
||||
cfgExeSet(exe);
|
||||
|
||||
cfgOptionValidSet(cfgOptRepoHost, true);
|
||||
cfgOptionValidSet(cfgOptRepoHostCmd, true);
|
||||
cfgOptionValidSet(cfgOptPgHost, true);
|
||||
|
||||
TEST_RESULT_VOID(cfgLoadUpdateOption(), "hosts are not set so don't update commands");
|
||||
StringList *argList = strLstNew();
|
||||
hrnCfgArgRawZ(argList, cfgOptStanza, "test");
|
||||
hrnCfgArgRawZ(argList, cfgOptPgPath, "/pg1");
|
||||
harnessCfgLoad(cfgCmdCheck, argList);
|
||||
|
||||
cfgOptionSet(cfgOptRepoHost, cfgSourceParam, varNewStrZ("repo-host"));
|
||||
|
||||
TEST_RESULT_VOID(cfgLoadUpdateOption(), "repo remote command is updated");
|
||||
TEST_RESULT_STR(cfgOptionStr(cfgOptRepoHostCmd), exe, " check repo1-host-cmd");
|
||||
TEST_RESULT_STR_Z(cfgOptionStr(cfgOptRepoHostCmd), testProjectExe(), " check repo1-host-cmd");
|
||||
|
||||
cfgOptionSet(cfgOptRepoHostCmd, cfgSourceParam, varNewStr(exeOther));
|
||||
cfgOptionSet(cfgOptRepoHostCmd, cfgSourceParam, VARSTRDEF("/other"));
|
||||
|
||||
TEST_RESULT_VOID(cfgLoadUpdateOption(), "repo remote command was already set");
|
||||
TEST_RESULT_STR(cfgOptionStr(cfgOptRepoHostCmd), exeOther, " check repo1-host-cmd");
|
||||
|
||||
cfgOptionSet(cfgOptRepoHost, cfgSourceParam, NULL);
|
||||
TEST_RESULT_STR_Z(cfgOptionStr(cfgOptRepoHostCmd), "/other", " check repo1-host-cmd");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
cfgOptionValidSet(cfgOptPgHostCmd, true);
|
||||
cfgOptionSet(cfgOptPgHost, cfgSourceParam, varNewStrZ("pg1-host"));
|
||||
TEST_TITLE("pg-host-cmd is defaulted when null");
|
||||
|
||||
cfgOptionValidSet(cfgOptPgHost + 1, true);
|
||||
cfgOptionSet(cfgOptPgHost + 1, cfgSourceParam, varNewStrZ("pg2-host"));
|
||||
cfgOptionValidSet(cfgOptPgHostCmd + 1, true);
|
||||
cfgOptionSet(cfgOptPgHostCmd + 1, cfgSourceParam, varNewStr(exeOther));
|
||||
argList = strLstNew();
|
||||
hrnCfgArgRawZ(argList, cfgOptStanza, "test");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 1, "/pg1");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptPgHost, 1, "pg1");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 2, "/pg2");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptPgHost, 2, "pg2");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptPgHostCmd, 2, "pg2-exe");
|
||||
harnessCfgLoad(cfgCmdCheck, argList);
|
||||
|
||||
cfgOptionValidSet(cfgOptPgHostCmd + 2, true);
|
||||
|
||||
cfgOptionValidSet(cfgOptPgHost + cfgDefOptionIndexTotal(cfgDefOptPgHost) - 1, true);
|
||||
cfgOptionSet(cfgOptPgHost + cfgDefOptionIndexTotal(cfgDefOptPgHost) - 1, cfgSourceParam, varNewStrZ("pgX-host"));
|
||||
cfgOptionValidSet(cfgOptPgHostCmd + cfgDefOptionIndexTotal(cfgDefOptPgHost) - 1, true);
|
||||
|
||||
TEST_RESULT_VOID(cfgLoadUpdateOption(), "pg remote command is updated");
|
||||
TEST_RESULT_STR(cfgOptionStr(cfgOptPgHostCmd), exe, " check pg1-host-cmd");
|
||||
TEST_RESULT_STR(cfgOptionStr(cfgOptPgHostCmd + 1), exeOther, " check pg2-host-cmd is already set");
|
||||
TEST_RESULT_STR(cfgOptionStrNull(cfgOptPgHostCmd + 2), NULL, " check pg3-host-cmd is not set");
|
||||
TEST_RESULT_STR(cfgOptionStr(cfgOptPgHostCmd + cfgDefOptionIndexTotal(cfgDefOptPgHost) - 1), exe, " check pgX-host-cmd");
|
||||
TEST_RESULT_STR_Z(cfgOptionStr(cfgOptPgHostCmd + 0), testProjectExe(), " check pg1-host-cmd");
|
||||
TEST_RESULT_STR_Z(cfgOptionStr(cfgOptPgHostCmd + 1), "pg2-exe", " check pg2-host-cmd");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
cfgInit();
|
||||
TEST_TITLE("db-timeout set but not protocol timeout");
|
||||
|
||||
cfgOptionValidSet(cfgOptDbTimeout, true);
|
||||
cfgOptionSet(cfgOptDbTimeout, cfgSourceParam, varNewDbl(100));
|
||||
TEST_RESULT_VOID(cfgLoadUpdateOption(), "pg timeout set but not protocol timeout");
|
||||
argList = strLstNew();
|
||||
hrnCfgArgRawZ(argList, cfgOptStanza, "test");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 1, "/pg1");
|
||||
hrnCfgArgRawZ(argList, cfgOptDbTimeout, "100");
|
||||
harnessCfgLoad(cfgCmdCheck, argList);
|
||||
|
||||
cfgOptionValidSet(cfgOptProtocolTimeout, true);
|
||||
cfgOptionSet(cfgOptProtocolTimeout, cfgSourceDefault, varNewDbl(101));
|
||||
TEST_RESULT_VOID(cfgLoadUpdateOption(), "protocol timeout > pg timeout");
|
||||
cfgOptionValidSet(cfgOptProtocolTimeout, false);
|
||||
cfgLoadUpdateOption();
|
||||
|
||||
cfgOptionSet(cfgOptDbTimeout, cfgSourceParam, varNewDbl(100000));
|
||||
TEST_RESULT_VOID(cfgLoadUpdateOption(), "protocol timeout set automatically");
|
||||
TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptProtocolTimeout), 100030, " check protocol timeout");
|
||||
TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptDbTimeout), 100, "check db-timeout");
|
||||
|
||||
cfgOptionValidSet(cfgOptProtocolTimeout, true);
|
||||
cfgOptionSet(cfgOptProtocolTimeout, cfgSourceParam, varNewDbl(50.5));
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("protocol-timeout set but not db timeout");
|
||||
|
||||
argList = strLstNew();
|
||||
hrnCfgArgRawZ(argList, cfgOptStanza, "test");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 1, "/pg1");
|
||||
hrnCfgArgRawZ(argList, cfgOptProtocolTimeout, "100");
|
||||
harnessCfgLoad(cfgCmdCheck, argList);
|
||||
|
||||
cfgOptionValidSet(cfgOptDbTimeout, false);
|
||||
cfgLoadUpdateOption();
|
||||
|
||||
TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptProtocolTimeout), 100, "check protocol-timeout");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("protocol-timeout set automatically");
|
||||
|
||||
argList = strLstNew();
|
||||
hrnCfgArgRawZ(argList, cfgOptStanza, "test");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 1, "/pg1");
|
||||
hrnCfgArgRawZ(argList, cfgOptDbTimeout, "100000");
|
||||
harnessCfgLoad(cfgCmdCheck, argList);
|
||||
|
||||
TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptProtocolTimeout), 100030, "check protocol-timeout");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("error when db-timeout and protocol-timeout set but invalid");
|
||||
|
||||
argList = strLstNew();
|
||||
hrnCfgArgRawZ(argList, cfgOptStanza, "test");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 1, "/pg1");
|
||||
hrnCfgArgRawZ(argList, cfgOptDbTimeout, "100000");
|
||||
hrnCfgArgRawZ(argList, cfgOptProtocolTimeout, "50.5");
|
||||
TEST_ERROR(
|
||||
cfgLoadUpdateOption(), OptionInvalidValueError,
|
||||
harnessCfgLoad(cfgCmdCheck, argList), 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).");
|
||||
|
||||
cfgOptionSet(cfgOptProtocolTimeout, cfgSourceParam, varNewDbl(45));
|
||||
cfgOptionSet(cfgOptDbTimeout, cfgSourceDefault, varNewDbl(3600));
|
||||
TEST_RESULT_VOID(cfgLoadUpdateOption(), "set default pg timeout to be less than protocol timeout");
|
||||
TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptProtocolTimeout), 45, " check protocol timeout");
|
||||
TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptDbTimeout), 15, " check db timeout");
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("very small protocol-timeout triggers db-timeout special handling");
|
||||
|
||||
cfgOptionSet(cfgOptProtocolTimeout, cfgSourceParam, varNewDbl(11));
|
||||
cfgOptionSet(cfgOptDbTimeout, cfgSourceDefault, varNewDbl(3600));
|
||||
TEST_RESULT_VOID(cfgLoadUpdateOption(), "set default pg timeout to be less than test protocol timeout");
|
||||
TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptProtocolTimeout), 11, " check protocol timeout");
|
||||
TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptDbTimeout), 5.5, " check db timeout");
|
||||
argList = strLstNew();
|
||||
hrnCfgArgRawZ(argList, cfgOptStanza, "test");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 1, "/pg1");
|
||||
hrnCfgArgRawZ(argList, cfgOptProtocolTimeout, "11");
|
||||
harnessCfgLoad(cfgCmdCheck, argList);
|
||||
|
||||
TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptProtocolTimeout), 11, "check protocol-timeout");
|
||||
TEST_RESULT_DOUBLE(cfgOptionDbl(cfgOptDbTimeout), 5.5, "check db-timeout");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
cfgInit();
|
||||
cfgCommandSet(cfgCmdBackup, cfgCmdRoleDefault);
|
||||
cfgExeSet(exe);
|
||||
TEST_TITLE("pg and repo cannot both be remote");
|
||||
|
||||
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");
|
||||
argList = strLstNew();
|
||||
hrnCfgArgRawZ(argList, cfgOptStanza, "test");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 1, "/pg1");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 4, "/pg4");
|
||||
hrnCfgArgKeyRawZ(argList, cfgOptPgHost, 4, "pg4");
|
||||
hrnCfgArgRawZ(argList, cfgOptRepoHost, "repo1");
|
||||
TEST_ERROR(harnessCfgLoad(cfgCmdCheck, argList), ConfigError, "pg and repo hosts cannot both be configured as remote");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
StringList *argList = strLstNew();
|
||||
TEST_TITLE("only pg can be remote");
|
||||
|
||||
// We'll have to cheat here and invalidate the repo-host option since there are currently no pg-only commands
|
||||
cfgOptionValidSet(cfgOptRepoHost, false);
|
||||
cfgLoadUpdateOption();
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("only repo can be remote");
|
||||
|
||||
argList = strLstNew();
|
||||
hrnCfgArgRawZ(argList, cfgOptRepoHost, "repo1");
|
||||
harnessCfgLoad(cfgCmdInfo, argList);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
argList = strLstNew();
|
||||
strLstAdd(argList, strNew("backup"));
|
||||
strLstAdd(argList, strNew("process-max"));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user