1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-15 01:04:37 +02:00

Improve protocol handlers.

Make protocol handlers have one function per command. This allows the logic of finding the handler to be in ProtocolServer, isolates each command to a function, and removes the need to test the "not found" condition for each handler.
This commit is contained in:
David Steele
2021-03-16 13:09:34 -04:00
committed by GitHub
parent b1d945ebb7
commit 2016fac0d9
34 changed files with 866 additions and 611 deletions

View File

@ -470,7 +470,7 @@ testRun(void)
}
// *****************************************************************************************************************************
if (testBegin("backupFile(), backupProtocol"))
if (testBegin("backupFile() and backupFileProtocol()"))
{
// Load Parameters
StringList *argList = strLstNew();
@ -513,8 +513,7 @@ testRun(void)
varLstAdd(paramList, varNewUInt(cipherTypeNone)); // cipherType
varLstAdd(paramList, NULL); // cipherSubPass
TEST_RESULT_BOOL(
backupProtocol(PROTOCOL_COMMAND_BACKUP_FILE_STR, paramList, server), true, "protocol backup file - skip");
TEST_RESULT_VOID(backupFileProtocol(paramList, server), "protocol backup file - skip");
TEST_RESULT_STR_Z(strNewBuf(serverWrite), "{\"out\":[3,0,0,null,null]}\n", " check result");
bufUsedSet(serverWrite, 0);
@ -606,8 +605,7 @@ testRun(void)
varLstAdd(paramList, varNewUInt(cipherTypeNone)); // cipherType
varLstAdd(paramList, NULL); // cipherSubPass
TEST_RESULT_BOOL(
backupProtocol(PROTOCOL_COMMAND_BACKUP_FILE_STR, paramList, server), true, "protocol backup file - pageChecksum");
TEST_RESULT_VOID(backupFileProtocol(paramList, server), "protocol backup file - pageChecksum");
TEST_RESULT_STR_Z(
strNewBuf(serverWrite),
"{\"out\":[1,12,12,\"c3ae4687ea8ccd47bfdb190dbe7fd3b37545fdb9\",{\"align\":false,\"valid\":false}]}\n",
@ -650,8 +648,7 @@ testRun(void)
varLstAdd(paramList, varNewUInt(cipherTypeNone)); // cipherType
varLstAdd(paramList, NULL); // cipherSubPass
TEST_RESULT_BOOL(
backupProtocol(PROTOCOL_COMMAND_BACKUP_FILE_STR, paramList, server), true, "protocol backup file - noop");
TEST_RESULT_VOID(backupFileProtocol(paramList, server), "protocol backup file - noop");
TEST_RESULT_STR_Z(
strNewBuf(serverWrite), "{\"out\":[4,12,0,\"c3ae4687ea8ccd47bfdb190dbe7fd3b37545fdb9\",null]}\n", " check result");
bufUsedSet(serverWrite, 0);
@ -793,8 +790,7 @@ testRun(void)
varLstAdd(paramList, varNewUInt(cipherTypeNone)); // cipherType
varLstAdd(paramList, NULL); // cipherSubPass
TEST_RESULT_BOOL(
backupProtocol(PROTOCOL_COMMAND_BACKUP_FILE_STR, paramList, server), true, "protocol backup file - copy, compress");
TEST_RESULT_VOID(backupFileProtocol(paramList, server), "protocol backup file - copy, compress");
TEST_RESULT_STR_Z(
strNewBuf(serverWrite), "{\"out\":[0,9,29,\"9bc8ab2dda60ef4beed07d1e19ce0676d5edde67\",null]}\n", " check result");
bufUsedSet(serverWrite, 0);
@ -817,10 +813,6 @@ testRun(void)
(storageExistsP(storageRepo(), strNewFmt(STORAGE_REPO_BACKUP "/%s/zerofile", strZ(backupLabel))) &&
result.pageChecksumResult == NULL),
true, " copy zero file to repo success");
// Check invalid protocol function
// -------------------------------------------------------------------------------------------------------------------------
TEST_RESULT_BOOL(backupProtocol(strNew(BOGUS_STR), paramList, server), false, "invalid function");
}
// *****************************************************************************************************************************
@ -913,8 +905,7 @@ testRun(void)
varLstAdd(paramList, varNewUInt(cipherTypeAes256Cbc)); // cipherType
varLstAdd(paramList, varNewStrZ("12345678")); // cipherPass
TEST_RESULT_BOOL(
backupProtocol(PROTOCOL_COMMAND_BACKUP_FILE_STR, paramList, server), true, "protocol backup file - recopy, encrypt");
TEST_RESULT_VOID(backupFileProtocol(paramList, server), "protocol backup file - recopy, encrypt");
TEST_RESULT_STR_Z(
strNewBuf(serverWrite), "{\"out\":[2,9,32,\"9bc8ab2dda60ef4beed07d1e19ce0676d5edde67\",null]}\n", " check result");
bufUsedSet(serverWrite, 0);