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

Add coverage for empty CATCH() blocks.

Currently empty CATCH() blocks are always marked as covered because of the loop structure of error handling.

A prototype implementation of error handling without looping has shown that these CATCH() blocks are not covered without new tests. Whether or not that prototype gets committed it is worth adding the tests.
This commit is contained in:
David Steele 2021-10-26 13:53:44 -04:00
parent e2eea974c1
commit d74fe7a222
2 changed files with 33 additions and 11 deletions

View File

@ -1191,6 +1191,27 @@ testRun(void)
cfgOptionSet(cfgOptResume, cfgSourceParam, BOOL_TRUE_VAR);
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("cannot resume when error on manifest load");
Manifest *manifest = NULL;
OBJ_NEW_BEGIN(Manifest)
{
manifest = manifestNewInternal();
manifest->pub.data.backupType = backupTypeFull;
manifest->pub.data.backrestVersion = STRDEF("BOGUS");
}
OBJ_NEW_END();
HRN_STORAGE_PUT_Z(storageRepoWrite(), STORAGE_REPO_BACKUP "/20191003-105320F/" BACKUP_MANIFEST_FILE INFO_COPY_EXT, "X");
TEST_RESULT_PTR(backupResumeFind(manifest, NULL), NULL, "find resumable backup");
TEST_RESULT_LOG(
"P00 WARN: backup '20191003-105320F' cannot be resumed: unable to read"
" <REPO:BACKUP>/20191003-105320F/backup.manifest.copy");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("cannot resume when pgBackRest version has changed");
@ -1216,16 +1237,6 @@ testRun(void)
storageNewWriteP(
storageRepoWrite(), STRDEF(STORAGE_REPO_BACKUP "/20191003-105320F/" BACKUP_MANIFEST_FILE INFO_COPY_EXT))));
Manifest *manifest = NULL;
OBJ_NEW_BEGIN(Manifest)
{
manifest = manifestNewInternal();
manifest->pub.data.backupType = backupTypeFull;
manifest->pub.data.backrestVersion = STRDEF("BOGUS");
}
OBJ_NEW_END();
TEST_RESULT_PTR(backupResumeFind(manifest, NULL), NULL, "find resumable backup");
TEST_RESULT_LOG(

View File

@ -179,6 +179,12 @@ testRun(void)
// Not in a test wrapper to avoid writing to stdout
cmdStorageList();
// Close the fd to make sure the error gets caught
close(STDOUT_FILENO);
// // Not in a test wrapper to avoid writing to stdout
cmdStorageList();
// Restore normal stdout
dup2(stdoutSave, STDOUT_FILENO);
@ -530,12 +536,17 @@ testRun(void)
// Not in a test wrapper to avoid writing to stdout
ASSERT(cmdStorageGet() == 0);
// Close the fd to make sure the error gets caught
close(STDOUT_FILENO);
// Not in a test wrapper to avoid writing to stdout
ASSERT(cmdStorageGet() == 1);
// Restore normal stdout
dup2(stdoutSave, STDOUT_FILENO);
TEST_STORAGE_GET(storageRepo(), "stdout.txt", fileRawContent, .comment = "get matches put");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("ignore missing file");