1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +02:00

Add harnessInfoChecksum/Z() to ease creation of test info files.

This commit is contained in:
David Steele 2019-04-23 14:02:30 -04:00
parent aebac47cd5
commit f41112a463
9 changed files with 114 additions and 153 deletions

View File

@ -74,6 +74,14 @@
</release-item>
</release-development-list>
</release-core-list>
<release-test-list>
<release-development-list>
<release-item>
<p>Add <code>harnessInfoChecksum/Z()</code> to ease creation of test info files.</p>
</release-item>
</release-development-list>
</release-test-list>
</release>
<release date="2019-04-18" version="2.13" title="Bug Fixes">

View File

@ -0,0 +1,55 @@
/***********************************************************************************************************************************
Harness for Loading Test Configurations
***********************************************************************************************************************************/
#include "common/harnessDebug.h"
#include "common/harnessInfo.h"
#include "common/io/bufferWrite.h"
#include "common/type/json.h"
#include "info/info.h"
#include "version.h"
/***********************************************************************************************************************************
Load a test configuration without any side effects
There's no need to open log files, acquire locks, reset log levels, etc.
***********************************************************************************************************************************/
Buffer *
harnessInfoChecksum(const String *info)
{
FUNCTION_HARNESS_BEGIN();
FUNCTION_HARNESS_PARAM(STRING, info);
FUNCTION_HARNESS_END();
Buffer *result = NULL;
MEM_CONTEXT_TEMP_BEGIN()
{
// Load data into an ini file
Ini *ini = iniNew();
iniParse(ini, info);
// Add header and checksum values
iniSet(ini, STRDEF("backrest"), STRDEF("backrest-version"), jsonFromStr(STRDEF(PROJECT_VERSION)));
iniSet(ini, STRDEF("backrest"), STRDEF("backrest-format"), jsonFromUInt(REPOSITORY_FORMAT));
iniSet(ini, STRDEF("backrest"), STRDEF("backrest-checksum"), jsonFromStr(infoHash(ini)));
// Write to a buffer
result = bufNew(0);
iniSave(ini, ioBufferWriteIo(ioBufferWriteNew(result)));
bufMove(result, MEM_CONTEXT_OLD());
}
MEM_CONTEXT_TEMP_END();
FUNCTION_HARNESS_RESULT(BUFFER, result);
}
Buffer *
harnessInfoChecksumZ(const char *info)
{
FUNCTION_HARNESS_BEGIN();
FUNCTION_HARNESS_PARAM(STRINGZ, info);
FUNCTION_HARNESS_END();
FUNCTION_HARNESS_RESULT(BUFFER, harnessInfoChecksum(STRDEF(info)));
}

View File

@ -0,0 +1,10 @@
/***********************************************************************************************************************************
Harness for Generating Test Info Files
***********************************************************************************************************************************/
#include "common/type/buffer.h"
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
Buffer *harnessInfoChecksum(const String *info);
Buffer *harnessInfoChecksumZ(const char *info);

View File

