From 03021c6a17f1374e84ef42614fa1dd2a6be4b64d Mon Sep 17 00:00:00 2001 From: Cynthia Shang Date: Mon, 14 Jun 2021 13:28:27 -0400 Subject: [PATCH] Update command/stanza test to use standard patterns. No core code changes; only changes for stanza-create, stanza-upgrade, and stanza-delete command unit tests. --- doc/xml/release.xml | 9 +- test/src/module/command/stanzaTest.c | 1048 ++++++++++++-------------- 2 files changed, 492 insertions(+), 565 deletions(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index cf05ad4a97..57235f3416 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -31,14 +31,19 @@ - + + + + + + -

Update command/expire test to use standard patterns.

+

Update command tests to use standard patterns.

diff --git a/test/src/module/command/stanzaTest.c b/test/src/module/command/stanzaTest.c index cc1b042e93..3750c7ffeb 100644 --- a/test/src/module/command/stanzaTest.c +++ b/test/src/module/command/stanzaTest.c @@ -18,24 +18,24 @@ testRun(void) { FUNCTION_HARNESS_VOID(); + // Create storage objects for the testing location and for the harness directory for items such as logs, stop files, etc Storage *storageTest = storagePosixNewP(TEST_PATH_STR, .write = true); + Storage *storageHrn = storagePosixNewP(HRN_PATH_STR, .write = true); - const String *stanza = STRDEF("db"); - const String *fileName = STRDEF("test.info"); - String *backupStanzaPath = strNewFmt("repo/backup/%s", strZ(stanza)); - String *backupInfoFileName = strNewFmt("%s/backup.info", strZ(backupStanzaPath)); - String *archiveStanzaPath = strNewFmt("repo/archive/%s", strZ(stanza)); - String *archiveInfoFileName = strNewFmt("%s/archive.info", strZ(archiveStanzaPath)); + #define TEST_STANZA "db" + #define TEST_STANZA_OTHER "otherstanza" StringList *argListBase = strLstNew(); - strLstAddZ(argListBase, "--no-online"); - strLstAdd(argListBase, strNewFmt("--stanza=%s", strZ(stanza))); - strLstAdd(argListBase, strNewFmt("--pg1-path=" TEST_PATH "/%s", strZ(stanza))); - strLstAddZ(argListBase, "--repo1-path=" TEST_PATH "/repo"); + hrnCfgArgRawBool(argListBase, cfgOptOnline, false); + hrnCfgArgRawZ(argListBase, cfgOptStanza, TEST_STANZA); + hrnCfgArgRawZ(argListBase, cfgOptPgPath, TEST_PATH_PG); + hrnCfgArgRawZ(argListBase, cfgOptRepoPath, TEST_PATH_REPO); // ***************************************************************************************************************************** if (testBegin("cmdStanzaCreate(), checkStanzaInfo(), cmdStanzaDelete()")) { + TEST_TITLE("stanza-create: repo option not valid"); + // Load Parameters StringList *argList = strLstDup(argListBase); hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 2, TEST_PATH "/repo2"); @@ -45,55 +45,51 @@ testRun(void) hrnCfgLoadP(cfgCmdStanzaCreate, argList), OptionInvalidError, "option 'repo' not valid for command 'stanza-create'"); //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("stanza-create: stop file error"); + HRN_CFG_LOAD(cfgCmdStanzaCreate, argListBase); - // Create the stop file - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageLocalWrite(), lockStopFileName(cfgOptionStr(cfgOptStanza))), BUFSTRDEF("")), - "create stop file"); - TEST_ERROR_FMT(cmdStanzaCreate(), StopError, "stop file exists for stanza %s", strZ(stanza)); - TEST_RESULT_VOID( - storageRemoveP(storageLocalWrite(), lockStopFileName(cfgOptionStr(cfgOptStanza))), " remove the stop file"); + // Create the stop file, test, then remove the stop file + HRN_STORAGE_PUT_EMPTY(storageHrn, strZ(lockStopFileName(cfgOptionStr(cfgOptStanza)))); + TEST_ERROR(cmdStanzaCreate(), StopError, "stop file exists for stanza " TEST_STANZA); + HRN_STORAGE_REMOVE(storageHrn, strZ(lockStopFileName(cfgOptionStr(cfgOptStanza)))); //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("stanza-create: validate info files created"); + argList = strLstDup(argListBase); HRN_CFG_LOAD(cfgCmdStanzaCreate, argList); // Create pg_control - storagePutP( - storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(stanza))), + HRN_STORAGE_PUT( + storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, hrnPgControlToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 6569239123849665679})); TEST_RESULT_VOID(cmdStanzaCreate(), "stanza create - one repo, no files exist"); - TEST_RESULT_LOG("P00 INFO: stanza-create for stanza 'db' on repo1"); + TEST_RESULT_LOG("P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1"); - const String *contentArchive = STRDEF - ( + HRN_INFO_PUT( + storageHrn, "test.info", "[db]\n" "db-id=1\n" "db-system-id=6569239123849665679\n" "db-version=\"9.6\"\n" "\n" "[db:history]\n" - "1={\"db-id\":6569239123849665679,\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, fileName), harnessInfoChecksum(contentArchive)), - "put archive info to test file"); + "1={\"db-id\":6569239123849665679,\"db-version\":\"9.6\"}\n", + .comment = "put archive info to test file"); TEST_RESULT_BOOL( (bufEq( - storageGetP(storageNewReadP(storageTest, archiveInfoFileName)), - storageGetP(storageNewReadP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(archiveInfoFileName))))) && + storageGetP(storageNewReadP(storageRepoIdx(0), INFO_ARCHIVE_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageRepoIdx(0), STRDEF(INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT)))) && bufEq( - storageGetP(storageNewReadP(storageTest, archiveInfoFileName)), - storageGetP(storageNewReadP(storageTest, fileName)))), - true, " test and stanza archive info files are equal"); + storageGetP(storageNewReadP(storageRepoIdx(0), INFO_ARCHIVE_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageHrn, STRDEF("test.info"))))), + true, "test and stanza archive info files are equal"); - const String *contentBackup = STRDEF - ( + HRN_INFO_PUT( + storageHrn, "test.info", "[db]\n" "db-catalog-version=201608131\n" "db-control-version=960\n" @@ -103,21 +99,17 @@ testRun(void) "\n" "[db:history]\n" "1={\"db-catalog-version\":201608131,\"db-control-version\":960,\"db-system-id\":6569239123849665679," - "\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, fileName), harnessInfoChecksum(contentBackup)), - "put backup info to test file"); + "\"db-version\":\"9.6\"}\n", + .comment = "put backup info to test file"); TEST_RESULT_BOOL( (bufEq( - storageGetP(storageNewReadP(storageTest, backupInfoFileName)), - storageGetP(storageNewReadP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(backupInfoFileName))))) && + storageGetP(storageNewReadP(storageRepoIdx(0), INFO_BACKUP_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageRepoIdx(0), STRDEF(INFO_BACKUP_PATH_FILE INFO_COPY_EXT)))) && bufEq( - storageGetP(storageNewReadP(storageTest, backupInfoFileName)), - storageGetP(storageNewReadP(storageTest, fileName)))), - true, " test and stanza backup info files are equal"); + storageGetP(storageNewReadP(storageRepoIdx(0), INFO_BACKUP_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageHrn, STRDEF("test.info"))))), + true, "test and stanza backup info files are equal"); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("cmdStanzaCreate success - multi-repo and encryption"); @@ -134,120 +126,111 @@ testRun(void) TEST_RESULT_VOID(cmdStanzaCreate(), "stanza create - files already exist on repo1 and both are valid"); TEST_RESULT_LOG( - "P00 INFO: stanza-create for stanza 'db' on repo1\n" - "P00 INFO: stanza 'db' already exists on repo1 and is valid\n" - "P00 INFO: stanza-create for stanza 'db' on repo2\n" - "P00 INFO: stanza-create for stanza 'db' on repo3\n" - "P00 INFO: stanza-create for stanza 'db' on repo4"); - - String *archiveInfoFileNameRepo2 = strNewFmt("repo2/archive/%s/archive.info", strZ(stanza)); - String *backupInfoFileNameRepo2 = strNewFmt("repo2/backup/%s/backup.info", strZ(stanza)); - String *archiveInfoFileNameRepo3 = strNewFmt("repo3/archive/%s/archive.info", strZ(stanza)); - String *backupInfoFileNameRepo3 = strNewFmt("repo3/backup/%s/backup.info", strZ(stanza)); - String *archiveInfoFileNameRepo4 = strNewFmt("repo4/archive/%s/archive.info", strZ(stanza)); - String *backupInfoFileNameRepo4 = strNewFmt("repo4/backup/%s/backup.info", strZ(stanza)); + "P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1\n" + "P00 INFO: stanza '" TEST_STANZA "' already exists on repo1 and is valid\n" + "P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo2\n" + "P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo3\n" + "P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo4"); InfoArchive *infoArchive = NULL; TEST_ASSIGN( - infoArchive, infoArchiveLoadFile(storageTest, archiveInfoFileNameRepo2, cipherTypeAes256Cbc, STRDEF("12345678")), - " load archive info"); - TEST_RESULT_PTR_NE(infoArchiveCipherPass(infoArchive), NULL, " cipher sub set"); + infoArchive, infoArchiveLoadFile(storageRepoIdx(1), INFO_ARCHIVE_PATH_FILE_STR, cipherTypeAes256Cbc, + STRDEF("12345678")), "load archive info from encrypted repo2"); + TEST_RESULT_PTR_NE(infoArchiveCipherPass(infoArchive), NULL, "cipher sub set"); InfoBackup *infoBackup = NULL; TEST_ASSIGN( - infoBackup, infoBackupLoadFile(storageTest, backupInfoFileNameRepo2, cipherTypeAes256Cbc, STRDEF("12345678")), - " load backup info"); - TEST_RESULT_PTR_NE(infoBackupCipherPass(infoBackup), NULL, " cipher sub set"); + infoBackup, infoBackupLoadFile(storageRepoIdx(1), INFO_BACKUP_PATH_FILE_STR, cipherTypeAes256Cbc, STRDEF("12345678")), + "load backup info from encrypted repo2"); + TEST_RESULT_PTR_NE(infoBackupCipherPass(infoBackup), NULL, "cipher sub set"); TEST_RESULT_BOOL( strEq(infoArchiveCipherPass(infoArchive), infoBackupCipherPass(infoBackup)), false, - " cipher sub different for archive and backup"); + "cipher sub different for archive and backup"); // Confirm non-encrypted repo created successfully TEST_ASSIGN( - infoArchive, infoArchiveLoadFile(storageTest, archiveInfoFileNameRepo3, cipherTypeNone, NULL), " load archive info"); - TEST_RESULT_PTR(infoArchiveCipherPass(infoArchive), NULL, " archive cipher sub not set on non-encrypted repo"); + infoArchive, infoArchiveLoadFile(storageRepoIdx(2), INFO_ARCHIVE_PATH_FILE_STR, cipherTypeNone, NULL), + "load archive info from repo3"); + TEST_RESULT_PTR(infoArchiveCipherPass(infoArchive), NULL, "archive cipher sub not set on non-encrypted repo"); TEST_ASSIGN( - infoBackup, infoBackupLoadFile(storageTest, backupInfoFileNameRepo3, cipherTypeNone, NULL)," load backup info"); - TEST_RESULT_PTR(infoBackupCipherPass(infoBackup), NULL, " backup cipher sub not set on non-encrypted repo"); + infoBackup, infoBackupLoadFile(storageRepoIdx(2), INFO_BACKUP_PATH_FILE_STR, cipherTypeNone, NULL), + "load backup info from repo3"); + TEST_RESULT_PTR(infoBackupCipherPass(infoBackup), NULL, "backup cipher sub not set on non-encrypted repo"); // Confirm other repo encrypted with different password TEST_ASSIGN( - infoArchive, infoArchiveLoadFile(storageTest, archiveInfoFileNameRepo4, cipherTypeAes256Cbc, STRDEF("87654321")), - " load archive info"); - TEST_RESULT_PTR_NE(infoArchiveCipherPass(infoArchive), NULL, " cipher sub set"); + infoArchive, infoArchiveLoadFile(storageRepoIdx(3), INFO_ARCHIVE_PATH_FILE_STR, cipherTypeAes256Cbc, + STRDEF("87654321")), "load archive info from encrypted repo4"); + TEST_RESULT_PTR_NE(infoArchiveCipherPass(infoArchive), NULL, "cipher sub set"); TEST_ASSIGN( - infoBackup, infoBackupLoadFile(storageTest, backupInfoFileNameRepo4, cipherTypeAes256Cbc, STRDEF("87654321")), - " load backup info"); - TEST_RESULT_PTR_NE(infoBackupCipherPass(infoBackup), NULL, " cipher sub set"); + infoBackup, infoBackupLoadFile(storageRepoIdx(3), INFO_BACKUP_PATH_FILE_STR, cipherTypeAes256Cbc, STRDEF("87654321")), + "load backup info from encrypted repo4"); + TEST_RESULT_PTR_NE(infoBackupCipherPass(infoBackup), NULL, "cipher sub set"); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("cmdStanzaCreate missing files - multi-repo and encryption"); // Remove backup.info on repo1 - TEST_RESULT_VOID(storageRemoveP(storageTest, backupInfoFileName, .errorOnMissing = true), "backup.info removed"); + TEST_STORAGE_EXISTS(storageRepoIdxWrite(0), INFO_BACKUP_PATH_FILE, .remove = true); // Remove archive.info on repo2 - TEST_RESULT_VOID(storageRemoveP(storageTest, archiveInfoFileNameRepo2, .errorOnMissing = true), "archive.info removed"); + TEST_STORAGE_EXISTS(storageRepoIdxWrite(1), INFO_ARCHIVE_PATH_FILE, .remove = true); // Remove info files on repo3 - TEST_RESULT_VOID(storageRemoveP(storageTest, archiveInfoFileNameRepo3, .errorOnMissing = true), "archive.info removed"); - TEST_RESULT_VOID(storageRemoveP(storageTest, backupInfoFileNameRepo3, .errorOnMissing = true), "backup.info removed"); + TEST_STORAGE_EXISTS(storageRepoIdxWrite(2), INFO_ARCHIVE_PATH_FILE, .remove = true); + TEST_STORAGE_EXISTS(storageRepoIdxWrite(2), INFO_BACKUP_PATH_FILE, .remove = true); // Remove copy files repo4 - TEST_RESULT_VOID( - storageRemoveP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(archiveInfoFileNameRepo4)), .errorOnMissing = true), - "archive.info.copy removed"); - TEST_RESULT_VOID( - storageRemoveP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(backupInfoFileNameRepo4)), .errorOnMissing = true), - "backup.info.copy removed"); + TEST_STORAGE_EXISTS(storageRepoIdxWrite(3), INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT, .remove = true); + TEST_STORAGE_EXISTS(storageRepoIdxWrite(3), INFO_BACKUP_PATH_FILE INFO_COPY_EXT, .remove = true); TEST_RESULT_VOID(cmdStanzaCreate(), "stanza create - success with missing files"); TEST_RESULT_LOG( - "P00 INFO: stanza-create for stanza 'db' on repo1\n" - "P00 INFO: stanza-create for stanza 'db' on repo2\n" - "P00 INFO: stanza-create for stanza 'db' on repo3\n" - "P00 INFO: stanza-create for stanza 'db' on repo4"); + "P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1\n" + "P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo2\n" + "P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo3\n" + "P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo4"); TEST_RESULT_BOOL( bufEq( - storageGetP(storageNewReadP(storageTest, backupInfoFileName)), - storageGetP(storageNewReadP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(backupInfoFileName))))), + storageGetP(storageNewReadP(storageRepoIdx(0), INFO_BACKUP_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageRepoIdx(0), STRDEF(INFO_BACKUP_PATH_FILE INFO_COPY_EXT)))), true, "backup.info recreated repo1 from backup.info.copy"); TEST_RESULT_BOOL( bufEq( - storageGetP(storageNewReadP(storageTest, archiveInfoFileNameRepo2)), - storageGetP(storageNewReadP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(archiveInfoFileNameRepo2))))), + storageGetP(storageNewReadP(storageRepoIdx(1), INFO_ARCHIVE_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageRepoIdx(1), STRDEF(INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT)))), true, "archive.info repo2 recreated from archive.info.copy"); TEST_RESULT_BOOL( (bufEq( - storageGetP(storageNewReadP(storageTest, backupInfoFileNameRepo3)), - storageGetP(storageNewReadP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(backupInfoFileNameRepo3))))) && + storageGetP(storageNewReadP(storageRepoIdx(2), INFO_BACKUP_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageRepoIdx(2), STRDEF(INFO_BACKUP_PATH_FILE INFO_COPY_EXT)))) && bufEq( - storageGetP(storageNewReadP(storageTest, archiveInfoFileNameRepo3)), - storageGetP(storageNewReadP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(archiveInfoFileNameRepo3)))))), - true, "info files recreated repo3 from copy files"); + storageGetP(storageNewReadP(storageRepoIdx(2), INFO_ARCHIVE_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageRepoIdx(2), STRDEF(INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT))))), + true, "info files recreated repo3 from copy files"); TEST_RESULT_BOOL( (bufEq( - storageGetP(storageNewReadP(storageTest, backupInfoFileNameRepo4)), - storageGetP(storageNewReadP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(backupInfoFileNameRepo4))))) && + storageGetP(storageNewReadP(storageRepoIdx(3), INFO_BACKUP_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageRepoIdx(3), STRDEF(INFO_BACKUP_PATH_FILE INFO_COPY_EXT)))) && bufEq( - storageGetP(storageNewReadP(storageTest, archiveInfoFileNameRepo4)), - storageGetP(storageNewReadP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(archiveInfoFileNameRepo4)))))), - true, "info files recreated repo4 from info files"); + storageGetP(storageNewReadP(storageRepoIdx(3), INFO_ARCHIVE_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageRepoIdx(3), STRDEF(INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT))))), + true, "copy files recreated repo4 from info files"); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("cmdStanzaDelete - multi-repo and encryption, delete"); StringList *argListCmd = strLstNew(); - hrnCfgArgKeyRawZ(argListCmd, cfgOptRepoPath, 1, TEST_PATH "/repo"); + hrnCfgArgKeyRawZ(argListCmd, cfgOptRepoPath, 1, TEST_PATH_REPO); hrnCfgArgKeyRawZ(argListCmd, cfgOptRepoPath, 2, TEST_PATH "/repo2"); hrnCfgArgKeyRawZ(argListCmd, cfgOptRepoPath, 3, TEST_PATH "/repo3"); hrnCfgArgKeyRawZ(argListCmd, cfgOptRepoPath, 4, TEST_PATH "/repo4"); - hrnCfgArgRawFmt(argListCmd, cfgOptStanza, "%s", strZ(stanza)); - hrnCfgArgKeyRawFmt(argListCmd, cfgOptPgPath, 1, TEST_PATH "/%s", strZ(stanza)); + hrnCfgArgRawZ(argListCmd, cfgOptStanza, TEST_STANZA); + hrnCfgArgRawZ(argListCmd, cfgOptPgPath, TEST_PATH_PG); TEST_ERROR( hrnCfgLoadP(cfgCmdStanzaDelete, argListCmd), OptionRequiredError, @@ -261,20 +244,30 @@ testRun(void) TEST_ERROR( cmdStanzaDelete(), FileMissingError, - "stop file does not exist for stanza 'db'\n" + "stop file does not exist for stanza '" TEST_STANZA "'\n" "HINT: has the pgbackrest stop command been run on this server for this stanza?"); // Create the stop file - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageLocalWrite(), lockStopFileName(cfgOptionStr(cfgOptStanza))), BUFSTRDEF("")), - "create stop file"); + HRN_STORAGE_PUT_EMPTY(storageHrn, strZ(lockStopFileName(cfgOptionStr(cfgOptStanza)))); + + TEST_STORAGE_LIST( + storageTest, "repo4", + "archive/\n" + "archive/" TEST_STANZA "/\n" + "archive/" TEST_STANZA "/archive.info\n" + "archive/" TEST_STANZA "/archive.info.copy\n" + "backup/\n" + "backup/" TEST_STANZA "/\n" + "backup/" TEST_STANZA "/backup.info\n" + "backup/" TEST_STANZA "/backup.info.copy\n", + .comment = "stanza exists in repo4"); TEST_RESULT_VOID(cmdStanzaDelete(), "stanza delete - repo4"); + + TEST_STORAGE_LIST(storageTest, "repo4", "archive/\nbackup/\n", .comment = "stanza deleted"); + TEST_RESULT_BOOL( - storagePathExistsP(storageTest, strNewFmt("repo4/archive/%s", strZ(stanza))), false, " stanza deleted"); - TEST_RESULT_BOOL( - storageExistsP(storageLocal(), lockStopFileName(cfgOptionStr(cfgOptStanza))), false, " stop file removed"); + storageExistsP(storageHrn, lockStopFileName(cfgOptionStr(cfgOptStanza))), false, "confirm stop file removed"); // Remove the cipher pass environment variable otherwise stanza-create will recreate the stanza hrnCfgEnvKeyRemoveRaw(cfgOptRepoCipherPass, 4); @@ -284,21 +277,15 @@ testRun(void) hrnCfgArgRawZ(argListDelete, cfgOptRepo, "3"); HRN_CFG_LOAD(cfgCmdStanzaDelete, argListDelete); - TEST_RESULT_VOID( - storagePathCreateP(storageTest, strNewFmt("repo3/archive/%s/9.6-1/1234567812345678", strZ(stanza))), - "create archive sub directory"); - TEST_RESULT_VOID( - storagePathCreateP(storageTest, strNewFmt("repo3/backup/%s/20190708-154306F", strZ(stanza))), - "create backup sub directory"); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageLocalWrite(), lockStopFileName(cfgOptionStr(cfgOptStanza))), BUFSTRDEF("")), - "create stop file"); - TEST_RESULT_VOID(cmdStanzaDelete(), " stanza delete - repo3 - sub directories only"); - TEST_RESULT_BOOL( - storagePathExistsP(storageTest, strNewFmt("repo3/archive/%s", strZ(stanza))), false, " stanza archive deleted"); - TEST_RESULT_BOOL( - storagePathExistsP(storageTest, strNewFmt("repo3/backup/%s", strZ(stanza))), false, " stanza backup deleted"); + HRN_STORAGE_PATH_CREATE( + storageRepoIdxWrite(2), STORAGE_REPO_ARCHIVE "/9.6-1/1234567812345678", .comment = "create archive sub directory"); + HRN_STORAGE_PATH_CREATE( + storageRepoIdxWrite(2), STORAGE_REPO_BACKUP "/20190708-154306F", .comment = "create backup sub directory"); + HRN_STORAGE_PUT_EMPTY(storageHrn, strZ(lockStopFileName(cfgOptionStr(cfgOptStanza))), .comment = "create stop file"); + + TEST_RESULT_VOID(cmdStanzaDelete(), "stanza delete - repo3 - sub directories only"); + + TEST_STORAGE_LIST(storageTest, "repo3", "archive/\nbackup/\n", .comment = "stanza deleted"); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("cmdStanzaCreate errors"); @@ -310,44 +297,42 @@ testRun(void) HRN_CFG_LOAD(cfgCmdStanzaCreate, argList); // Backup files removed - archive.info and archive.info.copy exist repo2 - TEST_RESULT_VOID( - storageRemoveP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(backupInfoFileNameRepo2)), .errorOnMissing = true), - "backup.info.copy removed repo2"); - TEST_RESULT_VOID(storageRemoveP(storageTest, backupInfoFileNameRepo2, .errorOnMissing = true), - "backup.info removed repo2"); + TEST_STORAGE_EXISTS( + storageRepoIdxWrite(1), INFO_BACKUP_PATH_FILE INFO_COPY_EXT, .remove = true, + .comment = "repo2: remove backup.info.copy"); + TEST_STORAGE_EXISTS( + storageRepoIdxWrite(1), INFO_BACKUP_PATH_FILE, .remove = true, .comment = "repo2: remove backup.info"); + TEST_ERROR( cmdStanzaCreate(), FileMissingError, "archive.info exists but backup.info is missing on repo2\n" "HINT: this may be a symptom of repository corruption!"); TEST_RESULT_LOG( - "P00 INFO: stanza-create for stanza 'db' on repo1\n" - "P00 INFO: stanza 'db' already exists on repo1 and is valid\n" - "P00 INFO: stanza-create for stanza 'db' on repo2"); + "P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1\n" + "P00 INFO: stanza '" TEST_STANZA "' already exists on repo1 and is valid\n" + "P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo2"); // Archive files removed - backup.info and backup.info.copy exist repo1 - TEST_RESULT_VOID( - storageRemoveP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(archiveInfoFileName)), .errorOnMissing = true), - "archive.info.copy removed repo1"); - TEST_RESULT_VOID(storageRemoveP(storageTest, archiveInfoFileName, .errorOnMissing = true), - "archive.info removed repo1"); + TEST_STORAGE_EXISTS( + storageRepoIdxWrite(0), INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT, .remove = true, + .comment = "repo1: remove archive.info.copy"); + TEST_STORAGE_EXISTS( + storageRepoIdxWrite(0), INFO_ARCHIVE_PATH_FILE, .remove = true, .comment = "repo1: remove archive.info"); + TEST_ERROR( cmdStanzaCreate(), FileMissingError, "backup.info exists but archive.info is missing on repo1\n" "HINT: this may be a symptom of repository corruption!"); - TEST_RESULT_LOG("P00 INFO: stanza-create for stanza 'db' on repo1"); + TEST_RESULT_LOG("P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1"); // Delete the last repo so only 1 remains argListDelete = strLstDup(argListCmd); hrnCfgArgRawZ(argListDelete, cfgOptRepo, "2"); HRN_CFG_LOAD(cfgCmdStanzaDelete, argListDelete); - // Create the stop file - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageLocalWrite(), lockStopFileName(cfgOptionStr(cfgOptStanza))), BUFSTRDEF("")), - "create stop file"); + HRN_STORAGE_PUT_EMPTY(storageHrn, strZ(lockStopFileName(cfgOptionStr(cfgOptStanza))), .comment = "create stop file"); - TEST_RESULT_VOID(cmdStanzaDelete(), " stanza delete - only 1 remains"); + TEST_RESULT_VOID(cmdStanzaDelete(), "stanza delete - only 1 remains"); // Remove the cipher pass environment variable otherwise stanza-create will recreate the stanza hrnCfgEnvKeyRemoveRaw(cfgOptRepoCipherPass, 2); @@ -356,58 +341,57 @@ testRun(void) HRN_CFG_LOAD(cfgCmdStanzaCreate, argList); // Archive files removed - backup.info exists - TEST_RESULT_VOID( - storageRemoveP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(backupInfoFileName)), .errorOnMissing = true), - "backup.info.copy removed"); + TEST_STORAGE_EXISTS( + storageRepoIdxWrite(0), INFO_BACKUP_PATH_FILE INFO_COPY_EXT, .remove = true, + .comment = "repo1: remove backup.info.copy"); TEST_ERROR( cmdStanzaCreate(), FileMissingError, "backup.info exists but archive.info is missing on repo1\n" "HINT: this may be a symptom of repository corruption!"); - TEST_RESULT_LOG("P00 INFO: stanza-create for stanza 'db' on repo1"); - - // Archive files removed - backup.info.copy exists - TEST_RESULT_VOID( - storageMoveP(storageTest, - storageNewReadP(storageTest, backupInfoFileName), - storageNewWriteP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(backupInfoFileName)))), - "backup.info moved to backup.info.copy"); + TEST_RESULT_LOG("P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1"); + + // Archive files removed - backup.info.copy exists, backup.info moved to backup.info.copy + HRN_STORAGE_MOVE(storageRepoIdxWrite(0), INFO_BACKUP_PATH_FILE, INFO_BACKUP_PATH_FILE INFO_COPY_EXT); TEST_ERROR( cmdStanzaCreate(), FileMissingError, "backup.info exists but archive.info is missing on repo1\n" "HINT: this may be a symptom of repository corruption!"); - TEST_RESULT_LOG("P00 INFO: stanza-create for stanza 'db' on repo1"); + TEST_RESULT_LOG("P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1"); // Backup files removed - archive.info file exists - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, archiveInfoFileName), harnessInfoChecksum(contentArchive)), - "put archive info to file"); - TEST_RESULT_VOID( - storageRemoveP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(backupInfoFileName)), .errorOnMissing = true), - "backup.info.copy removed"); + HRN_INFO_PUT( + storageRepoIdxWrite(0), INFO_ARCHIVE_PATH_FILE, + "[db]\n" + "db-id=1\n" + "db-system-id=6569239123849665679\n" + "db-version=\"9.6\"\n" + "\n" + "[db:history]\n" + "1={\"db-id\":6569239123849665679,\"db-version\":\"9.6\"}\n", + .comment = "put archive info to file repo1"); + TEST_STORAGE_EXISTS( + storageRepoIdxWrite(0), INFO_BACKUP_PATH_FILE INFO_COPY_EXT, .remove = true, + .comment = "repo1: remove backup.info.copy"); TEST_ERROR( cmdStanzaCreate(), FileMissingError, "archive.info exists but backup.info is missing on repo1\n" "HINT: this may be a symptom of repository corruption!"); - TEST_RESULT_LOG("P00 INFO: stanza-create for stanza 'db' on repo1"); - - // Backup files removed - archive.info.copy file exists - TEST_RESULT_VOID( - storageMoveP(storageTest, - storageNewReadP(storageTest, archiveInfoFileName), - storageNewWriteP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(archiveInfoFileName)))), - "archive.info moved to archive.info.copy"); + TEST_RESULT_LOG("P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1"); + + // Backup files removed - archive.info.copy file exists (renamed from archive.info) + HRN_STORAGE_MOVE(storageRepoIdxWrite(0), INFO_ARCHIVE_PATH_FILE, INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT); TEST_ERROR( cmdStanzaCreate(), FileMissingError, "archive.info exists but backup.info is missing on repo1\n" "HINT: this may be a symptom of repository corruption!"); - TEST_RESULT_LOG("P00 INFO: stanza-create for stanza 'db' on repo1"); + TEST_RESULT_LOG("P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1"); - // checkStanzaInfo() - already checked in checkTest so just a sanity check here //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("checkStanzaInfo() - already checked in checkTest so just a sanity check here"); + // Create a corrupted backup file - db id - contentBackup = STRDEF - ( + HRN_INFO_PUT( + storageRepoIdxWrite(0), INFO_BACKUP_PATH_FILE, "[db]\n" "db-catalog-version=201608131\n" "db-control-version=960\n" @@ -417,12 +401,8 @@ testRun(void) "\n" "[db:history]\n" "2={\"db-catalog-version\":201608131,\"db-control-version\":960,\"db-system-id\":6569239123849665679," - "\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, backupInfoFileName), harnessInfoChecksum(contentBackup)), - "put backup info to file - bad db-id"); + "\"db-version\":\"9.6\"}\n", + .comment = "put backup info to file - bad db-id"); TEST_ERROR( cmdStanzaCreate(), FileInvalidError, @@ -430,16 +410,19 @@ testRun(void) "archive: id = 1, version = 9.6, system-id = 6569239123849665679\n" "backup : id = 2, version = 9.6, system-id = 6569239123849665679\n" "HINT: this may be a symptom of repository corruption!"); - TEST_RESULT_LOG("P00 INFO: stanza-create for stanza 'db' on repo1"); + TEST_RESULT_LOG("P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1"); //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("archive.info file and backup.info files that match but do not match the current database version"); + // Copy files may or may not exist - remove - storageRemoveP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(archiveInfoFileName))); - storageRemoveP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(backupInfoFileName))); + HRN_STORAGE_REMOVE( + storageRepoIdxWrite(0), INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT, .comment = "repo1: remove archive.info.copy"); + HRN_STORAGE_REMOVE( + storageRepoIdxWrite(0), INFO_BACKUP_PATH_FILE INFO_COPY_EXT, .comment = "repo1: remove backup.info.copy"); - // Create an archive.info file and backup.info files that match but do not match the current database version - contentBackup = STRDEF - ( + HRN_INFO_PUT( + storageRepoIdxWrite(0), INFO_BACKUP_PATH_FILE, "[db]\n" "db-catalog-version=201510051\n" "db-control-version=942\n" @@ -449,53 +432,40 @@ testRun(void) "\n" "[db:history]\n" "1={\"db-catalog-version\":201510051,\"db-control-version\":942,\"db-system-id\":6569239123849665679," - "\"db-version\":\"9.5\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, backupInfoFileName), harnessInfoChecksum(contentBackup)), - "put backup info to file"); - - contentArchive = STRDEF - ( + "\"db-version\":\"9.5\"}\n"); + + HRN_INFO_PUT( + storageRepoIdxWrite(0), INFO_ARCHIVE_PATH_FILE, "[db]\n" "db-id=1\n" "db-system-id=6569239123849665679\n" "db-version=\"9.5\"\n" "\n" "[db:history]\n" - "1={\"db-id\":6569239123849665679,\"db-version\":\"9.5\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, archiveInfoFileName), harnessInfoChecksum(contentArchive)), - "put archive info file"); + "1={\"db-id\":6569239123849665679,\"db-version\":\"9.5\"}\n"); TEST_ERROR( cmdStanzaCreate(), FileInvalidError, "backup and archive info files exist but do not match the database\n" "HINT: is this the correct stanza?\n" "HINT: did an error occur during stanza-upgrade?"); - TEST_RESULT_LOG("P00 INFO: stanza-create for stanza 'db' on repo1"); + TEST_RESULT_LOG("P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1"); - // Create archive.info and backup.info files that match but do not match the current database system-id - contentArchive = STRDEF - ( + //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("archive.info and backup.info files that match but do not match the current database system-id"); + + HRN_INFO_PUT( + storageRepoIdxWrite(0), INFO_ARCHIVE_PATH_FILE, "[db]\n" "db-id=1\n" "db-system-id=6569239123849665999\n" "db-version=\"9.6\"\n" "\n" "[db:history]\n" - "1={\"db-id\":6569239123849665999,\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, archiveInfoFileName), harnessInfoChecksum(contentArchive)), - "put archive info to file"); - - contentBackup = STRDEF - ( + "1={\"db-id\":6569239123849665999,\"db-version\":\"9.6\"}\n"); + + HRN_INFO_PUT( + storageRepoIdxWrite(0), INFO_BACKUP_PATH_FILE, "[db]\n" "db-catalog-version=201608131\n" "db-control-version=960\n" @@ -505,122 +475,121 @@ testRun(void) "\n" "[db:history]\n" "1={\"db-catalog-version\":201608131,\"db-control-version\":960,\"db-system-id\":6569239123849665999," - "\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, backupInfoFileName), harnessInfoChecksum(contentBackup)), - "put backup info to file"); + "\"db-version\":\"9.6\"}\n"); TEST_ERROR( cmdStanzaCreate(), FileInvalidError, "backup and archive info files exist but do not match the database\n" "HINT: is this the correct stanza?\n" "HINT: did an error occur during stanza-upgrade?"); - TEST_RESULT_LOG("P00 INFO: stanza-create for stanza 'db' on repo1"); + TEST_RESULT_LOG("P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1"); // Remove the info files and add sub directory to backup - TEST_RESULT_VOID(storageRemoveP(storageTest, archiveInfoFileName, .errorOnMissing = true), "archive.info removed"); - TEST_RESULT_VOID(storageRemoveP(storageTest, backupInfoFileName, .errorOnMissing = true), "backup.info removed"); + TEST_STORAGE_EXISTS(storageRepoIdxWrite(0), INFO_ARCHIVE_PATH_FILE, .remove = true); + TEST_STORAGE_EXISTS(storageRepoIdxWrite(0), INFO_BACKUP_PATH_FILE, .remove = true); + HRN_STORAGE_PATH_CREATE( + storageRepoIdxWrite(0), STORAGE_REPO_BACKUP "/backup.history", .comment = "create directory in backup"); - TEST_RESULT_VOID( - storagePathCreateP(storageTest, strNewFmt("%s/backup.history", strZ(backupStanzaPath))), - "create directory in backup"); TEST_ERROR(cmdStanzaCreate(), PathNotEmptyError, "backup directory not empty"); - TEST_RESULT_LOG("P00 INFO: stanza-create for stanza 'db' on repo1"); + TEST_RESULT_LOG("P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1"); // File in archive, directory in backup - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, strNewFmt("%s/somefile", strZ(archiveStanzaPath))), BUFSTRDEF("some content")), - "create file in archive"); + HRN_STORAGE_PUT_Z(storageRepoIdxWrite(0), STORAGE_REPO_ARCHIVE "/somefile", "some content"); TEST_ERROR(cmdStanzaCreate(), PathNotEmptyError, "backup directory and/or archive directory not empty"); - TEST_RESULT_LOG("P00 INFO: stanza-create for stanza 'db' on repo1"); + TEST_RESULT_LOG("P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1"); // File in archive, backup empty - TEST_RESULT_VOID( - storagePathRemoveP(storageTest, strNewFmt("%s/backup.history", strZ(backupStanzaPath))), "remove backup subdir"); + HRN_STORAGE_PATH_REMOVE(storageRepoIdxWrite(0), STORAGE_REPO_BACKUP "/backup.history", .comment = "remove backup subdir"); TEST_ERROR(cmdStanzaCreate(), PathNotEmptyError, "archive directory not empty"); - TEST_RESULT_LOG("P00 INFO: stanza-create for stanza 'db' on repo1"); + TEST_RESULT_LOG("P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1"); - // Repeat last test using --force (deprecated) //-------------------------------------------------------------------------------------------------------------------------- - strLstAddZ(argList, "--force"); + TEST_TITLE("repeat last test using --force (deprecated)"); + + hrnCfgArgRawBool(argList, cfgOptForce, true); HRN_CFG_LOAD(cfgCmdStanzaCreate, argList); TEST_ERROR(cmdStanzaCreate(), PathNotEmptyError, "archive directory not empty"); TEST_RESULT_LOG( "P00 WARN: option --force is no longer supported\n" - "P00 INFO: stanza-create for stanza 'db' on repo1"); + "P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1"); } // ***************************************************************************************************************************** if (testBegin("pgValidate(), online=y")) { - const String *pg1 = STRDEF("pg1"); - String *pg1Path = strNewFmt(TEST_PATH "/%s", strZ(pg1)); - // Load Parameters StringList *argList = strLstNew(); - strLstAdd(argList, strNewFmt("--stanza=%s", strZ(stanza))); - strLstAdd(argList, strNewFmt("--pg1-path=%s", strZ(pg1Path))); - strLstAddZ(argList, "--repo1-path=" TEST_PATH "/repo"); + hrnCfgArgRawZ(argList, cfgOptStanza, TEST_STANZA); + hrnCfgArgRawZ(argList, cfgOptPgPath, TEST_PATH_PG); + hrnCfgArgRawZ(argList, cfgOptRepoPath, TEST_PATH_REPO); HRN_CFG_LOAD(cfgCmdStanzaCreate, argList); - // pgControl and database match //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("pgControl and database match"); + // Create pg_control - storagePutP( - storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1))), + HRN_STORAGE_PUT( + storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, hrnPgControlToBuffer((PgControl){.version = PG_VERSION_92, .systemId = 6569239123849665699})); harnessPqScriptSet((HarnessPq []) { - HRNPQ_MACRO_OPEN_GE_92(1, "dbname='postgres' port=5432", PG_VERSION_92, strZ(pg1Path), false, NULL, NULL), + HRNPQ_MACRO_OPEN_GE_92(1, "dbname='postgres' port=5432", PG_VERSION_92, TEST_PATH_PG, false, NULL, NULL), HRNPQ_MACRO_DONE() }); TEST_RESULT_VOID(cmdStanzaCreate(), "stanza create - db online"); - TEST_RESULT_LOG("P00 INFO: stanza-create for stanza 'db' on repo1"); - TEST_RESULT_BOOL( - storageExistsP(storageTest, strNewFmt("repo/archive/%s/archive.info", strZ(stanza))), true, " stanza created"); + TEST_RESULT_LOG("P00 INFO: stanza-create for stanza '" TEST_STANZA "' on repo1"); + TEST_STORAGE_LIST( + storageTest, TEST_PATH_REPO, + "archive/\n" + "archive/" TEST_STANZA "/\n" + "archive/" TEST_STANZA "/archive.info\n" + "archive/" TEST_STANZA "/archive.info.copy\n" + "backup/\n" + "backup/" TEST_STANZA "/\n" + "backup/" TEST_STANZA "/backup.info\n" + "backup/" TEST_STANZA "/backup.info.copy\n", + .comment = "stanza created"); HRN_CFG_LOAD(cfgCmdStanzaUpgrade, argList); harnessPqScriptSet((HarnessPq []) { - HRNPQ_MACRO_OPEN_GE_92(1, "dbname='postgres' port=5432", PG_VERSION_92, strZ(pg1Path), false, NULL, NULL), + HRNPQ_MACRO_OPEN_GE_92(1, "dbname='postgres' port=5432", PG_VERSION_92, TEST_PATH_PG, false, NULL, NULL), HRNPQ_MACRO_DONE() }); TEST_RESULT_VOID(cmdStanzaUpgrade(), "stanza upgrade - db online"); TEST_RESULT_LOG( - "P00 INFO: stanza-upgrade for stanza 'db' on repo1\n" - "P00 INFO: stanza 'db' on repo1 is already up to date"); + "P00 INFO: stanza-upgrade for stanza '" TEST_STANZA "' on repo1\n" + "P00 INFO: stanza '" TEST_STANZA "' on repo1 is already up to date"); - // Version mismatch //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("pg_control and version mismatch"); + // Create pg_control with different version - storagePutP( - storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1))), + HRN_STORAGE_PUT( + storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, hrnPgControlToBuffer((PgControl){.version = PG_VERSION_91, .systemId = 6569239123849665699})); harnessPqScriptSet((HarnessPq []) { - HRNPQ_MACRO_OPEN_GE_92(1, "dbname='postgres' port=5432", PG_VERSION_92, strZ(pg1Path), false, NULL, NULL), + HRNPQ_MACRO_OPEN_GE_92(1, "dbname='postgres' port=5432", PG_VERSION_92, TEST_PATH_PG, false, NULL, NULL), HRNPQ_MACRO_DONE() }); - TEST_ERROR_FMT( + TEST_ERROR( pgValidate(), DbMismatchError, - "version '" PG_VERSION_92_STR "' and path '%s' queried from cluster do not match version '" PG_VERSION_91_STR "' and " - "'%s' read from '%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL "'\n" - "HINT: the pg1-path and pg1-port settings likely reference different clusters.", - strZ(pg1Path), strZ(pg1Path), strZ(pg1Path)); + "version '" PG_VERSION_92_STR "' and path '" TEST_PATH_PG "' queried from cluster do not match version '" PG_VERSION_91_STR "' and " + "'" TEST_PATH_PG "' read from '" TEST_PATH_PG "/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL "'\n" + "HINT: the pg1-path and pg1-port settings likely reference different clusters."); - // Path mismatch //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("pg_control and path mismatch"); + // Create pg_control - storagePutP( - storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1))), + HRN_STORAGE_PUT( + storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, hrnPgControlToBuffer((PgControl){.version = PG_VERSION_92, .systemId = 6569239123849665699})); harnessPqScriptSet((HarnessPq []) @@ -629,56 +598,53 @@ testRun(void) HRNPQ_MACRO_DONE() }); - TEST_ERROR_FMT( + TEST_ERROR( pgValidate(), DbMismatchError, "version '" PG_VERSION_92_STR "' and path '" TEST_PATH "/pg2' queried from cluster do not match version '" - PG_VERSION_92_STR "' and '%s' read from '%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL - "'\nHINT: the pg1-path and pg1-port settings likely reference different clusters.", - strZ(pg1Path), strZ(pg1Path)); + PG_VERSION_92_STR "' and '" TEST_PATH_PG "' read from '" TEST_PATH_PG "/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL + "'\nHINT: the pg1-path and pg1-port settings likely reference different clusters."); - // Primary at pg2 //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("primary at pg2"); + argList = strLstNew(); - strLstAdd(argList, strNewFmt("--stanza=%s", strZ(stanza))); - strLstAddZ(argList, "--pg1-path=" TEST_PATH); - strLstAdd(argList, strNewFmt("--pg2-path=%s", strZ(pg1Path))); - strLstAddZ(argList, "--pg2-port=5434"); - strLstAddZ(argList, "--repo1-path=" TEST_PATH "/repo"); + hrnCfgArgRawZ(argList, cfgOptStanza, TEST_STANZA); + hrnCfgArgRawZ(argList, cfgOptPgPath, TEST_PATH_PG); + hrnCfgArgRawZ(argList, cfgOptRepoPath, TEST_PATH_REPO); + hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 2, TEST_PATH_PG "1"); + hrnCfgArgKeyRawZ(argList, cfgOptPgPort, 2, "5434"); + HRN_CFG_LOAD(cfgCmdStanzaCreate, argList); // Create pg_control for primary - storagePutP( - storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(pg1))), + HRN_STORAGE_PUT( + storagePgIdxWrite(1), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, hrnPgControlToBuffer((PgControl){.version = PG_VERSION_92, .systemId = 6569239123849665699})); // Create pg_control for standby - storagePutP( - storageNewWriteP(storageTest, STRDEF(TEST_PATH "/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL)), + HRN_STORAGE_PUT( + storagePgIdxWrite(0), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, hrnPgControlToBuffer((PgControl){.version = PG_VERSION_94, .systemId = 6569239123849665700})); harnessPqScriptSet((HarnessPq []) { - HRNPQ_MACRO_OPEN_GE_92(1, "dbname='postgres' port=5432", PG_VERSION_92, TEST_PATH, true, NULL, NULL), - HRNPQ_MACRO_OPEN_GE_92(2, "dbname='postgres' port=5434", PG_VERSION_92, strZ(pg1Path), false, NULL, NULL), + HRNPQ_MACRO_OPEN_GE_92(1, "dbname='postgres' port=5432", PG_VERSION_92, TEST_PATH_PG, true, NULL, NULL), + HRNPQ_MACRO_OPEN_GE_92(2, "dbname='postgres' port=5434", PG_VERSION_92, TEST_PATH "/pg1", false, NULL, NULL), HRNPQ_MACRO_DONE() }); PgControl pgControl = {0}; TEST_ASSIGN(pgControl, pgValidate(), "validate primary on pg2"); - TEST_RESULT_UINT(pgControl.version, PG_VERSION_92, " version set"); - TEST_RESULT_UINT(pgControl.systemId, 6569239123849665699, " systemId set"); - TEST_RESULT_UINT(pgControl.catalogVersion, 201204301, " catalogVersion set"); + TEST_RESULT_UINT(pgControl.version, PG_VERSION_92, "version set"); + TEST_RESULT_UINT(pgControl.systemId, 6569239123849665699, "systemId set"); + TEST_RESULT_UINT(pgControl.catalogVersion, 201204301, "catalogVersion set"); } // ***************************************************************************************************************************** if (testBegin("cmdStanzaUpgrade()")) { - // Create pg_control - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(stanza))), - hrnPgControlToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 6569239123849665679})), - "create pg_control"); + //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("stanza-upgrade - config errors"); // Load Parameters StringList *argList = strLstDup(argListBase); @@ -689,24 +655,25 @@ testRun(void) hrnCfgLoadP(cfgCmdStanzaUpgrade, argList), OptionInvalidError, "option 'repo' not valid for command 'stanza-upgrade'"); - //-------------------------------------------------------------------------------------------------------------------------- HRN_CFG_LOAD(cfgCmdStanzaUpgrade, argListBase); - // Create the stop file - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageLocalWrite(), lockStopFileName(cfgOptionStr(cfgOptStanza))), BUFSTRDEF("")), - "create stop file"); - TEST_ERROR_FMT(cmdStanzaUpgrade(), StopError, "stop file exists for stanza %s", strZ(stanza)); - TEST_RESULT_VOID( - storageRemoveP(storageLocalWrite(), lockStopFileName(cfgOptionStr(cfgOptStanza))), " remove the stop file"); + // Create the stop file, test and remove + HRN_STORAGE_PUT_EMPTY(storageHrn, strZ(lockStopFileName(cfgOptionStr(cfgOptStanza)))); + TEST_ERROR(cmdStanzaUpgrade(), StopError, "stop file exists for stanza " TEST_STANZA); + HRN_STORAGE_REMOVE(storageHrn, strZ(lockStopFileName(cfgOptionStr(cfgOptStanza)))); + + //-------------------------------------------------------------------------------------------------------------------------- + // Create pg_control for the rest of the tests + HRN_STORAGE_PUT( + storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, + hrnPgControlToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 6569239123849665679})); //-------------------------------------------------------------------------------------------------------------------------- - TEST_TITLE("cmdStanzaUpgrade - info file mismatches"); + TEST_TITLE("stanza-upgrade - info file mismatch: db-id"); // Stanza with only archive.info and backup.info but no .copy files - const String *contentBackup = STRDEF - ( + HRN_INFO_PUT( + storageRepoIdxWrite(0), INFO_BACKUP_PATH_FILE, "[db]\n" "db-catalog-version=201608131\n" "db-control-version=960\n" @@ -716,44 +683,18 @@ testRun(void) "\n" "[db:history]\n" "1={\"db-catalog-version\":201608131,\"db-control-version\":960,\"db-system-id\":6569239123849665679," - "\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, backupInfoFileName), harnessInfoChecksum(contentBackup)), - "put backup info to file"); - - const String *contentArchive = STRDEF - ( - "[db]\n" - "db-id=1\n" - "db-system-id=6569239123849665679\n" - "db-version=\"9.6\"\n" - "\n" - "[db:history]\n" - "1={\"db-id\":6569239123849665679,\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, archiveInfoFileName), harnessInfoChecksum(contentArchive)), - "put archive info file"); + "\"db-version\":\"9.6\"}\n"); // backup info up to date but archive info db-id mismatch - //-------------------------------------------------------------------------------------------------------------------------- - contentArchive = STRDEF - ( + HRN_INFO_PUT( + storageRepoIdxWrite(0), INFO_ARCHIVE_PATH_FILE, "[db]\n" "db-id=2\n" "db-system-id=6569239123849665679\n" "db-version=\"9.6\"\n" "\n" "[db:history]\n" - "2={\"db-id\":6569239123849665679,\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, archiveInfoFileName), harnessInfoChecksum(contentArchive)), - "put archive info to file"); + "2={\"db-id\":6569239123849665679,\"db-version\":\"9.6\"}\n"); TEST_ERROR( cmdStanzaUpgrade(), FileInvalidError, @@ -761,12 +702,14 @@ testRun(void) "archive: id = 2, version = 9.6, system-id = 6569239123849665679\n" "backup : id = 1, version = 9.6, system-id = 6569239123849665679\n" "HINT: this may be a symptom of repository corruption!"); - TEST_RESULT_LOG("P00 INFO: stanza-upgrade for stanza 'db' on repo1"); + TEST_RESULT_LOG("P00 INFO: stanza-upgrade for stanza '" TEST_STANZA "' on repo1"); - // backup info up to date but archive info version is not //-------------------------------------------------------------------------------------------------------------------------- - contentBackup = STRDEF - ( + TEST_TITLE("stanza-upgrade - info file mismatch: archive version"); + + // backup info up to date but archive info version is not + HRN_INFO_PUT( + storageRepoIdxWrite(0), INFO_BACKUP_PATH_FILE, "[db]\n" "db-catalog-version=201608131\n" "db-control-version=960\n" @@ -778,32 +721,22 @@ testRun(void) "1={\"db-catalog-version\":201510051,\"db-control-version\":942,\"db-system-id\":6569239123849665999," "\"db-version\":\"9.5\"}\n" "2={\"db-catalog-version\":201608131,\"db-control-version\":960,\"db-system-id\":6569239123849665679," - "\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, backupInfoFileName), harnessInfoChecksum(contentBackup)), - "put backup info to file"); - - contentArchive = STRDEF - ( + "\"db-version\":\"9.6\"}\n"); + HRN_INFO_PUT( + storageRepoIdxWrite(0), INFO_ARCHIVE_PATH_FILE, "[db]\n" "db-id=1\n" "db-system-id=6569239123849665679\n" "db-version=\"9.5\"\n" "\n" "[db:history]\n" - "1={\"db-id\":6569239123849665679,\"db-version\":\"9.5\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, archiveInfoFileName), harnessInfoChecksum(contentArchive)), - "put archive info to file"); + "1={\"db-id\":6569239123849665679,\"db-version\":\"9.5\"}\n"); TEST_RESULT_VOID(cmdStanzaUpgrade(), "stanza upgrade - archive.info file upgraded - version"); - TEST_RESULT_LOG("P00 INFO: stanza-upgrade for stanza 'db' on repo1"); - contentArchive = STRDEF - ( + TEST_RESULT_LOG("P00 INFO: stanza-upgrade for stanza '" TEST_STANZA "' on repo1"); + + HRN_INFO_PUT( + storageHrn, "test.info", "[db]\n" "db-id=2\n" "db-system-id=6569239123849665679\n" @@ -811,25 +744,24 @@ testRun(void) "\n" "[db:history]\n" "1={\"db-id\":6569239123849665679,\"db-version\":\"9.5\"}\n" - "2={\"db-id\":6569239123849665679,\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, fileName), harnessInfoChecksum(contentArchive)), - " put archive info to test file"); + "2={\"db-id\":6569239123849665679,\"db-version\":\"9.6\"}\n", + .comment = "put archive info to test file"); + TEST_RESULT_BOOL( (bufEq( - storageGetP(storageNewReadP(storageTest, archiveInfoFileName)), - storageGetP(storageNewReadP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(archiveInfoFileName))))) && + storageGetP(storageNewReadP(storageRepoIdx(0), INFO_ARCHIVE_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageRepoIdx(0), STRDEF(INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT)))) && bufEq( - storageGetP(storageNewReadP(storageTest, archiveInfoFileName)), - storageGetP(storageNewReadP(storageTest, fileName)))), - true, " test and stanza archive info files are equal"); + storageGetP(storageNewReadP(storageRepoIdx(0), INFO_ARCHIVE_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageHrn, STRDEF("test.info"))))), + true, "test and stanza archive info files are equal"); - // archive info up to date but backup info version is not //-------------------------------------------------------------------------------------------------------------------------- - contentBackup = STRDEF - ( + TEST_TITLE("stanza-upgrade - info file mismatch: backup version"); + + // archive info up to date but backup info version is not + HRN_INFO_PUT( + storageRepoIdxWrite(0), INFO_BACKUP_PATH_FILE, "[db]\n" "db-catalog-version=201608131\n" "db-control-version=960\n" @@ -839,17 +771,13 @@ testRun(void) "\n" "[db:history]\n" "1={\"db-catalog-version\":201510051,\"db-control-version\":942,\"db-system-id\":6569239123849665679," - "\"db-version\":\"9.5\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, backupInfoFileName), harnessInfoChecksum(contentBackup)), - "put backup info to file"); + "\"db-version\":\"9.5\"}\n"); TEST_RESULT_VOID(cmdStanzaUpgrade(), "stanza upgrade - backup.info file upgraded - version"); TEST_RESULT_LOG("P00 INFO: stanza-upgrade for stanza 'db' on repo1"); - contentBackup = STRDEF - ( + + HRN_INFO_PUT( + storageHrn, "test.info", "[db]\n" "db-catalog-version=201608131\n" "db-control-version=960\n" @@ -861,26 +789,24 @@ testRun(void) "1={\"db-catalog-version\":201510051,\"db-control-version\":942,\"db-system-id\":6569239123849665679," "\"db-version\":\"9.5\"}\n" "2={\"db-catalog-version\":201608131,\"db-control-version\":960,\"db-system-id\":6569239123849665679," - "\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, fileName), harnessInfoChecksum(contentBackup)), - " put backup info to test file"); + "\"db-version\":\"9.6\"}\n", + .comment = "put backup info to test file"); TEST_RESULT_BOOL( (bufEq( - storageGetP(storageNewReadP(storageTest, backupInfoFileName)), - storageGetP(storageNewReadP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(backupInfoFileName))))) && + storageGetP(storageNewReadP(storageRepoIdx(0), INFO_BACKUP_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageRepoIdx(0), STRDEF(INFO_BACKUP_PATH_FILE INFO_COPY_EXT)))) && bufEq( - storageGetP(storageNewReadP(storageTest, backupInfoFileName)), - storageGetP(storageNewReadP(storageTest, fileName)))), - true, " test and stanza backup info files are equal"); + storageGetP(storageNewReadP(storageRepoIdx(0), INFO_BACKUP_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageHrn, STRDEF("test.info"))))), + true, "test and stanza backup info files are equal"); - // backup info up to date but archive info system-id is not //-------------------------------------------------------------------------------------------------------------------------- - contentBackup = STRDEF - ( + TEST_TITLE("stanza-upgrade - info file mismatch: archive system-id"); + + // backup info up to date but archive info system-id is not + HRN_INFO_PUT( + storageRepoIdxWrite(0), INFO_BACKUP_PATH_FILE, "[db]\n" "db-catalog-version=201608131\n" "db-control-version=960\n" @@ -892,32 +818,22 @@ testRun(void) "1={\"db-catalog-version\":201510051,\"db-control-version\":942,\"db-system-id\":6569239123849665999," "\"db-version\":\"9.5\"}\n" "2={\"db-catalog-version\":201608131,\"db-control-version\":960,\"db-system-id\":6569239123849665679," - "\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, backupInfoFileName), harnessInfoChecksum(contentBackup)), - "put backup info to file"); - - contentArchive = STRDEF - ( + "\"db-version\":\"9.6\"}\n"); + HRN_INFO_PUT( + storageRepoIdxWrite(0), INFO_ARCHIVE_PATH_FILE, "[db]\n" "db-id=1\n" "db-system-id=6569239123849665999\n" "db-version=\"9.6\"\n" "\n" "[db:history]\n" - "1={\"db-id\":6569239123849665999,\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, archiveInfoFileName), harnessInfoChecksum(contentArchive)), - "put archive info to file"); + "1={\"db-id\":6569239123849665999,\"db-version\":\"9.6\"}\n"); TEST_RESULT_VOID(cmdStanzaUpgrade(), "stanza upgrade - archive.info file upgraded - system-id"); - TEST_RESULT_LOG("P00 INFO: stanza-upgrade for stanza 'db' on repo1"); - contentArchive = STRDEF - ( + TEST_RESULT_LOG("P00 INFO: stanza-upgrade for stanza '" TEST_STANZA "' on repo1"); + + HRN_INFO_PUT( + storageHrn, "test.info", "[db]\n" "db-id=2\n" "db-system-id=6569239123849665679\n" @@ -925,25 +841,24 @@ testRun(void) "\n" "[db:history]\n" "1={\"db-id\":6569239123849665999,\"db-version\":\"9.6\"}\n" - "2={\"db-id\":6569239123849665679,\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, fileName), harnessInfoChecksum(contentArchive)), - " put archive info to test file"); + "2={\"db-id\":6569239123849665679,\"db-version\":\"9.6\"}\n", + .comment = "put archive info to test file"); + TEST_RESULT_BOOL( (bufEq( - storageGetP(storageNewReadP(storageTest, archiveInfoFileName)), - storageGetP(storageNewReadP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(archiveInfoFileName))))) && + storageGetP(storageNewReadP(storageRepoIdx(0), INFO_ARCHIVE_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageRepoIdx(0), STRDEF(INFO_ARCHIVE_PATH_FILE INFO_COPY_EXT)))) && bufEq( - storageGetP(storageNewReadP(storageTest, archiveInfoFileName)), - storageGetP(storageNewReadP(storageTest, fileName)))), - true, " test and stanza archive info files are equal"); + storageGetP(storageNewReadP(storageRepoIdx(0), INFO_ARCHIVE_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageHrn, STRDEF("test.info"))))), + true, "test and stanza archive info files are equal"); - // archive info up to date but backup info system-id is not //-------------------------------------------------------------------------------------------------------------------------- - contentBackup = STRDEF - ( + TEST_TITLE("stanza-upgrade - info file mismatch: backup system-id"); + + // archive info up to date but backup info system-id is not + HRN_INFO_PUT( + storageRepoIdxWrite(0), INFO_BACKUP_PATH_FILE, "[db]\n" "db-catalog-version=201608131\n" "db-control-version=960\n" @@ -953,17 +868,13 @@ testRun(void) "\n" "[db:history]\n" "1={\"db-catalog-version\":201608131,\"db-control-version\":960,\"db-system-id\":6569239123849665999," - "\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, backupInfoFileName), harnessInfoChecksum(contentBackup)), - "put backup info to file"); + "\"db-version\":\"9.6\"}\n"); TEST_RESULT_VOID(cmdStanzaUpgrade(), "stanza upgrade - backup.info file upgraded - system-id"); - TEST_RESULT_LOG("P00 INFO: stanza-upgrade for stanza 'db' on repo1"); - contentBackup = STRDEF - ( + TEST_RESULT_LOG("P00 INFO: stanza-upgrade for stanza '" TEST_STANZA "' on repo1"); + + HRN_INFO_PUT( + storageHrn, "test.info", "[db]\n" "db-catalog-version=201608131\n" "db-control-version=960\n" @@ -975,21 +886,16 @@ testRun(void) "1={\"db-catalog-version\":201608131,\"db-control-version\":960,\"db-system-id\":6569239123849665999," "\"db-version\":\"9.6\"}\n" "2={\"db-catalog-version\":201608131,\"db-control-version\":960,\"db-system-id\":6569239123849665679," - "\"db-version\":\"9.6\"}\n" - ); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, fileName), harnessInfoChecksum(contentBackup)), - " put backup info to test file"); - + "\"db-version\":\"9.6\"}\n", + .comment = "put backup info to test file"); TEST_RESULT_BOOL( (bufEq( - storageGetP(storageNewReadP(storageTest, backupInfoFileName)), - storageGetP(storageNewReadP(storageTest, strNewFmt("%s" INFO_COPY_EXT, strZ(backupInfoFileName))))) && + storageGetP(storageNewReadP(storageRepoIdx(0), INFO_BACKUP_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageRepoIdx(0), STRDEF(INFO_BACKUP_PATH_FILE INFO_COPY_EXT)))) && bufEq( - storageGetP(storageNewReadP(storageTest, backupInfoFileName)), - storageGetP(storageNewReadP(storageTest, fileName)))), - true, " test and stanza backup info files are equal"); + storageGetP(storageNewReadP(storageRepoIdx(0), INFO_BACKUP_PATH_FILE_STR)), + storageGetP(storageNewReadP(storageHrn, STRDEF("test.info"))))), + true, "test and stanza backup info files are equal"); } // ***************************************************************************************************************************** @@ -997,136 +903,145 @@ testRun(void) { // Load Parameters StringList *argListCmd = strLstNew(); - strLstAddZ(argListCmd, "--repo1-path=" TEST_PATH "/repo"); - - //-------------------------------------------------------------------------------------------------------------------------- - const String *stanzaOther = STRDEF("otherstanza"); + hrnCfgArgKeyRawZ(argListCmd, cfgOptRepoPath, 1, TEST_PATH_REPO); // Load Parameters StringList *argList = strLstDup(argListCmd); - strLstAdd(argList, strNewFmt("--stanza=%s", strZ(stanzaOther))); - strLstAdd(argList, strNewFmt("--pg1-path=" TEST_PATH "/%s", strZ(stanzaOther))); - strLstAddZ(argList, "--no-online"); + hrnCfgArgRawZ(argList, cfgOptStanza, TEST_STANZA_OTHER); + hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 1, TEST_PATH "/" TEST_STANZA_OTHER); + hrnCfgArgRawBool(argList, cfgOptOnline, false); HRN_CFG_LOAD(cfgCmdStanzaCreate, argList); // Create pg_control for stanza-create - storagePutP( - storageNewWriteP(storageTest, strNewFmt("%s/" PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, strZ(stanzaOther))), + HRN_STORAGE_PUT( + storagePgWrite(), PG_PATH_GLOBAL "/" PG_FILE_PGCONTROL, hrnPgControlToBuffer((PgControl){.version = PG_VERSION_96, .systemId = 6569239123849665679})); TEST_RESULT_VOID(cmdStanzaCreate(), "create a stanza that will not be deleted"); - TEST_RESULT_LOG("P00 INFO: stanza-create for stanza 'otherstanza' on repo1"); + TEST_RESULT_LOG("P00 INFO: stanza-create for stanza '" TEST_STANZA_OTHER "' on repo1"); argList = strLstDup(argListCmd); - strLstAdd(argList, strNewFmt("--stanza=%s", strZ(stanza))); - strLstAdd(argList, strNewFmt("--pg1-path=" TEST_PATH "/%s", strZ(stanza))); + hrnCfgArgRawZ(argList, cfgOptStanza, TEST_STANZA); + hrnCfgArgKeyRawZ(argList, cfgOptPgPath, 1, TEST_PATH_PG); HRN_CFG_LOAD(cfgCmdStanzaDelete, argList); - // stanza already deleted //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("stanza-delete - stanza already deleted"); + TEST_RESULT_VOID(cmdStanzaDelete(), "stanza delete - success on stanza does not exist"); - TEST_RESULT_BOOL(stanzaDelete(storageRepoWrite(), NULL, NULL), true, " archiveList=NULL, backupList=NULL"); - TEST_RESULT_BOOL(stanzaDelete(storageRepoWrite(), strLstNew(), NULL), true, " archiveList=0, backupList=NULL"); - TEST_RESULT_BOOL(stanzaDelete(storageRepoWrite(), NULL, strLstNew()), true, " archiveList=NULL, backupList=0"); - TEST_RESULT_BOOL(stanzaDelete(storageRepoWrite(), strLstNew(), strLstNew()), true, " archiveList=0, backupList=0"); + TEST_RESULT_BOOL(stanzaDelete(storageRepoWrite(), NULL, NULL), true, "archiveList=NULL, backupList=NULL"); + TEST_RESULT_BOOL(stanzaDelete(storageRepoWrite(), strLstNew(), NULL), true, "archiveList=0, backupList=NULL"); + TEST_RESULT_BOOL(stanzaDelete(storageRepoWrite(), NULL, strLstNew()), true, "archiveList=NULL, backupList=0"); + TEST_RESULT_BOOL(stanzaDelete(storageRepoWrite(), strLstNew(), strLstNew()), true, "archiveList=0, backupList=0"); + + //-------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("stanza-delete - only archive exists"); + + // Confirm stanza does not exist + TEST_STORAGE_LIST( + storageTest, "repo/archive", TEST_STANZA_OTHER "/\n", .noRecurse=true, + .comment = "stanza '" TEST_STANZA "' archive does not exist"); + TEST_STORAGE_LIST( + storageTest, "repo/backup", TEST_STANZA_OTHER "/\n", .noRecurse=true, + .comment = "stanza '" TEST_STANZA "' backup does not exist"); // Create stanza archive only + HRN_STORAGE_PUT_EMPTY( + storageRepoWrite(), INFO_ARCHIVE_PATH_FILE, .comment = "create empty archive info for stanza '" TEST_STANZA "'"); + HRN_STORAGE_PUT_EMPTY(storageHrn, strZ(lockStopFileName(cfgOptionStr(cfgOptStanza))), .comment = "create stop file"); + TEST_STORAGE_LIST( + storageTest, "repo/archive", + TEST_STANZA "/\n" + TEST_STANZA_OTHER "/\n", + .noRecurse = true, .comment = "stanza archive exists"); + TEST_RESULT_VOID(cmdStanzaDelete(), "stanza delete - archive only"); + + TEST_STORAGE_LIST( + storageTest, "repo/archive", TEST_STANZA_OTHER "/\n", .noRecurse=true, .comment = "stanza '" TEST_STANZA "' deleted"); + //-------------------------------------------------------------------------------------------------------------------------- - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, strNewFmt("repo/archive/%s/archive.info", strZ(stanza))), BUFSTRDEF("")), - "create archive.info"); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageLocalWrite(), lockStopFileName(cfgOptionStr(cfgOptStanza))), BUFSTRDEF("")), - "create stop file"); - TEST_RESULT_VOID(cmdStanzaDelete(), " stanza delete - archive only"); - TEST_RESULT_BOOL( - storagePathExistsP(storageTest, strNewFmt("repo/archive/%s", strZ(stanza))), false, " stanza deleted"); + TEST_TITLE("stanza-delete - only backup exists"); // Create stanza backup only - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, strNewFmt("repo/backup/%s/backup.info", strZ(stanza))), BUFSTRDEF("")), - "create backup.info"); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageLocalWrite(), lockStopFileName(cfgOptionStr(cfgOptStanza))), BUFSTRDEF("")), - "create stop file"); - TEST_RESULT_VOID(cmdStanzaDelete(), " stanza delete - backup only"); - TEST_RESULT_BOOL( - storagePathExistsP(storageTest, strNewFmt("repo/backup/%s", strZ(stanza))), false, " stanza deleted"); + HRN_STORAGE_PUT_EMPTY( + storageRepoWrite(), INFO_BACKUP_PATH_FILE, + .comment = "create empty backup info for stanza '" TEST_STANZA "'"); + HRN_STORAGE_PUT_EMPTY(storageHrn, strZ(lockStopFileName(cfgOptionStr(cfgOptStanza))), .comment = "create stop file"); + TEST_STORAGE_LIST( + storageTest, "repo/backup", + TEST_STANZA "/\n" + TEST_STANZA_OTHER "/\n", + .noRecurse = true, .comment = "stanza backup exists"); + + TEST_RESULT_VOID(cmdStanzaDelete(), "stanza delete - backup only"); + TEST_STORAGE_LIST( + storageTest, "repo/backup", TEST_STANZA_OTHER "/\n", .noRecurse=true, .comment = "stanza '" TEST_STANZA "' deleted"); - // Create a backup file that matches the regex for a backup directory //-------------------------------------------------------------------------------------------------------------------------- - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, strNewFmt("repo/backup/%s/20190708-154306F", strZ(stanza))), BUFSTRDEF("")), - "backup file that looks like a directory"); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageLocalWrite(), lockStopFileName(cfgOptionStr(cfgOptStanza))), BUFSTRDEF("")), - "create stop file"); - TEST_ERROR_FMT( + TEST_TITLE("stanza-delete - error on file that looks like backup directory"); + + // Create a backup file that matches the regex for a backup directory + HRN_STORAGE_PUT_EMPTY( + storageRepoWrite(), STORAGE_REPO_BACKUP "/20190708-154306F", .comment = "backup file that looks like a directory"); + HRN_STORAGE_PUT_EMPTY(storageHrn, strZ(lockStopFileName(cfgOptionStr(cfgOptStanza))), .comment = "create stop file"); + TEST_ERROR( cmdStanzaDelete(), FileRemoveError, - "unable to remove '" TEST_PATH "/repo/backup/%s/20190708-154306F/backup.manifest': [20] Not a directory", strZ(stanza)); - TEST_RESULT_VOID( - storageRemoveP(storageTest, strNewFmt("repo/backup/%s/20190708-154306F", strZ(stanza))), "remove backup directory"); + "unable to remove '" TEST_PATH_REPO "/backup/" TEST_STANZA "/20190708-154306F/backup.manifest': [20] Not a directory"); + HRN_STORAGE_REMOVE(storageTest, "repo/backup/" TEST_STANZA "/20190708-154306F", "cleanup - remove backup file"); - // Create backup manifest //-------------------------------------------------------------------------------------------------------------------------- - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, strNewFmt("repo/backup/%s/20190708-154306F/backup.manifest", strZ(stanza))), - BUFSTRDEF("")), "create backup.manifest only"); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, strNewFmt("repo/backup/%s/20190708-154306F_20190716-191726I/backup.manifest.copy", - strZ(stanza))), BUFSTRDEF("")), "create backup.manifest.copy only"); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, strNewFmt("repo/backup/%s/20190708-154306F_20190716-191800D/backup.manifest", - strZ(stanza))), BUFSTRDEF("")), "create backup.manifest"); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, strNewFmt("repo/backup/%s/20190708-154306F_20190716-191800D/backup.manifest.copy", - strZ(stanza))), BUFSTRDEF("")), "create backup.manifest.copy"); + TEST_TITLE("manifestDelete()"); + + // Create backup manifests + HRN_STORAGE_PUT_EMPTY(storageRepoWrite(), STORAGE_REPO_BACKUP "/20190708-154306F/" BACKUP_MANIFEST_FILE); + HRN_STORAGE_PUT_EMPTY( + storageRepoWrite(), STORAGE_REPO_BACKUP "/20190708-154306F_20190716-191726I/" BACKUP_MANIFEST_FILE INFO_COPY_EXT); + HRN_STORAGE_PUT_EMPTY(storageRepoWrite(), STORAGE_REPO_BACKUP "/20190708-154306F_20190716-191800D/" BACKUP_MANIFEST_FILE); + HRN_STORAGE_PUT_EMPTY( + storageRepoWrite(), STORAGE_REPO_BACKUP "/20190708-154306F_20190716-191800D/" BACKUP_MANIFEST_FILE INFO_COPY_EXT); + + TEST_STORAGE_LIST( + storageRepoWrite(), STORAGE_REPO_BACKUP, + "20190708-154306F/\n" + "20190708-154306F/backup.manifest\n" + "20190708-154306F_20190716-191726I/\n" + "20190708-154306F_20190716-191726I/backup.manifest.copy\n" + "20190708-154306F_20190716-191800D/\n" + "20190708-154306F_20190716-191800D/backup.manifest\n" + "20190708-154306F_20190716-191800D/backup.manifest.copy\n"); + TEST_RESULT_VOID(manifestDelete(storageRepoWrite()), "delete manifests"); - TEST_RESULT_BOOL( - (storageExistsP(storageTest, strNewFmt("repo/backup/%s/20190708-154306F/backup.manifest", strZ(stanza))) && - storageExistsP(storageTest, strNewFmt("repo/backup/%s/20190708-154306F_20190716-191726I/backup.manifest.copy", - strZ(stanza))) && - storageExistsP(storageTest, strNewFmt("repo/backup/%s/20190708-154306F_20190716-191800D/backup.manifest", - strZ(stanza))) && - storageExistsP(storageTest, strNewFmt("repo/backup/%s/20190708-154306F_20190716-191800D/backup.manifest.copy", - strZ(stanza)))), false, " all manifests deleted"); + TEST_STORAGE_LIST( + storageRepoWrite(), STORAGE_REPO_BACKUP, + "20190708-154306F/\n" + "20190708-154306F_20190716-191726I/\n" + "20190708-154306F_20190716-191800D/\n", .comment = "all manifest files deleted"); - // Create only stanza paths //-------------------------------------------------------------------------------------------------------------------------- - TEST_RESULT_VOID(cmdStanzaDelete(), "stanza delete"); - TEST_RESULT_VOID( - storagePathCreateP(storageTest, strNewFmt("repo/archive/%s", strZ(stanza))), "create empty stanza archive path"); - TEST_RESULT_VOID( - storagePathCreateP(storageTest, strNewFmt("repo/backup/%s", strZ(stanza))), "create empty stanza backup path"); - TEST_RESULT_VOID(cmdStanzaDelete(), " stanza delete - empty directories"); + TEST_TITLE("stanza-delete - empty directories"); + + TEST_RESULT_VOID(cmdStanzaDelete(), "remove stanza '" TEST_STANZA "'"); + + // Create only stanza paths + HRN_STORAGE_PATH_CREATE(storageTest, "repo/archive/" TEST_STANZA, .comment = "create empty stanza archive path"); + HRN_STORAGE_PATH_CREATE(storageTest, "repo/backup/" TEST_STANZA, .comment = "create empty stanza backup path"); + + TEST_RESULT_VOID(cmdStanzaDelete(), "stanza delete - empty directories"); + TEST_STORAGE_LIST( + storageTest, "repo/archive", TEST_STANZA_OTHER "/\n", .noRecurse=true, .comment = "stanza '" TEST_STANZA "' deleted"); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("delete errors when pg appears to be running"); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, strNewFmt("repo/backup/%s/backup.info", strZ(stanza))), BUFSTRDEF("")), - "create backup.info"); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageLocalWrite(), lockStopFileName(cfgOptionStr(cfgOptStanza))), BUFSTRDEF("")), - "create stop file"); - TEST_RESULT_VOID( - storagePutP(storageNewWriteP(storageTest, strNewFmt("%s/" PG_FILE_POSTMASTERPID, strZ(stanza))), BUFSTRDEF("")), - "create pid file"); + HRN_STORAGE_PUT_EMPTY( + storageRepoWrite(), INFO_BACKUP_PATH_FILE, .comment = "create empty backup info for stanza '" TEST_STANZA "'"); + HRN_STORAGE_PUT_EMPTY(storageHrn, strZ(lockStopFileName(cfgOptionStr(cfgOptStanza))), .comment = "create stop file"); + HRN_STORAGE_PUT_EMPTY(storagePgWrite(), PG_FILE_POSTMASTERPID, .comment = "create postmaster pid file"); + TEST_ERROR( cmdStanzaDelete(), PgRunningError, PG_FILE_POSTMASTERPID " exists - looks like " PG_NAME " is running. " - "To delete stanza 'db' on repo1, shut down " PG_NAME " for stanza 'db' and try again, or use --force."); + "To delete stanza '" TEST_STANZA "' on repo1, shut down " PG_NAME " for stanza '" TEST_STANZA + "' and try again, or use --force."); // Specify repo option StringList *argListDel = strLstDup(argList); @@ -1134,35 +1049,42 @@ testRun(void) hrnCfgArgRawZ(argListDel, cfgOptRepo, "2"); HRN_CFG_LOAD(cfgCmdStanzaDelete, argListDel); - TEST_RESULT_VOID( - storagePutP( - storageNewWriteP(storageTest, strNewFmt("repo2/backup/%s/backup.info", strZ(stanza))), BUFSTRDEF("")), - "create backup.info"); + HRN_STORAGE_PUT_EMPTY(storageRepoIdxWrite(1), INFO_BACKUP_PATH_FILE, .comment = "create empty backup info repo2"); + TEST_ERROR( cmdStanzaDelete(), PgRunningError, PG_FILE_POSTMASTERPID " exists - looks like " PG_NAME " is running. " - "To delete stanza 'db' on repo2, shut down " PG_NAME " for stanza 'db' and try again, or use --force."); + "To delete stanza '" TEST_STANZA "' on repo2, shut down " PG_NAME " for stanza '" TEST_STANZA + "' and try again, or use --force."); //-------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("force delete when pg appears to be running, multi-repo"); argList = strLstDup(argListCmd); - hrnCfgArgRaw(argList, cfgOptStanza, stanza); - hrnCfgArgKeyRawFmt(argList, cfgOptPgPath, 1, TEST_PATH "/%s", strZ(stanza)); + hrnCfgArgRawZ(argList, cfgOptStanza, TEST_STANZA); + hrnCfgArgKeyRawFmt(argList, cfgOptPgPath, 1, TEST_PATH_PG); hrnCfgArgKeyRawZ(argList, cfgOptRepoPath, 2, TEST_PATH "/repo2"); hrnCfgArgRawZ(argList, cfgOptRepo, "1"); - strLstAddZ(argList,"--force"); + hrnCfgArgRawBool(argList, cfgOptForce, true); HRN_CFG_LOAD(cfgCmdStanzaDelete, argList); - TEST_RESULT_VOID(cmdStanzaDelete(), "stanza delete --force"); - TEST_RESULT_BOOL( - storagePathExistsP(storageTest, strNewFmt("repo/backup/%s", strZ(stanza))), false, "repo1: stanza deleted"); - TEST_RESULT_BOOL( - storagePathExistsP(storageTest, strNewFmt("repo2/backup/%s", strZ(stanza))), true, "repo2: stanza not deleted"); + TEST_RESULT_VOID(cmdStanzaDelete(), "stanza '" TEST_STANZA "' delete --force"); + TEST_RESULT_BOOL(storagePathExistsP(storageTest, strNewZ("repo/backup/" TEST_STANZA)), false, "repo1: stanza deleted"); + TEST_RESULT_BOOL(storagePathExistsP(storageTest, strNewZ("repo2/backup/" TEST_STANZA)), true, "repo2: stanza not deleted"); - // Ensure other stanza never deleted //-------------------------------------------------------------------------------------------------------------------------- - TEST_RESULT_BOOL( - storageExistsP(storageTest, strNewFmt("repo/archive/%s/archive.info", strZ(stanzaOther))), true, "otherstanza exists"); + TEST_TITLE("ensure other stanza never deleted from repo1"); + + TEST_STORAGE_LIST( + storageRepo(), "", + "archive/\n" + "archive/otherstanza/\n" + "archive/otherstanza/archive.info\n" + "archive/otherstanza/archive.info.copy\n" + "backup/\n" + "backup/otherstanza/\n" + "backup/otherstanza/backup.info\n" + "backup/otherstanza/backup.info.copy\n", + .comment = "otherstanza exists"); } FUNCTION_HARNESS_RETURN_VOID();