1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-05 00:28:52 +02:00

Move PostgreSQL version interface test functions to a test harness.

Some version interface test functions were integrated into the core code because they relied on the PostgreSQL versioned interface. Even though they were compiled out for production builds they cluttered the core code and made it harder to determine what was required by core.

Create a PostgreSQL version interface in a test harness to contain these functions. This does require some duplication but the cleaner core code seems a good tradeoff. It is possible for some of this code to be auto-generated but since it is only updated once per year the matter is not pressing.
This commit is contained in:
David Steele
2021-05-17 07:20:28 -04:00
parent 18cc02238b
commit ae7f0af202
33 changed files with 664 additions and 426 deletions

View File

@ -3,6 +3,8 @@ Test PostgreSQL Interface
***********************************************************************************************************************************/
#include "storage/posix/storage.h"
#include "common/harnessPostgres.h"
/***********************************************************************************************************************************
Test Run
***********************************************************************************************************************************/
@ -48,7 +50,7 @@ testRun(void)
String *controlFile = strNew(PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL);
// Create a bogus control file
Buffer *result = bufNew(PG_CONTROL_SIZE);
Buffer *result = bufNew(HRN_PG_CONTROL_SIZE);
memset(bufPtr(result), 0, bufSize(result));
bufUsedSet(result, bufSize(result));
@ -62,13 +64,10 @@ testRun(void)
pgControlFromBuffer(result), VersionNotSupportedError,
"unexpected control version = 501 and catalog version = 19780101\nHINT: is this version of PostgreSQL supported?");
//--------------------------------------------------------------------------------------------------------------------------
TEST_ERROR(pgControlTestToBuffer((PgControl){.version = 0}), AssertError, "invalid PostgreSQL version 0");
//--------------------------------------------------------------------------------------------------------------------------
storagePutP(
storageNewWriteP(storageTest, controlFile),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_11, .systemId = 0xFACEFACE, .walSegmentSize = 1024 * 1024}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_11, .systemId = 0xFACEFACE, .walSegmentSize = 1024 * 1024}));
PgControl info = {0};
TEST_ASSIGN(info, pgControlFromFile(storageTest), "get control info v11");
@ -79,7 +78,7 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
storagePutP(
storageNewWriteP(storageTest, controlFile),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_93, .walSegmentSize = 1024 * 1024}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_93, .walSegmentSize = 1024 * 1024}));
TEST_ERROR(
pgControlFromFile(storageTest), FormatError, "wal segment size is 1048576 but must be 16777216 for PostgreSQL <= 10");
@ -87,16 +86,16 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
storagePutP(
storageNewWriteP(storageTest, controlFile),
pgControlTestToBuffer((PgControl){.version = PG_VERSION_95, .pageSize = 32 * 1024}));
hrnPgControlToBuffer((PgControl){.version = PG_VERSION_95, .pageSize = 32 * 1024}));
TEST_ERROR(pgControlFromFile(storageTest), FormatError, "page size is 32768 but must be 8192");
//--------------------------------------------------------------------------------------------------------------------------
storagePutP(
storageNewWriteP(storageTest, controlFile),
pgControlTestToBuffer(
hrnPgControlToBuffer(
(PgControl){
.version = PG_VERSION_83, .systemId = 0xEFEFEFEFEF, .catalogVersion = pgCatalogTestVersion(PG_VERSION_83)}));
.version = PG_VERSION_83, .systemId = 0xEFEFEFEFEF, .catalogVersion = hrnPgCatalogVersion(PG_VERSION_83)}));
TEST_ASSIGN(info, pgControlFromFile(storageTest), "get control info v83");
TEST_RESULT_UINT(info.systemId, 0xEFEFEFEFEF, " check system id");
@ -209,11 +208,7 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
memset(bufPtr(result), 0, bufSize(result));
TEST_ERROR(pgWalTestToBuffer((PgWal){.version = 0}, result), AssertError, "invalid PostgreSQL version 0");
//--------------------------------------------------------------------------------------------------------------------------
memset(bufPtr(result), 0, bufSize(result));
pgWalTestToBuffer(
hrnPgWalToBuffer(
(PgWal){.version = PG_VERSION_11, .systemId = 0xECAFECAF, .size = PG_WAL_SEGMENT_SIZE_DEFAULT * 2}, result);
storagePutP(storageNewWriteP(storageTest, walFile), result);
@ -225,14 +220,14 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
memset(bufPtr(result), 0, bufSize(result));
pgWalTestToBuffer(
hrnPgWalToBuffer(
(PgWal){.version = PG_VERSION_83, .systemId = 0xEAEAEAEA, .size = PG_WAL_SEGMENT_SIZE_DEFAULT * 2}, result);
TEST_ERROR(pgWalFromBuffer(result), FormatError, "wal segment size is 33554432 but must be 16777216 for PostgreSQL <= 10");
//--------------------------------------------------------------------------------------------------------------------------
memset(bufPtr(result), 0, bufSize(result));
pgWalTestToBuffer((PgWal){.version = PG_VERSION_83, .systemId = 0xEAEAEAEA, .size = PG_WAL_SEGMENT_SIZE_DEFAULT}, result);
hrnPgWalToBuffer((PgWal){.version = PG_VERSION_83, .systemId = 0xEAEAEAEA, .size = PG_WAL_SEGMENT_SIZE_DEFAULT}, result);
storagePutP(storageNewWriteP(storageTest, walFile), result);
TEST_ASSIGN(info, pgWalFromFile(walFile, storageTest), "get wal info v8.3");