mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-18 04:58:51 +02:00
Add optional remove to TEST_STORAGE_EXISTS().
This allows TEST_STORAGE_EXISTS() to be used in most cases where TEST_STORAGE_REMOVE() was used before. Rename TEST_STORAGE_REMOVE() to HRN_STORAGE_REMOVE() now that is is no longer used as a test. Still allow an error when the file is missing just to help keep tests tidy.
This commit is contained in:
parent
4a075b7252
commit
c6a8528e31
@ -208,6 +208,9 @@ testStorageExists(const Storage *const storage, const char *const file, const Te
|
||||
hrnTestResultComment(param.comment);
|
||||
|
||||
hrnTestResultBool(storageExistsP(storage, fileFull), true);
|
||||
|
||||
if (param.remove)
|
||||
storageRemoveP(storage, fileFull, .errorOnMissing = true);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
@ -429,7 +432,7 @@ hrnStoragePathRemove(const Storage *const storage, const char *const path, HrnSt
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
hrnStorageRemove(const Storage *const storage, const char *const file, const TestStorageRemoveParam param)
|
||||
hrnStorageRemove(const Storage *const storage, const char *const file, const HrnStorageRemoveParam param)
|
||||
{
|
||||
hrnTestResultBegin(__func__, false);
|
||||
|
||||
@ -439,7 +442,7 @@ hrnStorageRemove(const Storage *const storage, const char *const file, const Tes
|
||||
printf("remove file '%s'", strZ(storagePathP(storage, STR(file))));
|
||||
hrnTestResultComment(param.comment);
|
||||
|
||||
storageRemoveP(storage, STR(file), .errorOnMissing = true);
|
||||
storageRemoveP(storage, STR(file), .errorOnMissing = param.errorOnMissing);
|
||||
|
||||
hrnTestResultEnd();
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ Check file exists
|
||||
typedef struct TestStorageExistsParam
|
||||
{
|
||||
VAR_PARAM_HEADER;
|
||||
bool remove; // Remove file after testing?
|
||||
const char *comment; // Comment
|
||||
} TestStorageExistsParam;
|
||||
|
||||
@ -171,23 +172,24 @@ void hrnStoragePut(
|
||||
HrnStoragePutParam param);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Remove a file and error if it does not exist
|
||||
Remove a file
|
||||
***********************************************************************************************************************************/
|
||||
typedef struct TestStorageRemoveParam
|
||||
typedef struct HrnStorageRemoveParam
|
||||
{
|
||||
VAR_PARAM_HEADER;
|
||||
bool errorOnMissing; // Error when the file is missing
|
||||
const char *comment; // Comment
|
||||
} TestStorageRemoveParam;
|
||||
} HrnStorageRemoveParam;
|
||||
|
||||
#define TEST_STORAGE_REMOVE(storage, file, ...) \
|
||||
#define HRN_STORAGE_REMOVE(storage, file, ...) \
|
||||
do \
|
||||
{ \
|
||||
hrnTestLogPrefix(__LINE__); \
|
||||
hrnStorageRemove(storage, file, (TestStorageRemoveParam){VAR_PARAM_INIT, __VA_ARGS__}); \
|
||||
hrnStorageRemove(storage, file, (HrnStorageRemoveParam){VAR_PARAM_INIT, __VA_ARGS__}); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
void hrnStorageRemove(const Storage *const storage, const char *const file, const TestStorageRemoveParam param);
|
||||
void hrnStorageRemove(const Storage *const storage, const char *const file, const HrnStorageRemoveParam param);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Change the time of a path/file
|
||||
|
@ -213,8 +213,9 @@ testRun(void)
|
||||
.remove = true);
|
||||
TEST_STORAGE_LIST(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN, "000000010000000100000001.pgbackrest.tmp\n");
|
||||
|
||||
TEST_STORAGE_REMOVE(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz");
|
||||
TEST_STORAGE_EXISTS(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz",
|
||||
.remove = true);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("single segment");
|
||||
@ -268,8 +269,9 @@ testRun(void)
|
||||
TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001", .remove = true);
|
||||
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
||||
|
||||
TEST_STORAGE_REMOVE(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz");
|
||||
TEST_STORAGE_EXISTS(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz",
|
||||
.remove = true);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("single segment with one invalid file");
|
||||
@ -305,8 +307,9 @@ testRun(void)
|
||||
TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000100000001", .remove = true);
|
||||
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
||||
|
||||
TEST_STORAGE_REMOVE(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz");
|
||||
TEST_STORAGE_EXISTS(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-2/000000010000000100000001-abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.gz",
|
||||
.remove = true);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("multiple segments where some are missing or errored and mismatched repo");
|
||||
@ -442,10 +445,12 @@ testRun(void)
|
||||
.remove = true);
|
||||
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
||||
|
||||
TEST_STORAGE_REMOVE(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
|
||||
TEST_STORAGE_REMOVE(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||
TEST_STORAGE_EXISTS(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||
.remove = true);
|
||||
TEST_STORAGE_EXISTS(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
.remove = true);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("warn on invalid file");
|
||||
@ -493,8 +498,9 @@ testRun(void)
|
||||
TEST_STORAGE_GET_EMPTY(storageSpoolWrite(), STORAGE_SPOOL_ARCHIVE_IN "/000000010000000200000000", .remove = true);
|
||||
TEST_STORAGE_LIST_EMPTY(storageSpool(), STORAGE_SPOOL_ARCHIVE_IN);
|
||||
|
||||
TEST_STORAGE_REMOVE(
|
||||
storageRepoIdxWrite(1), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||
TEST_STORAGE_EXISTS(
|
||||
storageRepoIdxWrite(1), STORAGE_REPO_ARCHIVE "/10-1/000000010000000200000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
.remove = true);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("error with warnings");
|
||||
@ -837,8 +843,9 @@ testRun(void)
|
||||
"HINT: are multiple primaries archiving to this stanza?");
|
||||
|
||||
TEST_STORAGE_LIST(storagePg(), "pg_wal", NULL);
|
||||
TEST_STORAGE_REMOVE(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
|
||||
TEST_STORAGE_EXISTS(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||
.remove = true);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("get from prior db-id");
|
||||
@ -871,10 +878,12 @@ testRun(void)
|
||||
TEST_RESULT_LOG("P00 INFO: found 01ABCDEF01ABCDEF01ABCDEF in the repo1: 10-4 archive");
|
||||
|
||||
TEST_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true);
|
||||
TEST_STORAGE_REMOVE(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||
TEST_STORAGE_REMOVE(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-4/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||
TEST_STORAGE_EXISTS(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-1/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
.remove = true);
|
||||
TEST_STORAGE_EXISTS(
|
||||
storageRepoWrite(), STORAGE_REPO_ARCHIVE "/10-4/01ABCDEF01ABCDEF01ABCDEF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
.remove = true);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("get partial");
|
||||
@ -898,9 +907,9 @@ testRun(void)
|
||||
TEST_RESULT_LOG("P00 INFO: found 000000010000000100000001.partial in the repo1: 10-4 archive");
|
||||
|
||||
TEST_STORAGE_LIST(storagePgWrite(), "pg_wal", "RECOVERYXLOG\n", .remove = true);
|
||||
TEST_STORAGE_REMOVE(
|
||||
TEST_STORAGE_EXISTS(
|
||||
storageRepoWrite(),
|
||||
STORAGE_REPO_ARCHIVE "/10-4/000000010000000100000001.partial-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||
STORAGE_REPO_ARCHIVE "/10-4/000000010000000100000001.partial-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", .remove = true);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("get missing history");
|
||||
|
@ -342,8 +342,9 @@ testRun(void)
|
||||
storageRepoIdx(0),
|
||||
strNewFmt(STORAGE_REPO_ARCHIVE "/11-1/000000010000000100000001-%s.gz", walBuffer1Sha1)),
|
||||
true, "check repo for WAL file");
|
||||
TEST_STORAGE_REMOVE(
|
||||
storageRepoIdxWrite(0), strZ(strNewFmt(STORAGE_REPO_ARCHIVE "/11-1/000000010000000100000001-%s.gz", walBuffer1Sha1)));
|
||||
TEST_STORAGE_EXISTS(
|
||||
storageRepoIdxWrite(0), strZ(strNewFmt(STORAGE_REPO_ARCHIVE "/11-1/000000010000000100000001-%s.gz", walBuffer1Sha1)),
|
||||
.remove = true);
|
||||
|
||||
// Generate valid WAL and push them
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
@ -582,10 +583,12 @@ testRun(void)
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("push succeeds on one repo when other repo fails to load archive.info");
|
||||
|
||||
TEST_STORAGE_REMOVE(
|
||||
storageTest, strZ(strNewFmt("repo2/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)));
|
||||
TEST_STORAGE_REMOVE(
|
||||
storageTest, strZ(strNewFmt("repo3/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)));
|
||||
TEST_STORAGE_EXISTS(
|
||||
storageTest, strZ(strNewFmt("repo2/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)),
|
||||
.remove = true);
|
||||
TEST_STORAGE_EXISTS(
|
||||
storageTest, strZ(strNewFmt("repo3/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)),
|
||||
.remove = true);
|
||||
HRN_STORAGE_MODE(storageTest, "repo2", .mode = 0200);
|
||||
|
||||
TEST_ERROR(
|
||||
@ -602,8 +605,9 @@ testRun(void)
|
||||
"HINT: use --no-archive-check to disable archive checks during backup if you have an alternate archiving scheme.");
|
||||
|
||||
// Make sure WAL got pushed to repo3
|
||||
TEST_STORAGE_REMOVE(
|
||||
storageTest, strZ(strNewFmt("repo3/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)));
|
||||
TEST_STORAGE_EXISTS(
|
||||
storageTest, strZ(strNewFmt("repo3/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)),
|
||||
.remove = true);
|
||||
|
||||
HRN_STORAGE_MODE(storageTest, "repo2");
|
||||
|
||||
@ -619,8 +623,9 @@ testRun(void)
|
||||
" [13] Permission denied");
|
||||
|
||||
// Make sure WAL got pushed to repo3
|
||||
TEST_STORAGE_REMOVE(
|
||||
storageTest, strZ(strNewFmt("repo3/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)));
|
||||
TEST_STORAGE_EXISTS(
|
||||
storageTest, strZ(strNewFmt("repo3/archive/test/11-1/0000000100000001/000000010000000100000002-%s", walBuffer2Sha1)),
|
||||
.remove = true);
|
||||
|
||||
HRN_STORAGE_MODE(storageTest, "repo2/archive/test/11-1");
|
||||
}
|
||||
|
@ -2422,9 +2422,9 @@ testRun(void)
|
||||
"compare file list");
|
||||
|
||||
// Remove test files
|
||||
TEST_STORAGE_REMOVE(storagePgWrite(), "base/1/2");
|
||||
TEST_STORAGE_REMOVE(storagePgWrite(), "base/1/3");
|
||||
TEST_STORAGE_REMOVE(storagePgWrite(), "base/1/4");
|
||||
HRN_STORAGE_REMOVE(storagePgWrite(), "base/1/2", .errorOnMissing = true);
|
||||
HRN_STORAGE_REMOVE(storagePgWrite(), "base/1/3", .errorOnMissing = true);
|
||||
HRN_STORAGE_REMOVE(storagePgWrite(), "base/1/4", .errorOnMissing = true);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -473,7 +473,7 @@ testRun(void)
|
||||
TEST_ERROR(cmdExpire(), StopError, "stop file exists for stanza db");
|
||||
|
||||
// Remove the stop file
|
||||
TEST_STORAGE_REMOVE(storagePosixNewP(HRN_PATH_STR, .write = true), strZ(lockStopFileName(cfgOptionStr(cfgOptStanza))));
|
||||
HRN_STORAGE_REMOVE(storagePosixNewP(HRN_PATH_STR, .write = true), strZ(lockStopFileName(cfgOptionStr(cfgOptStanza))));
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("retention-archive not set");
|
||||
|
Loading…
x
Reference in New Issue
Block a user