Skip to content

Commit

Permalink
systemtests: write testrunner script for the messages test
Browse files Browse the repository at this point in the history
- call the messages unittest to distribute a message
- check if the desired files exist and contain the expected message
  • Loading branch information
franku committed Feb 11, 2020
1 parent a81b4be commit c7f4064
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 42 deletions.
13 changes: 9 additions & 4 deletions core/src/tests/messages.cc
Expand Up @@ -38,12 +38,17 @@ using directordaemon::my_config;

TEST(messages, send_message_to_all_configured_destinations)
{
getenv_std_string();
std::string path_to_config_file =
std::string(RELATIVE_PROJECT_SOURCE_DIR "/configs/messages");
std::string config_dir = getenv_std_string("BAREOS_CONFIG_DIR");
std::string working_dir = getenv_std_string("BAREOS_WORKING_DIR");

ASSERT_FALSE(working_dir.empty());
ASSERT_FALSE(config_dir.empty());

SetWorkingDirectory(working_dir.c_str());
InitConsoleMsg(working_dir.c_str());

std::unique_ptr<ConfigurationParser> p{
InitDirConfig(path_to_config_file.c_str(), M_ERROR_TERM)};
InitDirConfig(config_dir.c_str(), M_ERROR_TERM)};

directordaemon::my_config = p.get();
ASSERT_TRUE(directordaemon::my_config->ParseConfig());
Expand Down
61 changes: 23 additions & 38 deletions systemtests/tests/messages-test/testrunner
Expand Up @@ -6,8 +6,6 @@
TestName="$(basename "$(pwd)")"
export TestName

JobName=backup-bareos-fd

#shellcheck source=../environment.in
. ./environment

Expand All @@ -16,45 +14,32 @@ JobName=backup-bareos-fd
"${rscripts}"/cleanup
"${rscripts}"/setup

console_messages_file="${working}"/.conmsg
extra_append_file="${logdir}"/bareos.log

rm -f "$console_messages_file"
rm -f "$extra_append_file"

function exit_error() {
[ "$1" == "" ] || echo "$1"
estat=1
end_test
exit 1
}

# Directory to backup.
# This directory will be created by setup_data "$@"().
BackupDirectory="${tmp}/data"
function check_output_file {
[ -f "$1" ] || exit_error "$1 does not exist"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data "$@"
if ! grep --quiet "This is an error message" "$1"; then
exit_error "\"$1\" does not contain the expected text"
fi
}

start_test

cat <<END_OF_DATA >$tmp/bconcmds
@$out /dev/null
messages
@$out $tmp/log1.out
setdebug level=100 storage=File
label volume=TestVolume001 storage=File pool=Full
run job=$JobName yes
status director
status client
status storage=File
wait
messages
@#
@# now do a restore
@#
@$out $tmp/log2.out
wait
restore client=bareos-fd fileset=SelfTest where=$tmp/bareos-restores select all done
yes
wait
messages
quit
END_OF_DATA

run_bareos "$@"
check_for_zombie_jobs storage=File
stop_bareos

check_two_logs
check_restore_diff ${BackupDirectory}
${BAREOS_UNITTESTS_BINARY_DIR}/messages || exit_failure

check_output_file "$console_messages_file"
check_output_file "$extra_append_file"

end_test

0 comments on commit c7f4064

Please sign in to comment.