1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-11-06 08:49:29 +02:00

Update unit tests for stricter option validity.

Some tests used options in contexts that are currently valid but are not correct usage, i.e. usage of internal options for the default role.

Update these tests in advance of the option validity becoming stricter.
This commit is contained in:
David Steele
2020-12-28 15:22:21 -05:00
parent 23f5712d02
commit 26e81785d9
3 changed files with 15 additions and 9 deletions

View File

@@ -1216,7 +1216,6 @@ testRun(void)
strLstAdd(argList, strNewFmt("--config=%s", strZ(configFile)));
strLstAdd(argList, strNew("--no-online"));
hrnCfgArgKeyRawBool(argList, cfgOptPgLocal, 2, true);
hrnCfgArgRawZ(argList, cfgOptPg, "2");
strLstAdd(argList, strNew("--reset-pg1-host"));
strLstAdd(argList, strNew("--reset-pg3-host"));
strLstAdd(argList, strNew("--reset-backup-standby"));
@@ -1283,9 +1282,9 @@ testRun(void)
TEST_RESULT_BOOL(cfgOptionIdxTest(cfgOptPgHost, 0), false, " pg1-host is not set (command line reset override)");
TEST_RESULT_BOOL(cfgOptionIdxReset(cfgOptPgHost, 0), true, " pg1-host was reset");
TEST_RESULT_UINT(cfgOptionGroupIdxDefault(cfgOptGrpPg), 1, " pg2 is default");
TEST_RESULT_UINT(cfgOptionGroupIdxToKey(cfgOptGrpPg, 1), 2, " pg2 is index 1");
TEST_RESULT_STR_Z(cfgOptionStr(cfgOptPgPath), "/path/to/db2", " default pg-path");
TEST_RESULT_UINT(cfgOptionGroupIdxDefault(cfgOptGrpPg), 0, " pg1 is default");
TEST_RESULT_UINT(cfgOptionGroupIdxToKey(cfgOptGrpPg, 1), 2, " pg2 is index 2");
TEST_RESULT_STR_Z(cfgOptionStr(cfgOptPgPath), "/path/to/db", " default pg-path");
TEST_RESULT_UINT(cfgOptionGroupIdxTotal(cfgOptGrpPg), 2, " pg1 and pg2 are set");
TEST_RESULT_BOOL(cfgOptionIdxBool(cfgOptPgLocal, 1), true, " pg2-local is set");
TEST_RESULT_BOOL(cfgOptionIdxTest(cfgOptPgHost, 1), false, " pg2-host is not set (pg2-local override)");
@@ -1321,7 +1320,7 @@ testRun(void)
TEST_RESULT_UINT(cfgOptionIdxUInt64(cfgOptPgPort, 1), 5432, " pg2-port is set");
TEST_RESULT_STR(cfgOptionIdxStrNull(cfgOptPgHost, 1), NULL, " pg2-host is NULL");
TEST_RESULT_STR(cfgOptionStrNull(cfgOptPgHost), NULL, " pg2-host is NULL");
TEST_ERROR(cfgOptionStr(cfgOptPgHost), AssertError, "option 'pg2-host' is null but non-null was requested");
TEST_ERROR(cfgOptionIdxStr(cfgOptPgHost, 1), AssertError, "option 'pg2-host' is null but non-null was requested");
TEST_RESULT_BOOL(varBool(cfgOptionDefault(cfgOptBackupStandby)), false, " backup-standby default is false");
TEST_RESULT_BOOL(varBool(cfgOptionDefault(cfgOptBackupStandby)), false, " backup-standby default is false (again)");
@@ -1336,7 +1335,7 @@ testRun(void)
TEST_ERROR(cfgOptionDefaultValue(cfgOptDbInclude), AssertError, "default value not available for option type 3");
TEST_ERROR(cfgOptionLst(cfgOptDbInclude), AssertError, "option 'db-include' is not valid for the current command");
TEST_ERROR(cfgOptionKv(cfgOptPgPath), AssertError, "option 'pg2-path' is type 4 but 3 was requested");
TEST_ERROR(cfgOptionKv(cfgOptPgPath), AssertError, "option 'pg1-path' is type 4 but 3 was requested");
TEST_RESULT_VOID(cfgOptionInvalidate(cfgOptPgPath), " invalidate pg-path");
TEST_RESULT_BOOL(cfgOptionValid(cfgOptPgPath), false, " pg-path no longer valid");
@@ -1470,11 +1469,15 @@ testRun(void)
setenv("PGBACKREST_STANZA", "db", true);
setenv("PGBACKREST_PG1_PATH", "/path/to/db", true);
hrnCfgEnvKeyRawZ(cfgOptPgPath, 2, "/path/to/db2");
hrnCfgEnvRawZ(cfgOptPg, "2");
setenv("PGBACKREST_RECOVERY_OPTION", "f=g:hijk=l", true);
setenv("PGBACKREST_DB_INCLUDE", "77", true);
TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), TEST_COMMAND_RESTORE " command");
TEST_RESULT_STR_Z(cfgOptionStr(cfgOptPgPath), "/path/to/db2", "default pg-path");
TEST_ASSIGN(recoveryKv, cfgOptionKv(cfgOptRecoveryOption), "get recovery options");
TEST_RESULT_STR_Z(varStr(kvGet(recoveryKv, varNewStr(strNew("f")))), "g", "check recovery option");
TEST_RESULT_STR_Z(varStr(kvGet(recoveryKv, varNewStr(strNew("hijk")))), "l", "check recovery option");
@@ -1483,6 +1486,8 @@ testRun(void)
unsetenv("PGBACKREST_STANZA");
unsetenv("PGBACKREST_PG1_PATH");
hrnCfgEnvKeyRemoveRaw(cfgOptPgPath, 2);
hrnCfgEnvRemoveRaw(cfgOptPg);
unsetenv("PGBACKREST_RECOVERY_OPTION");
unsetenv("PGBACKREST_DB_INCLUDE");
@@ -1567,7 +1572,9 @@ testRun(void)
hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 1, "/pg1");
hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 8, "/pg8");
hrnCfgArgRawZ(argList, cfgOptPg, "4");
TEST_ERROR(harnessCfgLoad(cfgCmdCheck, argList), OptionInvalidValueError, "key '4' is not valid for 'pg' option");
TEST_ERROR(
harnessCfgLoadRole(cfgCmdCheck, cfgCmdRoleRemote, argList), OptionInvalidValueError,
"key '4' is not valid for 'pg' option");
}
// *****************************************************************************************************************************

View File

@@ -237,7 +237,6 @@ testRun(void)
strLstAddZ(argList, "pgbackrest");
strLstAddZ(argList, "--stanza=test1");
strLstAddZ(argList, "--pg1-path=/pg");
hrnCfgArgRawReset(argList, cfgOptPg);
strLstAddZ(argList, "--repo1-retention-full=1");
strLstAddZ(argList, "--log-subprocess");
strLstAddZ(argList, "backup");

View File

@@ -32,7 +32,7 @@ testRun(void)
strLstAddZ(argList, "--repo1-host=localhost");
strLstAdd(argList, strNewFmt("--repo1-host-user=%s", testUser()));
strLstAdd(argList, strNewFmt("--repo1-path=%s/repo", testPath()));
harnessCfgLoad(cfgCmdArchivePush, argList);
harnessCfgLoadRole(cfgCmdArchivePush, cfgCmdRoleLocal, argList);
// Set type since we'll be running local and remote tests here
cfgOptionSet(cfgOptRemoteType, cfgSourceParam, VARSTRDEF("repo"));