You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-05 00:28:52 +02:00
Allow control version and WAL magic to be overridden in test harness.
This makes it easier to write tests for invalid control version/WAL magic. Also add HRN_PG_WAL_TO_BUFFER() to simplify generation of WAL headers.
This commit is contained in:
@ -62,20 +62,14 @@ testRun(void)
|
||||
TEST_RESULT_UINT(pgInterface[0].version, PG_VERSION_MAX, "check max version");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
// Create a bogus control file
|
||||
Buffer *result = bufNew(HRN_PG_CONTROL_SIZE);
|
||||
memset(bufPtr(result), 0, bufSize(result));
|
||||
bufUsedSet(result, bufSize(result));
|
||||
TEST_TITLE("unknown control version");
|
||||
|
||||
*(PgControlCommon *)bufPtr(result) = (PgControlCommon)
|
||||
{
|
||||
.controlVersion = 501,
|
||||
.catalogVersion = 19780101,
|
||||
};
|
||||
HRN_PG_CONTROL_OVERRIDE_PUT(storageTest, PG_VERSION_15, 1501, .catalogVersion = 202211110);
|
||||
|
||||
TEST_ERROR(
|
||||
pgControlFromBuffer(result), VersionNotSupportedError,
|
||||
"unexpected control version = 501 and catalog version = 19780101\nHINT: is this version of PostgreSQL supported?");
|
||||
pgControlFromFile(storageTest), VersionNotSupportedError,
|
||||
"unexpected control version = 1501 and catalog version = 202211110\n"
|
||||
"HINT: is this version of PostgreSQL supported?");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
HRN_PG_CONTROL_PUT(
|
||||
@ -184,29 +178,29 @@ testRun(void)
|
||||
{
|
||||
const String *walFile = STRDEF(TEST_PATH "/0000000F0000000F0000000F");
|
||||
|
||||
// Create a bogus control file, initially not in long format)
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("unknown WAL magic");
|
||||
|
||||
Buffer *result = bufNew((size_t)16 * 1024 * 1024);
|
||||
memset(bufPtr(result), 0, bufSize(result));
|
||||
bufUsedSet(result, bufSize(result));
|
||||
|
||||
*(PgWalCommon *)bufPtr(result) = (PgWalCommon){.magic = 777};
|
||||
|
||||
TEST_ERROR(pgWalFromBuffer(result), FormatError, "first page header in WAL file is expected to be in long format");
|
||||
|
||||
// Add the long flag so that the version will now error
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
((PgWalCommon *)bufPtr(result))->flag = PG_WAL_LONG_HEADER;
|
||||
HRN_PG_WAL_OVERRIDE_TO_BUFFER(result, PG_VERSION_15, 777);
|
||||
|
||||
TEST_ERROR(
|
||||
pgWalFromBuffer(result), VersionNotSupportedError,
|
||||
"unexpected WAL magic 777\n"
|
||||
"HINT: is this version of PostgreSQL supported?");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("invalid wal flag");
|
||||
|
||||
((PgWalCommon *)bufPtr(result))->flag = 0;
|
||||
|
||||
TEST_ERROR(pgWalFromBuffer(result), FormatError, "first page header in WAL file is expected to be in long format");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
memset(bufPtr(result), 0, bufSize(result));
|
||||
hrnPgWalToBuffer(
|
||||
(PgWal){.version = PG_VERSION_11, .systemId = 0xECAFECAF, .size = PG_WAL_SEGMENT_SIZE_DEFAULT * 2}, result);
|
||||
HRN_PG_WAL_TO_BUFFER(result, PG_VERSION_11, .systemId = 0xECAFECAF, .size = PG_WAL_SEGMENT_SIZE_DEFAULT * 2);
|
||||
storagePutP(storageNewWriteP(storageTest, walFile), result);
|
||||
|
||||
PgWal info = {0};
|
||||
@ -217,14 +211,13 @@ testRun(void)
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
memset(bufPtr(result), 0, bufSize(result));
|
||||
hrnPgWalToBuffer(
|
||||
(PgWal){.version = PG_VERSION_96, .systemId = 0xEAEAEAEA, .size = PG_WAL_SEGMENT_SIZE_DEFAULT * 2}, result);
|
||||
HRN_PG_WAL_TO_BUFFER(result, PG_VERSION_96, .systemId = 0xEAEAEAEA, .size = PG_WAL_SEGMENT_SIZE_DEFAULT * 2);
|
||||
|
||||
TEST_ERROR(pgWalFromBuffer(result), FormatError, "wal segment size is 33554432 but must be 16777216 for PostgreSQL <= 10");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
memset(bufPtr(result), 0, bufSize(result));
|
||||
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_93, .systemId = 0xEAEAEAEA, .size = PG_WAL_SEGMENT_SIZE_DEFAULT}, result);
|
||||
HRN_PG_WAL_TO_BUFFER(result, PG_VERSION_93, .systemId = 0xEAEAEAEA, .size = PG_WAL_SEGMENT_SIZE_DEFAULT);
|
||||
storagePutP(storageNewWriteP(storageTest, walFile), result);
|
||||
|
||||
TEST_ASSIGN(info, pgWalFromFile(walFile, storageTest), "get wal info v9.3");
|
||||
|
Reference in New Issue
Block a user