pgbackrest.git / summary / log / commit / refs
commit 46911c64c19dc8ff76d2a6ff4548fc01647043e0
Author: David Steele <david@pgmasters.net>
Date: Mon Mar 16 21:24:21 2020 +0000
Make storage and logging dry-run aware.
Enhance dry-run support added in 2fa69af8 by forbidding writes in the storage layer and adding prefixes to log messages.
The former will protect against mistakes in dry-run implementations and the latter will make it clear when a command was executed in dry-run mode.
Update expire unit tests with the new log prefix.
src/common/log.c | 19 +++++++++++++++++--
src/common/log.h | 2 +-
src/config/load.c | 8 +++++++-
src/config/parse.c | 2 +-
src/storage/helper.c | 32 ++++++++++++++++++++++++++++++++
src/storage/helper.h | 5 +++++
test/define.yaml | 2 +-
test/src/common/harnessConfig.c | 6 ++++++
test/src/common/harnessLog.c | 23 +++++++++++++++++++----
test/src/common/harnessLog.h | 6 ++++++
test/src/module/command/expireTest.c | 16 ++++++++--------
test/src/module/common/logTest.c | 33 ++++++++++++++++++---------------
test/src/module/config/loadTest.c | 24 +++++++++++++++++++++++-
test/src/module/storage/posixTest.c | 21 +++++++++++++++++++++
14 files changed, 165 insertions(+), 34 deletions(-)
diff --git a/src/common/log.c b/src/common/log.c
index fb4ecca93..fe2a519e8 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -40,6 +40,14 @@ DEBUG_UNIT_EXTERN bool logTimestamp = false;
// Size of the process id field
DEBUG_UNIT_EXTERN int logProcessSize = 2;
+// Prefix DRY-RUN to log messages
+DEBUG_UNIT_EXTERN bool logDryRun = false;
+
+/***********************************************************************************************************************************
+Dry run prefix
+***********************************************************************************************************************************/
+#define DRY_RUN_PREFIX "[DRY-RUN] "
+
/***********************************************************************************************************************************
Test Asserts
***********************************************************************************************************************************/
@@ -143,13 +151,15 @@ Initialize the log system
void
logInit(
LogLevel logLevelStdOutParam, LogLevel logLevelStdErrParam, LogLevel logLevelFileParam, bool logTimestampParam,
- unsigned int logProcessMax)
+ unsigned int logProcessMax, bool dryRunParam)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, logLevelStdOutParam);
FUNCTION_TEST_PARAM(ENUM, logLevelStdErrParam);
FUNCTION_TEST_PARAM(ENUM, logLevelFileParam);
FUNCTION_TEST_PARAM(BOOL, logTimestampParam);
+ FUNCTION_TEST_PARAM(UINT, logProcessMax);
+ FUNCTION_TEST_PARAM(BOOL, dryRunParam);
FUNCTION_TEST_END();
ASSERT(logLevelStdOutParam <= LOG_LEVEL_MAX);
@@ -162,6 +172,7 @@ logInit(
logLevelFile = logLevelFileParam;
logTimestamp = logTimestampParam;
logProcessSize = logProcessMax > 99 ? 3 : 2;
+ logDryRun = dryRunParam;
logAnySet();
@@ -241,7 +252,7 @@ logClose(void)
FUNCTION_TEST_VOID();
// Disable all logging
- logInit(logLevelOff, logLevelOff, logLevelOff, false, 1);
+ logInit(logLevelOff, logLevelOff, logLevelOff, false, 1, false);
// Close the log file if it is open
logFileClose();
@@ -392,6 +403,10 @@ logPre(LogLevel logLevel, unsigned int processId, const char *fileName, const ch
if (code != 0)
result.bufferPos += (size_t)snprintf(logBuffer + result.bufferPos, sizeof(logBuffer) - result.bufferPos, "[%03d]: ", code);
+ // Add dry-run prefix
+ if (logDryRun)
+ result.bufferPos += (size_t)snprintf(logBuffer + result.bufferPos, sizeof(logBuffer) - result.bufferPos, DRY_RUN_PREFIX);
+
// Add debug info
if (logLevel >= logLevelDebug)
{
diff --git a/src/common/log.h b/src/common/log.h
index 230ed1278..a282010f9 100644
--- a/src/common/log.h
+++ b/src/common/log.h
@@ -20,7 +20,7 @@ Functions
***********************************************************************************************************************************/
void logInit(
LogLevel logLevelStdOutParam, LogLevel logLevelStdErrParam, LogLevel logLevelFileParam, bool logTimestampParam,
- unsigned int logProcessMax);
+ unsigned int logProcessMax, bool dryRun);
void logClose(void);
bool logFileSet(const char *logFile);
diff --git a/src/config/load.c b/src/config/load.c
index d43397b8b..1d5cc9292 100644
--- a/src/config/load.c
+++ b/src/config/load.c
@@ -16,6 +16,7 @@ Configuration Load
#include "config/config.h"
#include "config/load.h"
#include "config/parse.h"
+#include "storage/helper.h"
/***********************************************************************************************************************************
Load log settings
@@ -49,7 +50,9 @@ cfgLoadLogSetting(void)
if (cfgOptionValid(cfgOptProcessMax))
logProcessMax = cfgOptionUInt(cfgOptProcessMax);
- logInit(logLevelConsole, logLevelStdErr, logLevelFile, logTimestamp, logProcessMax);
+ logInit(
+ logLevelConsole, logLevelStdErr, logLevelFile, logTimestamp, logProcessMax,
+ cfgOptionValid(cfgOptDryRun) && cfgOptionBool(cfgOptDryRun));
FUNCTION_LOG_RETURN_VOID();
}
@@ -325,6 +328,9 @@ cfgLoad(unsigned int argListSize, const char *argList[])
// Parse config from command line and config file
configParse(argListSize, argList, true);
+ // Initialize dry-run mode for storage when valid for the current command
+ storageHelperDryRunInit(cfgOptionValid(cfgOptDryRun) && cfgOptionBool(cfgOptDryRun));
+
// Load the log settings
cfgLoadLogSetting();
diff --git a/src/config/parse.c b/src/config/parse.c
index 827ea3135..c6b1ef747 100644
--- a/src/config/parse.c
+++ b/src/config/parse.c
@@ -615,7 +615,7 @@ configParse(unsigned int argListSize, const char *argList[], bool resetLogLevel)
// Enable logging (except for local and remote commands) so config file warnings will be output
if (cfgCommandRole() != cfgCmdRoleLocal && cfgCommandRole() != cfgCmdRoleRemote && resetLogLevel)
- logInit(logLevelWarn, logLevelWarn, logLevelOff, false, 1);
+ logInit(logLevelWarn, logLevelWarn, logLevelOff, false, 1, false);
// Only continue if command options need to be validated, i.e. a real command is running or we are getting help for a
// specific command and would like to display actual option values in the help.
diff --git a/src/storage/helper.c b/src/storage/helper.c
index aebe5bdc5..beecfae34 100644
--- a/src/storage/helper.c
+++ b/src/storage/helper.c
@@ -29,6 +29,12 @@ STRING_EXTERN(STORAGE_REPO_BACKUP_STR, STORAGE_REPO
STRING_EXTERN(STORAGE_PATH_ARCHIVE_STR, STORAGE_PATH_ARCHIVE);
STRING_EXTERN(STORAGE_PATH_BACKUP_STR, STORAGE_PATH_BACKUP);
+/***********************************************************************************************************************************
+Error message when writable storage is requested in dry-run mode
+***********************************************************************************************************************************/
+#define WRITABLE_WHILE_DRYRUN \
+ "unable to get writable storage in dry-run mode or before dry-run is initialized"
+
/***********************************************************************************************************************************
Local variables
***********************************************************************************************************************************/
@@ -47,6 +53,8 @@ static struct StorageHelper
String *stanza; // Stanza for storage
bool stanzaInit; // Has the stanza been initialized?
+ bool dryRunInit; // Has dryRun been initialized? If not disallow writes.
+ bool dryRun; // Disallow writes in dry-run mode.
RegExp *walRegExp; // Regular expression for identifying wal files
} storageHelper;
@@ -74,6 +82,18 @@ storageHelperInit(void)
FUNCTION_TEST_RETURN_VOID();
}
+/**********************************************************************************************************************************/
+void
+storageHelperDryRunInit(bool dryRun)
+{
+ FUNCTION_TEST_VOID();
+
+ storageHelper.dryRunInit = true;
+ storageHelper.dryRun = dryRun;
+
+ FUNCTION_TEST_RETURN_VOID();
+}
+
/***********************************************************************************************************************************
Initialize the stanza and error if it changes
***********************************************************************************************************************************/
@@ -224,6 +244,10 @@ storagePgIdWrite(unsigned int hostId)
FUNCTION_TEST_PARAM(UINT, hostId);
FUNCTION_TEST_END();
+ // Writes not allowed in dry-run mode
+ if (!storageHelper.dryRunInit || storageHelper.dryRun)
+ THROW(AssertError, WRITABLE_WHILE_DRYRUN);
+
if (storageHelper.storagePgWrite == NULL || storageHelper.storagePgWrite[hostId - 1] == NULL)
{
storageHelperInit();
@@ -419,6 +443,10 @@ storageRepoWrite(void)
{
FUNCTION_TEST_VOID();
+ // Writes not allowed in dry-run mode
+ if (!storageHelper.dryRunInit || storageHelper.dryRun)
+ THROW(AssertError, WRITABLE_WHILE_DRYRUN);
+
if (storageHelper.storageRepoWrite == NULL)
{
storageHelperInit();
@@ -504,6 +532,10 @@ storageSpoolWrite(void)
{
FUNCTION_TEST_VOID();
+ // Writes not allowed in dry-run mode
+ if (!storageHelper.dryRunInit || storageHelper.dryRun)
+ THROW(AssertError, WRITABLE_WHILE_DRYRUN);
+
if (storageHelper.storageSpoolWrite == NULL)
{
storageHelperInit();
diff --git a/src/storage/helper.h b/src/storage/helper.h
index e46d3c36e..ce9950c08 100644
--- a/src/storage/helper.h
+++ b/src/storage/helper.h
@@ -34,6 +34,11 @@ Repository storage types
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
+// Initialize dry-run for the current command. No writes are allowed until dry-run has been intitialized and no writes are allowed
+// after initialization if dry-run is true. Note that storageLocalWrite() is exempt from this rule. The primary purpose is to
+// prevent damage to the repository from an error in dry-run coding in the individual commands.
+void storageHelperDryRunInit(bool dryRun);
+
const Storage *storageLocal(void);
const Storage *storageLocalWrite(void);
const Storage *storagePg(void);
diff --git a/test/define.yaml b/test/define.yaml
index f992a546c..cf78f39fe 100644
--- a/test/define.yaml
+++ b/test/define.yaml
@@ -393,7 +393,7 @@ unit:
# ----------------------------------------------------------------------------------------------------------------------------
- name: posix
- total: 20
+ total: 21
containerReq: true
coverage:
diff --git a/test/src/common/harnessConfig.c b/test/src/common/harnessConfig.c
index a466a17a3..1af46f052 100644
--- a/test/src/common/harnessConfig.c
+++ b/test/src/common/harnessConfig.c
@@ -25,6 +25,12 @@ harnessCfgLoadRaw(unsigned int argListSize, const char *argList[])
configParse(argListSize, argList, false);
cfgLoadUpdateOption();
+ // Set dry-run mode for storage and logging
+ storageHelperDryRunInit(cfgOptionValid(cfgOptDryRun) && cfgOptionBool(cfgOptDryRun));
+#ifndef NO_LOG
+ harnessLogDryRunSet(cfgOptionValid(cfgOptDryRun) && cfgOptionBool(cfgOptDryRun));
+#endif
+
FUNCTION_HARNESS_RESULT_VOID();
}
diff --git a/test/src/common/harnessLog.c b/test/src/common/harnessLog.c
index 240edf5ae..1c4d54a05 100644
--- a/test/src/common/harnessLog.c
+++ b/test/src/common/harnessLog.c
@@ -26,9 +26,11 @@ extern bool logFileBanner;
extern void logAnySet(void);
/***********************************************************************************************************************************
-Default log level for testing
+Log settings for testing
***********************************************************************************************************************************/
+LogLevel logLevelTest = logLevelInfo;
LogLevel logLevelTestDefault = logLevelOff;
+bool logDryRunTest = false;
/***********************************************************************************************************************************
Name of file where logs are stored for testing
@@ -70,7 +72,7 @@ harnessLogInit(void)
{
FUNCTION_HARNESS_VOID();
- logInit(logLevelTestDefault, logLevelOff, logLevelInfo, false, 99);
+ logInit(logLevelTestDefault, logLevelOff, logLevelInfo, false, 99, false);
logFileBanner = true;
snprintf(logFile, sizeof(logFile), "%s/expect.log", testDataPath());
@@ -80,6 +82,15 @@ harnessLogInit(void)
FUNCTION_HARNESS_RESULT_VOID();
}
+/**********************************************************************************************************************************/
+void
+harnessLogDryRunSet(bool dryRun)
+{
+ logDryRunTest = dryRun;
+
+ logInit(logLevelTestDefault, logLevelOff, logLevelTest, false, 99, logDryRunTest);
+}
+
/***********************************************************************************************************************************
Change test log level
@@ -88,7 +99,9 @@ This is info by default but it can sometimes be useful to set the log level to s
void
harnessLogLevelSet(LogLevel logLevel)
{
- logInit(logLevelTestDefault, logLevelOff, logLevel, false, 99);
+ logLevelTest = logLevel;
+
+ logInit(logLevelTestDefault, logLevelOff, logLevelTest, false, 99, logDryRunTest);
}
/***********************************************************************************************************************************
@@ -99,7 +112,9 @@ Set back to info
void
harnessLogLevelReset(void)
{
- logInit(logLevelTestDefault, logLevelOff, logLevelInfo, false, 99);
+ logLevelTest = logLevelInfo;
+
+ logInit(logLevelTestDefault, logLevelOff, logLevelTest, false, 99, logDryRunTest);
}
/***********************************************************************************************************************************
diff --git a/test/src/common/harnessLog.h b/test/src/common/harnessLog.h
index 66152f764..a390ec82d 100644
--- a/test/src/common/harnessLog.h
+++ b/test/src/common/harnessLog.h
@@ -26,4 +26,10 @@ Setters
void harnessLogLevelReset(void);
void harnessLogLevelSet(LogLevel logLevel);
+/***********************************************************************************************************************************
+Internal Setters
+***********************************************************************************************************************************/
+// Set dry-run on or off. This is usually called only from the config harness.
+void harnessLogDryRunSet(bool dryRun);
+
#endif
diff --git a/test/src/module/command/expireTest.c b/test/src/module/command/expireTest.c
index 7b35a1b51..3ffbf1daa 100644
--- a/test/src/module/command/expireTest.c
+++ b/test/src/module/command/expireTest.c
@@ -750,8 +750,8 @@ testRun(void)
storageExistsP(storageTest, strNewFmt("%s/20181119-152138F/" BACKUP_MANIFEST_FILE, strPtr(backupStanzaPath))),
true, " backup not removed");
harnessLogResult(
- "P00 INFO: expire full backup 20181119-152138F\n"
- "P00 INFO: remove expired backup 20181119-152138F");
+ "P00 INFO: [DRY-RUN] expire full backup 20181119-152138F\n"
+ "P00 INFO: [DRY-RUN] remove expired backup 20181119-152138F");
// Save a copy of the info files for a later test
storageCopy(
@@ -828,13 +828,13 @@ testRun(void)
storageTest, strNewFmt("%s/20181119-152800F_20181119-152252D/" BACKUP_MANIFEST_FILE, strPtr(backupStanzaPath)))),
true, " backup not removed");
harnessLogResult(strPtr(strNewFmt(
- "P00 INFO: expire full backup set: 20181119-152800F, 20181119-152800F_20181119-152152D, "
+ "P00 INFO: [DRY-RUN] expire full backup set: 20181119-152800F, 20181119-152800F_20181119-152152D, "
"20181119-152800F_20181119-152155I, 20181119-152800F_20181119-152252D\n"
- "P00 INFO: remove expired backup 20181119-152800F_20181119-152252D\n"
- "P00 INFO: remove expired backup 20181119-152800F_20181119-152155I\n"
- "P00 INFO: remove expired backup 20181119-152800F_20181119-152152D\n"
- "P00 INFO: remove expired backup 20181119-152800F\n"
- "P00 INFO: remove archive path: %s/%s/9.4-1", testPath(), strPtr(archiveStanzaPath))));
+ "P00 INFO: [DRY-RUN] remove expired backup 20181119-152800F_20181119-152252D\n"
+ "P00 INFO: [DRY-RUN] remove expired backup 20181119-152800F_20181119-152155I\n"
+ "P00 INFO: [DRY-RUN] remove expired backup 20181119-152800F_20181119-152152D\n"
+ "P00 INFO: [DRY-RUN] remove expired backup 20181119-152800F\n"
+ "P00 INFO: [DRY-RUN] remove archive path: %s/%s/9.4-1", testPath(), strPtr(archiveStanzaPath))));
argList = strLstDup(argListAvoidWarn);
strLstAddZ(argList, "--repo1-retention-archive=1");
diff --git a/test/src/module/common/logTest.c b/test/src/module/common/logTest.c
index 31c7c410e..6c859bf11 100644
--- a/test/src/module/common/logTest.c
+++ b/test/src/module/common/logTest.c
@@ -120,14 +120,16 @@ testRun(void)
TEST_RESULT_INT(logLevelStdErr, logLevelError, "stderr logging is error");
TEST_RESULT_INT(logLevelFile, logLevelOff, "file logging is off");
- TEST_RESULT_VOID(logInit(logLevelInfo, logLevelWarn, logLevelError, true, 99), "init logging");
+ TEST_RESULT_VOID(logInit(logLevelInfo, logLevelWarn, logLevelError, true, 99, true), "init logging");
TEST_RESULT_INT(logLevelStdOut, logLevelInfo, "console logging is info");
TEST_RESULT_INT(logLevelStdErr, logLevelWarn, "stderr logging is warn");
TEST_RESULT_INT(logLevelFile, logLevelError, "file logging is error");
TEST_RESULT_INT(logProcessSize, 2, "process field size is 2");
+ TEST_RESULT_BOOL(logDryRun, true, "dry run is true");
- TEST_RESULT_VOID(logInit(logLevelInfo, logLevelWarn, logLevelError, true, 100), "init logging");
+ TEST_RESULT_VOID(logInit(logLevelInfo, logLevelWarn, logLevelError, true, 100, false), "init logging");
TEST_RESULT_INT(logProcessSize, 3, "process field size is 3");
+ TEST_RESULT_BOOL(logDryRun, false, "dry run is false");
}
// *****************************************************************************************************************************
@@ -166,12 +168,12 @@ testRun(void)
// *****************************************************************************************************************************
if (testBegin("logInternal() and logInternalFmt()"))
{
- TEST_RESULT_VOID(logInit(logLevelOff, logLevelOff, logLevelOff, false, 1), "init logging to off");
+ TEST_RESULT_VOID(logInit(logLevelOff, logLevelOff, logLevelOff, false, 1, false), "init logging to off");
TEST_RESULT_VOID(
logInternal(logLevelWarn, LOG_LEVEL_MIN, LOG_LEVEL_MAX, 0, "file", "function", 0, "format"),
"message not logged anywhere");
- TEST_RESULT_VOID(logInit(logLevelWarn, logLevelOff, logLevelOff, true, 1), "init logging to warn (timestamp on)");
+ TEST_RESULT_VOID(logInit(logLevelWarn, logLevelOff, logLevelOff, true, 1, false), "init logging to warn (timestamp on)");
TEST_RESULT_VOID(logFileSet(BOGUS_STR), "ignore bogus filename because file logging is off");
TEST_RESULT_VOID(
logInternal(logLevelWarn, LOG_LEVEL_MIN, LOG_LEVEL_MAX, 0, "file", "function", 0, "TEST"), "log timestamp");
@@ -191,7 +193,7 @@ testRun(void)
snprintf(stderrFile, sizeof(stderrFile), "%s/stderr.log", testPath());
logHandleStdErr = testLogOpen(stderrFile, O_WRONLY | O_CREAT | O_TRUNC, 0640);
- TEST_RESULT_VOID(logInit(logLevelWarn, logLevelOff, logLevelOff, false, 1), "init logging to warn (timestamp off)");
+ TEST_RESULT_VOID(logInit(logLevelWarn, logLevelOff, logLevelOff, false, 1, false), "init logging to warn (timestamp off)");
logBuffer[0] = 0;
TEST_RESULT_VOID(
@@ -213,7 +215,7 @@ testRun(void)
"log error with multiple lines");
TEST_RESULT_Z(logBuffer, "P00 ERROR: [026]: message1\nmessage2\n", " check log");
- TEST_RESULT_VOID(logInit(logLevelDebug, logLevelDebug, logLevelDebug, false, 999), "init logging to debug");
+ TEST_RESULT_VOID(logInit(logLevelDebug, logLevelDebug, logLevelDebug, false, 999, false), "init logging to debug");
// Log to file
char fileFile[1024];
@@ -236,23 +238,24 @@ testRun(void)
TEST_RESULT_Z(logBuffer, "P000 TRACE: test::test_func: message\n", " check log");
// Reopen the log file
- TEST_RESULT_VOID(logInit(logLevelDebug, logLevelDebug, logLevelDebug, false, 99), "reduce log size");
+ TEST_RESULT_VOID(
+ logInit(logLevelDebug, logLevelDebug, logLevelDebug, false, 99, true), "reduce process-id size and dry-run");
TEST_RESULT_BOOL(logFileSet(fileFile), true, "open valid file");
logBuffer[0] = 0;
TEST_RESULT_VOID(
logInternal(logLevelInfo, LOG_LEVEL_MIN, LOG_LEVEL_MAX, 1, "test.c", "test_func", 0, "info message"), "log info");
- TEST_RESULT_Z(logBuffer, "P01 INFO: info message\n", " check log");
+ TEST_RESULT_Z(logBuffer, "P01 INFO: [DRY-RUN] info message\n", " check log");
TEST_RESULT_VOID(
logInternal(logLevelInfo, LOG_LEVEL_MIN, LOG_LEVEL_MAX, 99, "test.c", "test_func", 0, "info message 2"), "log info");
- TEST_RESULT_Z(logBuffer, "P99 INFO: info message 2\n", " check log");
+ TEST_RESULT_Z(logBuffer, "P99 INFO: [DRY-RUN] info message 2\n", " check log");
// Reopen invalid log file
TEST_RESULT_BOOL(logFileSet("/" BOGUS_STR), false, "attempt to open bogus file");
TEST_RESULT_INT(logHandleFile, -1, "log file is closed");
// Close logging again
- TEST_RESULT_VOID(logInit(logLevelDebug, logLevelDebug, logLevelDebug, false, 99), "reduce log size");
+ TEST_RESULT_VOID(logInit(logLevelDebug, logLevelDebug, logLevelDebug, false, 99, false), "reduce log size");
TEST_RESULT_BOOL(logFileSet(fileFile), true, "open valid file");
TEST_RESULT_BOOL(logHandleFile != -1, true, "log file is open");
@@ -275,9 +278,9 @@ testRun(void)
stderrFile,
"DEBUG: test::test_func: message\n"
" message2\n"
- "INFO: info message\n"
- "INFO: info message 2\n"
- "WARN: unable to open log file '/BOGUS': Permission denied\n"
+ "INFO: [DRY-RUN] info message\n"
+ "INFO: [DRY-RUN] info message 2\n"
+ "WARN: [DRY-RUN] unable to open log file '/BOGUS': Permission denied\n"
" NOTE: process will continue without log file.");
// Check file
@@ -288,8 +291,8 @@ testRun(void)
" message2\n"
"\n"
"-------------------PROCESS START-------------------\n"
- "P01 INFO: info message\n"
- "P99 INFO: info message 2");
+ "P01 INFO: [DRY-RUN] info message\n"
+ "P99 INFO: [DRY-RUN] info message 2");
}
FUNCTION_HARNESS_RESULT_VOID();
diff --git a/test/src/module/config/loadTest.c b/test/src/module/config/loadTest.c
index 4f46c4f9c..9bfc8e069 100644
--- a/test/src/module/config/loadTest.c
+++ b/test/src/module/config/loadTest.c
@@ -334,9 +334,31 @@ testRun(void)
// *****************************************************************************************************************************
if (testBegin("cfgLoad()"))
{
- // Command does not have umask
// -------------------------------------------------------------------------------------------------------------------------
+ TEST_TITLE("dry-run valid, --no-dry-run");
+
StringList *argList = strLstNew();
+ strLstAddZ(argList, PROJECT_BIN);
+ strLstAddZ(argList, "--" CFGOPT_STANZA "=db");
+ strLstAdd(argList, strNewFmt("--" CFGOPT_LOCK_PATH "=%s/lock", testDataPath()));
+ strLstAddZ(argList, CFGCMD_EXPIRE);
+
+ TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config");
+ TEST_RESULT_VOID(storageRepoWrite(), " check writable storage");
+ lockRelease(true);
+
+ TEST_TITLE("dry-run valid, dry-run");
+
+ strLstAddZ(argList, "--" CFGOPT_DRY_RUN);
+
+ TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config");
+ TEST_ERROR(
+ storageRepoWrite(), AssertError, "unable to get writable storage in dry-run mode or before dry-run is initialized");
+ lockRelease(true);
+
+ // Command does not have umask
+ // -------------------------------------------------------------------------------------------------------------------------
+ argList = strLstNew();
strLstAdd(argList, strNew("pgbackrest"));
strLstAdd(argList, strNew("info"));
diff --git a/test/src/module/storage/posixTest.c b/test/src/module/storage/posixTest.c
index 8f7fe3574..8bad3e38c 100644
--- a/test/src/module/storage/posixTest.c
+++ b/test/src/module/storage/posixTest.c
@@ -61,6 +61,27 @@ testRun(void)
// Write file for testing if storage is read-only
String *writeFile = strNewFmt("%s/writefile", testPath());
+ // This test should always be first so the storage helper is uninitialized
+ // *****************************************************************************************************************************
+ if (testBegin("storageHelperDryRunInit()"))
+ {
+ // -------------------------------------------------------------------------------------------------------------------------
+ TEST_TITLE("writable storage fails when dry-run is not initialized");
+
+ TEST_ERROR(storagePgIdWrite(1), AssertError, WRITABLE_WHILE_DRYRUN);
+ TEST_ERROR(storageRepoWrite(), AssertError, WRITABLE_WHILE_DRYRUN);
+ TEST_ERROR(storageSpoolWrite(), AssertError, WRITABLE_WHILE_DRYRUN);
+
+ // -------------------------------------------------------------------------------------------------------------------------
+ TEST_TITLE("writable storage fails when dry-run is true");
+
+ storageHelperDryRunInit(true);
+
+ TEST_ERROR(storagePgIdWrite(1), AssertError, WRITABLE_WHILE_DRYRUN);
+ TEST_ERROR(storageRepoWrite(), AssertError, WRITABLE_WHILE_DRYRUN);
+ TEST_ERROR(storageSpoolWrite(), AssertError, WRITABLE_WHILE_DRYRUN);
+ }
+
// *****************************************************************************************************************************
if (testBegin("storageNew() and storageFree()"))
{
[parent: 2fa69af8da40]