#!/bin/bash
set -e
set -o pipefail
set -u

TestName="$(basename "$(pwd)")"
export TestName

JobName=backup-s3-fd

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

#shellcheck source=../scripts/functions
. "${rscripts}"/functions
"${rscripts}"/cleanup
"${rscripts}"/setup

"${rscripts}"/start_minio.sh "$MINIO_PORT" "$TestName"

# shortcut for s3cmd
S3="${S3CMD} --no-check-certificate --config ${S3CFG}"

$S3 mb S3://backup


# Fill ${BackupDirectory} with data.
setup_data

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

check_two_logs
check_restore_diff "${BackupDirectory}"

"${rscripts}"/stop_minio.sh "$TestName"

end_test
