You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-08-10 22:21:39 +02:00
Added ability to test warning messages.
Contributed by Cynthia Shang.
This commit is contained in:
committed by
David Steele
parent
3d84f2ce5e
commit
b63ede5614
@@ -243,6 +243,14 @@
|
||||
<release-item>
|
||||
<p>Fixed flapping archive stop tests.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<release-item-contributor-list>
|
||||
<release-item-contributor id="shang.cynthia"/>
|
||||
</release-item-contributor-list>
|
||||
|
||||
<p>Added ability to test warning messages.</p>
|
||||
</release-item>
|
||||
</release-refactor-list>
|
||||
</release-test-list>
|
||||
</release>
|
||||
|
@@ -796,4 +796,34 @@ sub testCheck
|
||||
|
||||
push @EXPORT, qw(testCheck);
|
||||
|
||||
####################################################################################################################################
|
||||
# logLevel - get the current log levels
|
||||
####################################################################################################################################
|
||||
sub logLevel
|
||||
{
|
||||
return ($strLogLevelFile, $strLogLevelConsole, $strLogLevelStdErr, $bLogTimestamp);
|
||||
}
|
||||
|
||||
push @EXPORT, qw(logLevel);
|
||||
|
||||
####################################################################################################################################
|
||||
# logFileCacheClear - Clear the log file cache
|
||||
####################################################################################################################################
|
||||
sub logFileCacheClear
|
||||
{
|
||||
undef($strLogFileCache);
|
||||
}
|
||||
|
||||
push @EXPORT, qw(logFileCacheClear);
|
||||
|
||||
####################################################################################################################################
|
||||
# logFileCache - Get the log file cache
|
||||
####################################################################################################################################
|
||||
sub logFileCache
|
||||
{
|
||||
return $strLogFileCache;
|
||||
}
|
||||
|
||||
push @EXPORT, qw(logFileCache);
|
||||
|
||||
1;
|
||||
|
@@ -2734,7 +2734,7 @@ sub optionValidate
|
||||
####################################################################################################################################
|
||||
# configFileValidate
|
||||
#
|
||||
# Determine if the configuration file contains any invalid options or placements
|
||||
# Determine if the configuration file contains any invalid options or placements.
|
||||
####################################################################################################################################
|
||||
sub configFileValidate
|
||||
{
|
||||
@@ -2772,7 +2772,7 @@ sub configFileValidate
|
||||
if (!defined($oOptionRule{$strOption}{&OPTION_RULE_COMMAND}{$strCommand}))
|
||||
{
|
||||
&log(WARN, optionGet(OPTION_CONFIG) . " valid option '${strOption}' is not valid for command " .
|
||||
"'$strCommand'");
|
||||
"'${strCommand}'");
|
||||
$bFileValid = false;
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ use File::Basename qw(dirname);
|
||||
|
||||
use pgBackRest::Common::Exception;
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::Common::String;
|
||||
use pgBackRest::Common::Wait;
|
||||
|
||||
use pgBackRestTest::Common::DefineTest;
|
||||
@@ -285,6 +286,7 @@ sub testResult
|
||||
$strExpected,
|
||||
$strDescription,
|
||||
$iWaitSeconds,
|
||||
$strLogExpect,
|
||||
) =
|
||||
logDebugParam
|
||||
(
|
||||
@@ -293,19 +295,27 @@ sub testResult
|
||||
{name => 'strExpected', required => false, trace => true},
|
||||
{name => 'strDescription', trace => true},
|
||||
{name => 'iWaitSeconds', optional => true, default => 0, trace => true},
|
||||
{name => 'strLogExpect', optional => true, trace => true},
|
||||
);
|
||||
|
||||
&log(INFO, ' ' . $strDescription);
|
||||
my $strActual;
|
||||
my $bWarnValid = true;
|
||||
|
||||
my $oWait = waitInit($iWaitSeconds);
|
||||
my $bDone = false;
|
||||
|
||||
# Save the current log levels and set the file level to warn, console to off and timestamp false
|
||||
my ($strLogLevelFile, $strLogLevelConsole, $strLogLevelStdErr, $bLogTimestamp) = logLevel();
|
||||
logLevelSet(WARN, OFF, undef, false);
|
||||
|
||||
# Clear the cache for this test
|
||||
logFileCacheClear();
|
||||
|
||||
do
|
||||
{
|
||||
eval
|
||||
{
|
||||
logDisable();
|
||||
my @stryResult = ref($fnSub) eq 'CODE' ? $fnSub->() : $fnSub;
|
||||
|
||||
if (@stryResult <= 1)
|
||||
@@ -317,12 +327,14 @@ sub testResult
|
||||
$strActual = ${logDebugBuild(\@stryResult)};
|
||||
}
|
||||
|
||||
logEnable();
|
||||
# Restore the log level
|
||||
logLevelSet($strLogLevelFile, $strLogLevelConsole, $strLogLevelStdErr, $bLogTimestamp);
|
||||
return true;
|
||||
}
|
||||
or do
|
||||
{
|
||||
logEnable();
|
||||
# Restore the log level
|
||||
logLevelSet($strLogLevelFile, $strLogLevelConsole, $strLogLevelStdErr, $bLogTimestamp);
|
||||
|
||||
if (!isException($EVAL_ERROR))
|
||||
{
|
||||
@@ -347,6 +359,23 @@ sub testResult
|
||||
}
|
||||
} while (!$bDone);
|
||||
|
||||
# If we get here then test any warning message
|
||||
if (defined($strLogExpect))
|
||||
{
|
||||
my $strLogMessage = trim(logFileCache());
|
||||
|
||||
# Strip leading Process marker and whitespace from each line
|
||||
$strLogMessage =~ s/^(P[0-9]{2})*\s+//mg;
|
||||
|
||||
# If the expected message does not exactly match the logged message or is not at least contained in it, then error
|
||||
if (!($strLogMessage eq $strLogExpect || $strLogMessage =~ $strLogExpect))
|
||||
{
|
||||
confess &log(ERROR,
|
||||
"the log message:\n$strLogMessage\ndoes not match or does not contain the expected message:\n" .
|
||||
$strLogExpect);
|
||||
}
|
||||
}
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn($strOperation);
|
||||
}
|
||||
|
@@ -26,25 +26,33 @@ sub run
|
||||
my $self = shift;
|
||||
|
||||
my $oConfig = {};
|
||||
|
||||
optionSet(OPTION_CONFIG, $self->testPath() . '/pgbackrest.conf', true);
|
||||
my $strConfigFile = $self->testPath() . '/pgbackrest.conf';
|
||||
optionSet(OPTION_CONFIG, $strConfigFile, true);
|
||||
|
||||
if ($self->begin('valid option ' . OPTION_DB_PORT . ' under invalid section'))
|
||||
{
|
||||
my $oConfig = {};
|
||||
$$oConfig{&CONFIG_SECTION_GLOBAL}{&OPTION_DB_PORT} = 1234;
|
||||
|
||||
$self->testResult(sub {configFileValidate($oConfig)}, false,
|
||||
'valid option ' . OPTION_DB_PORT . ' under invalid section',
|
||||
{strLogExpect =>
|
||||
"WARN: $strConfigFile valid option '" . OPTION_DB_PORT . "' is a stanza section option and is not valid in" .
|
||||
" section " . CONFIG_SECTION_GLOBAL . "\nHINT: global options can be specified in global or stanza sections but" .
|
||||
" not visa-versa"});
|
||||
}
|
||||
|
||||
if ($self->begin('valid option ' . OPTION_DB_PORT . ' for command ' . CMD_BACKUP . ' under invalid global section'))
|
||||
{
|
||||
my $oConfig = {};
|
||||
$$oConfig{&CONFIG_SECTION_GLOBAL . ':' . &CMD_BACKUP}{&OPTION_DB_PORT} = 1234;
|
||||
|
||||
$self->testResult(sub {configFileValidate($oConfig)}, false,
|
||||
'valid option ' . OPTION_DB_PORT . ' under invalid section');
|
||||
}
|
||||
|
||||
if ($self->begin('valid option ' . OPTION_DB_PORT . ' under invalid global section command'))
|
||||
{
|
||||
my $oConfig = {};
|
||||
$$oConfig{&CONFIG_SECTION_GLOBAL . ':' . &CMD_ARCHIVE_PUSH}{&OPTION_DB_PORT} = 1234;
|
||||
|
||||
$self->testResult(sub {configFileValidate($oConfig)}, false,
|
||||
'valid option ' . OPTION_DB_PORT . ' under invalid global section command');
|
||||
'valid option ' . OPTION_DB_PORT . ' for command ' . CMD_BACKUP . ' under invalid global section',
|
||||
{strLogExpect =>
|
||||
"WARN: $strConfigFile valid option '" . OPTION_DB_PORT . "' is a stanza section option and is not valid in" .
|
||||
" section " . CONFIG_SECTION_GLOBAL ."\nHINT: global options can be specified in global or stanza sections but" .
|
||||
" not visa-versa"});
|
||||
}
|
||||
|
||||
if ($self->begin('valid option ' . OPTION_DB_PORT . ' under invalid stanza section command'))
|
||||
@@ -53,7 +61,9 @@ sub run
|
||||
$$oConfig{$self->stanza() . ':' . &CMD_ARCHIVE_PUSH}{&OPTION_DB_PORT} = 1234;
|
||||
|
||||
$self->testResult(sub {configFileValidate($oConfig)}, false,
|
||||
'valid option ' . OPTION_DB_PORT . ' under invalid stanza section command');
|
||||
'valid option ' . OPTION_DB_PORT . ' under invalid stanza section command',
|
||||
{strLogExpect =>
|
||||
"WARN: $strConfigFile valid option '" . OPTION_DB_PORT . "' is not valid for command '" . CMD_ARCHIVE_PUSH ."'"});
|
||||
}
|
||||
|
||||
if ($self->begin('invalid option'))
|
||||
@@ -61,7 +71,8 @@ sub run
|
||||
my $oConfig = {};
|
||||
$$oConfig{&CONFIG_SECTION_GLOBAL}{&BOGUS} = BOGUS;
|
||||
|
||||
$self->testResult(sub {configFileValidate($oConfig)}, false, 'invalid option ' . $$oConfig{&CONFIG_SECTION_GLOBAL}{&BOGUS});
|
||||
$self->testResult(sub {configFileValidate($oConfig)}, false, 'invalid option ' . $$oConfig{&CONFIG_SECTION_GLOBAL}{&BOGUS},
|
||||
{strLogExpect => "WARN: $strConfigFile file contains invalid option '" . BOGUS . "'"});
|
||||
}
|
||||
|
||||
if ($self->begin('valid alt name'))
|
||||
|
Reference in New Issue
Block a user