@ -1,16 +1,17 @@
/***********************************************************************************************************************************
Test Archive Get Command
***********************************************************************************************************************************/
#include "postgres/interface.h"
#include "postgres/version.h"
#include "common/compress/gzip/compress.h"
#include "common/harnessConfig.h"
#include "common/harnessFork.h"
#include "common/io/bufferRead.h"
#include "common/io/bufferWrite.h"
#include "postgres/interface.h"
#include "postgres/version.h"
#include "storage/driver/posix/storage.h"
#include "common/harnessInfo.h"
/***********************************************************************************************************************************
Test Run
***********************************************************************************************************************************/
@ -53,12 +54,7 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
storagePutNP(
storageNewWriteNP(storageTest, strNew("repo/archive/test1/archive.info")),
BUFSTRDEF(
"[backrest]\n"
"backrest-checksum=\"806471e1481804dc3ddf8dc6f1da7c34939420a8\"\n"
"backrest-format=5\n"
"backrest-version=\"2.06\"\n"
"\n"
harnessInfoChecksumZ(
"[db]\n"
"db-id=1\n"
"\n"
@ -73,12 +69,7 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
storagePutNP(
storageNewWriteNP(storageTest, strNew("repo/archive/test1/archive.info")),
BUFSTRDEF(
"[backrest]\n"
"backrest-checksum=\"4120e2a5c3918a480af951fb99bee7dc091f080a\"\n"
"backrest-format=5\n"
"backrest-version=\"2.06\"\n"
"\n"
harnessInfoChecksumZ(
"[db]\n"
"db-id=3\n"
"\n"
@ -151,12 +142,7 @@ testRun(void)
// Create archive.info
storagePutNP(
storageNewWriteNP(storageTest, strNew("repo/archive/test1/archive.info")),
BUFSTRDEF(
"[backrest]\n"
"backrest-checksum=\"bf9d69c6131e906898511432b4445335f377b12b\"\n"
"backrest-format=5\n"
"backrest-version=\"2.06\"\n"
"\n"
harnessInfoChecksumZ(
"[db]\n"
"db-id=1\n"
"\n"
@ -208,12 +194,7 @@ testRun(void)
storagePutNP(
infoWrite,
BUFSTRDEF(
"[backrest]\n"
"backrest-checksum=\"5e4bf8cafff30b488c01574411e858c7866df4a2\"\n"
"backrest-format=5\n"
"backrest-version=\"2.06\"\n"
"\n"
harnessInfoChecksumZ(
"[cipher]\n"
"cipher-pass=\"worstpassphraseever\"\n"
"\n"
@ -372,12 +353,7 @@ testRun(void)
storagePutNP(
storageNewWriteNP(storageTest, strNew("repo/archive/test2/archive.info")),
BUFSTRDEF(
"[backrest]\n"
"backrest-checksum=\"398aa38312ce69e3625b2ecfb4dfc6387e5ce7d3\"\n"
"backrest-format=5\n"
"backrest-version=\"2.11\"\n"
"\n"
harnessInfoChecksumZ(
"[db]\n"
"db-id=1\n"
"\n"

View File

@ -11,6 +11,7 @@ Test Archive Push Command
#include "common/harnessConfig.h"
#include "common/harnessFork.h"
#include "common/harnessInfo.h"
/***********************************************************************************************************************************
Test Run
@ -128,12 +129,7 @@ testRun(void)
// Create incorrect archive info
storagePutNP(
storageNewWriteNP(storageTest, strNew("repo/archive/test/archive.info")),
BUFSTRDEF(
"[backrest]\n"
"backrest-checksum=\"806471e1481804dc3ddf8dc6f1da7c34939420a8\"\n"
"backrest-format=5\n"
"backrest-version=\"2.06\"\n"
"\n"
harnessInfoChecksumZ(
"[db]\n"
"db-id=1\n"
"\n"
@ -148,12 +144,7 @@ testRun(void)
// Fix the version
storagePutNP(
storageNewWriteNP(storageTest, strNew("repo/archive/test/archive.info")),
BUFSTRDEF(
"[backrest]\n"
"backrest-checksum=\"4656aad82fa16a5d87b1aed36cb8a20c2707b9f9\"\n"
"backrest-format=5\n"
"backrest-version=\"2.08\"\n"
"\n"
harnessInfoChecksumZ(
"[db]\n"
"db-id=1\n"
"\n"
@ -168,12 +159,7 @@ testRun(void)
// Fix archive info
storagePutNP(
storageNewWriteNP(storageTest, strNew("repo/archive/test/archive.info")),
BUFSTRDEF(
"[backrest]\n"
"backrest-checksum=\"724b21c26c64f4c25567a11eb222c18766cbec00\"\n"
"backrest-format=5\n"
"backrest-version=\"2.11\"\n"
"\n"
harnessInfoChecksumZ(
"[db]\n"
"db-id=1\n"
"\n"
@ -227,12 +213,7 @@ testRun(void)
storagePutNP(
storageNewWriteNP(storageTest, strNew("repo/archive/test/archive.info")),
BUFSTRDEF(
"[backrest]\n"
"backrest-checksum=\"f5c9e17258db65e8d22609e23d1e99985d6bb063\"\n"
"backrest-format=5\n"
"backrest-version=\"2.12\"\n"
"\n"
harnessInfoChecksumZ(
"[db]\n"
"db-id=1\n"
"\n"
@ -401,12 +382,7 @@ testRun(void)
storagePutNP(
infoWrite,
BUFSTRDEF(
"[backrest]\n"
"backrest-checksum=\"4ce1b0e8f7132e3b5193a9c385f2d039dd75062f\"\n"
"backrest-format=5\n"
"backrest-version=\"2.12\"\n"
"\n"
harnessInfoChecksumZ(
"[cipher]\n"
"cipher-pass=\"badsubpassphrase\"\n"
"\n"
@ -482,12 +458,7 @@ testRun(void)
storagePutNP(
storageNewWriteNP(storageTest, strNew("repo/archive/test/archive.info")),
BUFSTRDEF(
"[backrest]\n"
"backrest-checksum=\"d12be58a906afa894c34f49ac9cbb6b968efc5a4\"\n"
"backrest-format=5\n"
"backrest-version=\"2.12\"\n"
"\n"
harnessInfoChecksumZ(
"[db]\n"
"db-id=1\n"
"\n"

View File

@ -4,6 +4,7 @@ Test Info Command
#include "storage/driver/posix/storage.h"
#include "common/harnessConfig.h"
#include "common/harnessInfo.h"
/***********************************************************************************************************************************
Test Run
@ -71,11 +72,6 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
String *content = strNew
(
"[backrest]\n"
"backrest-checksum=\"a52ab193e02b367ab338bff842e2faa31d8aa921\"\n"
"backrest-format=5\n"
"backrest-version=\"2.04\"\n"
"\n"
"[cipher]\n"
"cipher-pass=\"12345\"\n"
"\n"
@ -95,7 +91,7 @@ testRun(void)
TEST_RESULT_VOID(
storagePutNP(storageNewWriteNP(storageLocalWrite(), strNewFmt("%s/backup.info", strPtr(backupStanza1Path))),
BUFSTR(content)), "put backup info to file");
harnessInfoChecksum(content)), "put backup info to file");
TEST_ERROR_FMT(infoRender(), FileMissingError,
"unable to load info file '%s/archive.info' or '%s/archive.info.copy':\n"
@ -112,11 +108,6 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
content = strNew
(
"[backrest]\n"
"backrest-checksum=\"0da11608456bae64c42cc1dc8df4ae79b953d597\"\n"
"backrest-format=5\n"
"backrest-version=\"2.04\"\n"
"\n"
"[db]\n"
"db-id=1\n"
"db-system-id=6569239123849665679\n"
@ -130,7 +121,7 @@ testRun(void)
TEST_RESULT_VOID(
storagePutNP(storageNewWriteNP(storageLocalWrite(), strNewFmt("%s/archive.info", strPtr(archiveStanza1Path))),
BUFSTR(content)), "put archive info to file");
harnessInfoChecksum(content)), "put archive info to file");
// archive section will cross reference backup db-id 2 to archive db-id 3 but db section will only use the db-ids from
// backup.info
@ -226,11 +217,6 @@ testRun(void)
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
content = strNew
(
"[backrest]\n"
"backrest-checksum=\"c68d528a1b28f6ef1c370955ac8915eab737d402\"\n"
"backrest-format=5\n"
"backrest-version=\"2.04\"\n"
"\n"
"[db]\n"
"db-catalog-version=201409291\n"
"db-control-version=942\n"
@ -258,7 +244,7 @@ testRun(void)
TEST_RESULT_VOID(
storagePutNP(storageNewWriteNP(storageLocalWrite(), strNewFmt("%s/backup.info", strPtr(backupStanza1Path))),
BUFSTR(content)), "put backup info to file");
harnessInfoChecksum(content)), "put backup info to file");
TEST_RESULT_STR(strPtr(infoRender()),
"[\n"
@ -361,11 +347,6 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
content = strNew
(
"[backrest]\n"
"backrest-checksum=\"075a202d42c3b6a0257da5f73a68fa77b342f777\"\n"
"backrest-format=5\n"
"backrest-version=\"2.08dev\"\n"
"\n"
"[db]\n"
"db-id=2\n"
"db-system-id=6626363367545678089\n"
@ -378,15 +359,10 @@ testRun(void)
TEST_RESULT_VOID(
storagePutNP(storageNewWriteNP(storageLocalWrite(), strNewFmt("%s/archive.info", strPtr(archiveStanza1Path))),
BUFSTR(content)), "put archive info to file - stanza1");
harnessInfoChecksum(content)), "put archive info to file - stanza1");
content = strNew
(
"[backrest]\n"
"backrest-checksum=\"b50db7cf8f659ac15a0c7a2f45a0813f46a68c6b\"\n"
"backrest-format=5\n"
"backrest-version=\"2.08dev\"\n"
"\n"
"[backup:current]\n"
"20181119-152138F={"
"\"backrest-format\":5,\"backrest-version\":\"2.08dev\","
@ -430,7 +406,7 @@ testRun(void)
TEST_RESULT_VOID(
storagePutNP(storageNewWriteNP(storageLocalWrite(), strNewFmt("%s/backup.info", strPtr(backupStanza1Path))),
BUFSTR(content)), "put backup info to file - stanza1");
harnessInfoChecksum(content)), "put backup info to file - stanza1");
String *archiveStanza2Path = strNewFmt("%s/stanza2", strPtr(archivePath));
String *backupStanza2Path = strNewFmt("%s/stanza2", strPtr(backupPath));
@ -439,11 +415,6 @@ testRun(void)
content = strNew
(
"[backrest]\n"
"backrest-checksum=\"6779d476833114925a73e058ef9ff04e5a8c7bd2\"\n"
"backrest-format=5\n"
"backrest-version=\"2.08dev\"\n"
"\n"
"[db]\n"
"db-id=1\n"
"db-system-id=6625633699176220261\n"
@ -455,15 +426,10 @@ testRun(void)
TEST_RESULT_VOID(
storagePutNP(storageNewWriteNP(storageLocalWrite(), strNewFmt("%s/archive.info", strPtr(archiveStanza2Path))),
BUFSTR(content)), "put archive info to file - stanza2");
harnessInfoChecksum(content)), "put archive info to file - stanza2");
content = strNew
(
"[backrest]\n"
"backrest-checksum=\"2393c52cb48aff2d6c6e87e21a34a3e28200f42e\"\n"
"backrest-format=5\n"
"backrest-version=\"2.08dev\"\n"
"\n"
"[db]\n"
"db-catalog-version=201409291\n"
"db-control-version=942\n"
@ -478,7 +444,7 @@ testRun(void)
TEST_RESULT_VOID(
storagePutNP(storageNewWriteNP(storageLocalWrite(), strNewFmt("%s/backup.info", strPtr(backupStanza2Path))),
BUFSTR(content)), "put backup info to file - stanza2");
harnessInfoChecksum(content)), "put backup info to file - stanza2");
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
TEST_RESULT_STR(strPtr(infoRender()),

View File

@ -1,6 +1,7 @@
/***********************************************************************************************************************************
Test Archive Info Handler
***********************************************************************************************************************************/
#include "common/harnessInfo.h"
/***********************************************************************************************************************************
Test Run
@ -31,11 +32,6 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
content = strNew
(
"[backrest]\n"
"backrest-checksum=\"1efa53e0611604ad7d833c5547eb60ff716e758c\"\n"
"backrest-format=5\n"
"backrest-version=\"2.04\"\n"
"\n"
"[db]\n"
"db-id=1\n"
"db-system-id=6569239123849665679\n"
@ -46,7 +42,8 @@ testRun(void)
);
TEST_RESULT_VOID(
storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), BUFSTR(content)), "put archive info to file");
storagePutNP(
storageNewWriteNP(storageLocalWrite(), fileName), harnessInfoChecksum(content)), "put archive info to file");
TEST_ASSIGN(info, infoArchiveNew(storageLocal(), fileName, true, cipherTypeNone, NULL), " new archive info");
TEST_RESULT_STR(strPtr(infoArchiveId(info)), "9.4-1", " archiveId set");
@ -64,11 +61,6 @@ testRun(void)
{
content = strNew
(
"[backrest]\n"
"backrest-checksum=\"075a202d42c3b6a0257da5f73a68fa77b342f777\"\n"
"backrest-format=5\n"
"backrest-version=\"2.08dev\"\n"
"\n"
"[db]\n"
"db-id=2\n"
"db-system-id=6626363367545678089\n"
@ -80,7 +72,8 @@ testRun(void)
);
TEST_RESULT_VOID(
storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), BUFSTR(content)), "put archive info to file");
storagePutNP(
storageNewWriteNP(storageLocalWrite(), fileName), harnessInfoChecksum(content)), "put archive info to file");
TEST_ASSIGN(info, infoArchiveNew(storageLocal(), fileName, true, cipherTypeNone, NULL), "new archive info");
TEST_RESULT_STR(strPtr(infoArchiveIdHistoryMatch(info, 2, 90500, 6626363367545678089)), "9.5-2", " full match found");

View File

@ -1,6 +1,7 @@
/***********************************************************************************************************************************
Test Backup Info Handler
***********************************************************************************************************************************/
#include "common/harnessInfo.h"
/***********************************************************************************************************************************
Test Run
@ -32,11 +33,6 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
content = strNew
(
"[backrest]\n"
"backrest-checksum=\"5c17df9523543f5283efdc3c5aa7eb933c63ea0b\"\n"
"backrest-format=5\n"
"backrest-version=\"2.04\"\n"
"\n"
"[db]\n"
"db-catalog-version=201409291\n"
"db-control-version=942\n"
@ -50,7 +46,8 @@ testRun(void)
);
TEST_RESULT_VOID(
storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), BUFSTR(content)), "put backup info to file");
storagePutNP(
storageNewWriteNP(storageLocalWrite(), fileName), harnessInfoChecksum(content)), "put backup info to file");
TEST_ASSIGN(infoBackup, infoBackupNew(storageLocal(), fileName, false, cipherTypeNone, NULL), " new backup info");
TEST_RESULT_PTR(infoBackupPg(infoBackup), infoBackup->infoPg, " infoPg set");
@ -97,11 +94,6 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
content = strNew
(
"[backrest]\n"
"backrest-checksum=\"7f77f7a8efc72bd99b1a20022b6db50d4cbd72fa\"\n"
"backrest-format=5\n"
"backrest-version=\"2.04\"\n"
"\n"
"[db]\n"
"db-catalog-version=201409291\n"
"db-control-version=942\n"
@ -139,7 +131,8 @@ testRun(void)
);
TEST_RESULT_VOID(
storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), BUFSTR(content)), "put backup info current to file");
storagePutNP(
storageNewWriteNP(storageLocalWrite(), fileName), harnessInfoChecksum(content)), "put backup info current to file");
TEST_ASSIGN(infoBackup, infoBackupNew(storageLocal(), fileName, false, cipherTypeNone, NULL), " new backup info");
TEST_RESULT_INT(infoBackupDataTotal(infoBackup), 3, " backup list contains backups");

View File

@ -1,6 +1,7 @@
/***********************************************************************************************************************************
Test PostgreSQL Info Handler
***********************************************************************************************************************************/
#include "common/harnessInfo.h"
/***********************************************************************************************************************************
Test Run
@ -18,11 +19,6 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
content = strNew
(
"[backrest]\n"
"backrest-checksum=\"1efa53e0611604ad7d833c5547eb60ff716e758c\"\n"
"backrest-format=5\n"
"backrest-version=\"2.04\"\n"
"\n"
"[db]\n"
"db-id=1\n"
"db-system-id=6569239123849665679\n"
@ -32,7 +28,8 @@ testRun(void)
"1={\"db-id\":6569239123849665679,\"db-version\":\"9.4\"}\n"
);
TEST_RESULT_VOID(storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), BUFSTR(content)), "put info to file");
TEST_RESULT_VOID(
storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), harnessInfoChecksum(content)), "put info to file");
InfoPg *infoPg = NULL;
@ -55,11 +52,6 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
content = strNew
(
"[backrest]\n"
"backrest-checksum=\"5c17df9523543f5283efdc3c5aa7eb933c63ea0b\"\n"
"backrest-format=5\n"
"backrest-version=\"2.04\"\n"
"\n"
"[db]\n"
"db-catalog-version=201409291\n"
"db-control-version=942\n"
@ -72,7 +64,8 @@ testRun(void)
"\"db-version\":\"9.4\"}\n"
);
TEST_RESULT_VOID(storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), BUFSTR(content)), "put info to file");
TEST_RESULT_VOID(
storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), harnessInfoChecksum(content)), "put info to file");
TEST_ASSIGN(
infoPg, infoPgNew(storageLocal(), fileName, infoPgBackup, cipherTypeNone, NULL), "new infoPg backup - load file");
@ -90,11 +83,6 @@ testRun(void)
//--------------------------------------------------------------------------------------------------------------------------
content = strNew
(
"[backrest]\n"
"backrest-checksum=\"62e4d16add4b111bed37c9e9ab0b6f60897e27da\"\n"
"backrest-format=5\n"
"backrest-version=\"2.04\"\n"
"\n"
"[db]\n"
"db-catalog-version=201510051\n"
"db-control-version=942\n"
@ -109,7 +97,8 @@ testRun(void)
"\"db-version\":\"9.5\"}\n"
);
TEST_RESULT_VOID(storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), BUFSTR(content)), "put info to file");
TEST_RESULT_VOID(
storagePutNP(storageNewWriteNP(storageLocalWrite(), fileName), harnessInfoChecksum(content)), "put info to file");
TEST_ASSIGN(
infoPg, infoPgNew(storageLocal(), fileName, infoPgManifest, cipherTypeNone, NULL), "new infoPg manifest - load file");